@Test public void testGetAnonymousEnvWithNoBaseSet() throws Exception { tested.setUrl("ldap://ldap.example.com:389"); tested.afterPropertiesSet(); Hashtable env = tested.getAnonymousEnv(); assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389"); // check that base was not added to environment assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isNull(); }
@Test public void testGetAnonymousEnvWithBaseEnvironment() throws Exception { tested.setUrl("ldap://ldap.example.com:389"); HashMap map = new HashMap(); map.put(LdapContextSource.SUN_LDAP_POOLING_FLAG, "true"); tested.setBaseEnvironmentProperties(map); tested.afterPropertiesSet(); Hashtable env = tested.getAnonymousEnv(); assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389"); assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isNull(); }
@Test public void testGetAnonymousEnvWithPoolingInBaseEnvironmentAndPoolingOff() throws Exception { tested.setUrl("ldap://ldap.example.com:389"); HashMap map = new HashMap(); map.put(LdapContextSource.SUN_LDAP_POOLING_FLAG, "true"); tested.setBaseEnvironmentProperties(map); tested.setPooled(false); tested.afterPropertiesSet(); Hashtable env = tested.getAnonymousEnv(); assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389"); assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isNull(); }
@Test public void testGetAnonymousEnvWithEmptyBaseSet() throws Exception { tested.setUrl("ldap://ldap.example.com:389"); tested.setBase(null); tested.afterPropertiesSet(); Hashtable env = tested.getAnonymousEnv(); assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389"); // check that base was not added to environment assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isNull(); }
@Test public void testGetAnonymousEnvWhenCacheIsOff() throws Exception { tested.setBase("dc=example,dc=se"); tested.setUrl("ldap://ldap.example.com:389"); tested.setPooled(true); tested.setUserDn("cn=Some User"); tested.setPassword("secret"); tested.setCacheEnvironmentProperties(false); tested.afterPropertiesSet(); Hashtable env = tested.getAnonymousEnv(); assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389/dc=example,dc=se"); assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isEqualTo("true"); assertThat(env.get(Context.SECURITY_PRINCIPAL)).isNull(); assertThat(env.get(Context.SECURITY_CREDENTIALS)).isNull(); tested.setUrl("ldap://ldap2.example.com:389"); env = tested.getAnonymousEnv(); assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap2.example.com:389/dc=example,dc=se"); } }
@Test public void testGetAnonymousEnv() throws Exception { tested.setBase("dc=some example,dc=se"); tested.setUrl("ldap://ldap.example.com:389"); tested.setPooled(true); tested.setUserDn("cn=Some User"); tested.setPassword("secret"); tested.afterPropertiesSet(); Hashtable env = tested.getAnonymousEnv(); assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389/dc=some%20example,dc=se"); assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isEqualTo("true"); assertThat(env.get(Context.SECURITY_PRINCIPAL)).isNull(); assertThat(env.get(Context.SECURITY_CREDENTIALS)).isNull(); // check that base was added to environment assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isEqualTo(LdapUtils.newLdapName("dc=some example,dc=se")); // Verify that changing values does not change the environment values. tested.setBase("dc=other,dc=se"); tested.setUrl("ldap://ldap2.example.com:389"); tested.setPooled(false); env = tested.getAnonymousEnv(); assertThat(env.get(Context.PROVIDER_URL)).isEqualTo("ldap://ldap.example.com:389/dc=some%20example,dc=se"); assertThat(env.get(LdapContextSource.SUN_LDAP_POOLING_FLAG)).isEqualTo("true"); assertThat(env.get(Context.SECURITY_PRINCIPAL)).isNull(); assertThat(env.get(Context.SECURITY_CREDENTIALS)).isNull(); assertThat(env.get(DefaultDirObjectFactory.JNDI_ENV_BASE_PATH_KEY)).isEqualTo(LdapUtils.newLdapName("dc=some example,dc=se")); }