public void testUserAndGroupMappingsToSelfSignedLdapServer()
throws Exception
{
final NexusClient nexusClient = getNexusClient();
final LdapServerConfigurationDTO ldapServerConfig = getLdapServerConfiguration();
final URI uri = getLdapServerUri(ldapServerConfig);
// trust ldap server certificate
nexusClient.getSubsystem(Certificates.class).get(uri.getHost(), uri.getPort(), uri.getScheme()).save();
// disable Nexus TrustStore for default server
nexusClient.getSubsystem(TrustStore.class).disableFor(ldapTrustStoreKey(ldapServerConfig.getId()));
// test without sending the ldap server id. This will result in not using Nexus SSL Trust Store which
// should result in a failure
try {
testUserAndGroupMappings(ldapServerConfig, false);
assertThat("Expected to fail with Exception", false);
}
catch (Exception e) {
assertThat(e.getMessage(), containsString("unable to find valid certification path"));
}
// test with sending the ldap server id. Nexus SSL Trust Store will not be used as is not enabled
// which should result in a failure
try {
testUserAndGroupMappings(ldapServerConfig, true);
assertThat("Expected to fail with Exception", false);
}
catch (Exception e) {
assertThat(e.getMessage(), containsString("unable to find valid certification path"));
}
// enable Nexus TrustStore for default server
nexusClient.getSubsystem(TrustStore.class).enableFor(ldapTrustStoreKey(ldapServerConfig.getId()));
// test with sending the ldap server id. Nexus SSL Trust Store will be used as it is enabled
// which should result in a success
testUserAndGroupMappings(ldapServerConfig, true);