use of io.crate.protocols.postgres.ConnectionProperties in project crate by crate.
the class HostBasedAuthenticationTest method testPSQLSslOption.
@Test
public void testPSQLSslOption() {
Settings sslConfig;
HostBasedAuthentication authService;
sslConfig = Settings.builder().put(HBA_1).put("auth.host_based.config.1." + HostBasedAuthentication.SSL.KEY, HostBasedAuthentication.SSL.OPTIONAL.VALUE).build();
authService = new HostBasedAuthentication(sslConfig, null, SystemDefaultDnsResolver.INSTANCE);
assertThat(authService.getEntry("crate", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, null)), not(Optional.empty()));
assertThat(authService.getEntry("crate", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, sslSession)), not(Optional.empty()));
sslConfig = Settings.builder().put(HBA_1).put("auth.host_based.config.1." + HostBasedAuthentication.SSL.KEY, HostBasedAuthentication.SSL.REQUIRED.VALUE).build();
authService = new HostBasedAuthentication(sslConfig, null, SystemDefaultDnsResolver.INSTANCE);
assertThat(authService.getEntry("crate", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, null)), is(Optional.empty()));
assertThat(authService.getEntry("crate", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, sslSession)), not(Optional.empty()));
sslConfig = Settings.builder().put(HBA_1).put("auth.host_based.config.1." + HostBasedAuthentication.SSL.KEY, HostBasedAuthentication.SSL.NEVER.VALUE).build();
authService = new HostBasedAuthentication(sslConfig, null, SystemDefaultDnsResolver.INSTANCE);
assertThat(authService.getEntry("crate", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, null)), not(Optional.empty()));
assertThat(authService.getEntry("crate", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, sslSession)), is(Optional.empty()));
}
use of io.crate.protocols.postgres.ConnectionProperties in project crate by crate.
the class HostBasedAuthenticationTest method testEmptyHbaConf.
@Test
public void testEmptyHbaConf() {
HostBasedAuthentication authService = new HostBasedAuthentication(Settings.EMPTY, null, SystemDefaultDnsResolver.INSTANCE);
AuthenticationMethod method = authService.resolveAuthenticationType("crate", new ConnectionProperties(LOCALHOST, Protocol.POSTGRES, null));
assertNull(method);
}
use of io.crate.protocols.postgres.ConnectionProperties in project crate by crate.
the class HostBasedAuthenticationTest method cert_method_resolved_when_ssl_on_and_keystore_configured.
@Test
public void cert_method_resolved_when_ssl_on_and_keystore_configured() throws Exception {
// This test makes sure that "ssl: on" from crate.yml in test resources
// is correctly mapped to the corresponding enum value despite on yml treats "on" as "true".
Path config = getAbsoluteFilePathFromClassPath("org/elasticsearch/node/config").toPath();
HashMap<String, String> settings = new HashMap<>();
settings.put("path.home", ".");
settings.put("path.conf", config.toAbsolutePath().toString());
settings.put("stats.enabled", "false");
// Settings are intentionally created not by directly putting properties
// but by using InternalSettingsPreparer.prepareEnvironment to trigger yml parsing.
Settings finalSettings = InternalSettingsPreparer.prepareEnvironment(Settings.EMPTY, settings, config, () -> "node1").settings();
// 'on' becomes 'true' -
assertThat(finalSettings.get("auth.host_based.config.0.ssl"), is("true"));
HostBasedAuthentication hba = new HostBasedAuthentication(finalSettings, null, SystemDefaultDnsResolver.INSTANCE);
AuthenticationMethod authMethod = hba.resolveAuthenticationType("crate", new ConnectionProperties(InetAddresses.forString("1.2.3.4"), Protocol.TRANSPORT, mock(SSLSession.class)));
assertThat(authMethod, instanceOf(ClientCertAuth.class));
AuthenticationMethod authMethod2 = hba.resolveAuthenticationType("crate", new ConnectionProperties(InetAddresses.forString("1.2.3.4"), Protocol.TRANSPORT, mock(SSLSession.class)));
assertThat(authMethod2, instanceOf(ClientCertAuth.class));
}
use of io.crate.protocols.postgres.ConnectionProperties in project crate by crate.
the class ClientCertAuthTest method testMissingClientCert.
@Test
public void testMissingClientCert() throws Exception {
SSLSession sslSession = mock(SSLSession.class);
when(sslSession.getPeerCertificates()).thenReturn(new Certificate[0]);
ConnectionProperties connectionProperties = new ConnectionProperties(InetAddresses.forString("127.0.0.1"), Protocol.POSTGRES, sslSession);
ClientCertAuth clientCertAuth = new ClientCertAuth(userName -> exampleUser);
expectedException.expectMessage("Client certificate authentication failed for user \"example.com\"");
clientCertAuth.authenticate("example.com", null, connectionProperties);
}
Aggregations