-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
233 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...ogin-module-common/src/test/java/org/esbtools/auth/ldap/LdapRoleProviderRecoveryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.esbtools.auth.ldap; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
import com.redhat.lightblue.ldap.test.LdapServerExternalResource; | ||
|
||
import com.unboundid.ldap.listener.InMemoryDirectoryServer; | ||
import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig; | ||
import com.unboundid.ldap.listener.InMemoryListenerConfig; | ||
import com.unboundid.ldap.sdk.Attribute; | ||
import com.unboundid.ldap.sdk.LDAPException; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class LdapRoleProviderRecoveryTest { | ||
private final LdapConfiguration ldapConfiguration = new LdapConfiguration() | ||
.bindDn("uid=admin,dc=com") | ||
.bindDNPwd("password") | ||
.server("localhost") | ||
.port(LdapServerExternalResource.DEFAULT_PORT) | ||
.retryIntervalSeconds(1); | ||
|
||
private InMemoryDirectoryServer ldapServer; | ||
|
||
@Before | ||
public void createButDoNotStartLdapServer() throws LDAPException { | ||
InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=com"); | ||
config.addAdditionalBindCredentials("uid=admin,dc=com", "password"); | ||
|
||
InMemoryListenerConfig listenerConfig = new InMemoryListenerConfig( | ||
"test", null, LdapServerExternalResource.DEFAULT_PORT, null, null, null); | ||
config.setListenerConfigs(listenerConfig); | ||
config.setSchema(null); | ||
|
||
ldapServer = new InMemoryDirectoryServer(config); | ||
|
||
ldapServer.add("dc=com", new Attribute("objectClass", "top"), | ||
new Attribute("objectClass", "domain"), | ||
new Attribute("dc", "com")); | ||
} | ||
|
||
@After | ||
public void stopLdapServer() { | ||
ldapServer.shutDown(true); | ||
} | ||
|
||
@Test | ||
public void eventuallyConnectsToLdapIfNotFailFast() throws Exception { | ||
LdapRolesProvider provider = null; | ||
|
||
try { | ||
provider = new LdapRolesProvider( | ||
LdapServerExternalResource.DEFAULT_BASE_DN, | ||
ldapConfiguration, false); | ||
} catch (LDAPException e) { | ||
fail("Expected not to fail fast if failFast is false but got: " + e); | ||
} | ||
|
||
try { | ||
provider.getUserRoles("test"); | ||
fail("Expected exception since LDAP server is not yet started, but no exception was thrown"); | ||
} catch (LDAPException expected) { | ||
// fall through | ||
} | ||
|
||
// Above should fail even if server already started due to retry interval, however it's possible | ||
// (if unlikely) the test could take a second before calling getUserRoles which would mean it | ||
// would attempt the connection, succeed, then fail the test. Thus to avoid a flakey test, | ||
// not testing that case exactly. | ||
ldapServer.startListening(); | ||
|
||
// Wait retry interval... | ||
Thread.sleep(1000); | ||
|
||
try { | ||
provider.getUserRoles("test"); | ||
// pass! | ||
} catch (LDAPException e) { | ||
fail("Expected to recover after retry interval but got: " + e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters