/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
*/
/**
* A set of test cases for the exact match identity mapper.
*/
public class ExactMatchIdentityMapperTestCase
extends ExtensionsTestCase
{
/**
* Ensures that the Directory Server is running.
*
* @throws Exception If an unexpected problem occurs.
*/
@BeforeClass()
public void startServer()
throws Exception
{
}
/**
* Retrieves a set of valid configuration entries that may be used to
* initialize this identity mapper.
*
* @return A set of valid configuration entries that may be used to
* initialize this identity mapper.
*
* @throws Exception If an unexpected problem occurs.
*/
throws Exception
{
"dn: cn=Exact Match,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: uid",
"",
"dn: cn=Exact Match,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: uid",
"ds-cfg-match-base-dn: ",
"",
"dn: cn=Exact Match,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: uid",
"ds-cfg-match-base-dn: o=test",
"",
"dn: cn=Exact Match,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: uid",
"ds-cfg-match-attribute: sn",
"ds-cfg-match-base-dn: o=test"
);
"dn: cn=Exact Match,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: uid");
{
}
return configEntries;
}
/**
* Tests to ensure that the identity mapper can be initialized and finalized
* using various valid configurations.
*
* @param e The configuration entry to use to initialize the identity
* mapper.
*
* @throws Exception If an unexpected problem occurs.
*/
throws Exception
{
}
/**
* Retrieves a set of invalid configuration entries that should cause the
* identity mapper initialization to fail.
*
* @return A set of invalid configuration entries that should cause the
* identity mapper initialization to fail.
*
* @throws Exception If an unexpected problem occurs.
*/
throws Exception
{
"dn: cn=Exact Match 1,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: undefinedAttribute",
"",
"dn: cn=Exact Match 2,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: uid",
"ds-cfg-match-base-dn: invalidDN",
"",
"dn: cn=Exact Match 3,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: ",
"ds-cfg-match-base-dn: o=test"
);
{
}
return configEntries;
}
/**
* Tests to ensure that the identity mapper can be initialized and finalized
* using various valid configurations.
*
* @param e The configuration entry to use to initialize the identity
* mapper.
*
* @throws Exception If an unexpected problem occurs.
*/
expectedExceptions = { ConfigException.class,
InitializationException.class })
throws Exception
{
}
/**
* Tests to ensure that the exact match identity mapper is configured and
* enabled within the Directory Server.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testMapperEnabled()
throws Exception
{
}
/**
* Tests the <CODE>getEntryForID</CODE> method with a simple equality match
* with only one entry and with no search base DN defined.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSimpleMatchWithoutBaseDN()
throws Exception
{
// Create the identity mapper with an appropriate configuration for this
// test.
"dn: cn=Exact Match,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: uid");
// Create a user entry and add it to the directory.
"dn: uid=test,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test",
"givenName: Test",
"sn: Test",
"cn: Test",
"userPassword: password");
// Ensure that the identity mapper is able to establish the mapping
// successfully.
}
/**
* Tests the <CODE>getEntryForID</CODE> method with a simple equality match
* with only one entry and with a valid search base DN defined.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSimpleMatchWithValidBaseDN()
throws Exception
{
// Create the identity mapper with an appropriate configuration for this
// test.
"dn: cn=Exact Match,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: uid",
"ds-cfg-match-base-dn: o=test");
// Create a user entry and add it to the directory.
"dn: uid=test,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test",
"givenName: Test",
"sn: Test",
"cn: Test",
"userPassword: password");
// Ensure that the identity mapper is able to establish the mapping
// successfully.
}
/**
* Tests the <CODE>getEntryForID</CODE> method with a simple equality match
* with only one entry and with an search base DN defined that doesn't exist
* in the directory.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSimpleMatchWithInvalidBaseDN()
throws Exception
{
// Create the identity mapper with an appropriate configuration for this
// test.
"dn: cn=Exact Match,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: uid",
"ds-cfg-match-base-dn: o=notdefined");
// Create a user entry and add it to the directory.
"dn: uid=test,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test",
"givenName: Test",
"sn: Test",
"cn: Test",
"userPassword: password");
// Ensure that the identity mapper is able to establish the mapping
// successfully.
}
/**
* Tests the <CODE>getEntryForID</CODE> method with a simple equality match
* that doesn't match any user in the directory.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSimpleMismatch()
throws Exception
{
// Create the identity mapper with an appropriate configuration for this
// test.
"dn: cn=Exact Match,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: uid",
"ds-cfg-match-base-dn: o=test");
// Create a user entry and add it to the directory.
"dn: uid=test,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test",
"givenName: Test",
"sn: Test",
"cn: Test",
"userPassword: password");
// Ensure that the identity mapper is able to establish the mapping
// successfully.
}
/**
* Tests the <CODE>getEntryForID</CODE> method with a simple equality match
* that matches multiple entries in the directory.
*
* @throws Exception If an unexpected problem occurs.
*/
public void testDuplicateMatch()
throws Exception
{
// Create the identity mapper with an appropriate configuration for this
// test.
"dn: cn=Exact Match,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: cn",
"ds-cfg-match-base-dn: o=test");
// Create two user entries and add them to the directory.
"dn: uid=test,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test",
"givenName: Test",
"sn: Test",
"cn: Test",
"userPassword: password");
"dn: uid=test2,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test2",
"givenName: Test",
"sn: Test",
"cn: Test",
"userPassword: password");
// Ensure that the identity mapper is able to establish the mapping
// successfully.
try
{
}
finally
{
}
}
/**
* Tests the <CODE>getEntryForID</CODE> method with a compound filter that
* matches the first attribute in the list.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testCompoundFirstMatch()
throws Exception
{
// Create the identity mapper with an appropriate configuration for this
// test.
"dn: cn=Exact Match,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: uid",
"ds-cfg-match-attribute: cn");
// Create a user entry and add it to the directory.
"dn: uid=foo,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: foo",
"givenName: Foo",
"sn: Bar",
"cn: Bar",
"userPassword: password");
// Ensure that the identity mapper is able to establish the mapping
// successfully.
}
/**
* Tests the <CODE>getEntryForID</CODE> method with a compound filter that
* matches the second attribute in the list.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testCompoundSecondMatch()
throws Exception
{
// Create the identity mapper with an appropriate configuration for this
// test.
"dn: cn=Exact Match,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: uid",
"ds-cfg-match-attribute: cn");
// Create a user entry and add it to the directory.
"dn: uid=foo,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: foo",
"givenName: Foo",
"sn: Bar",
"cn: Bar",
"userPassword: password");
// Ensure that the identity mapper is able to establish the mapping
// successfully.
}
/**
* Tests the <CODE>getEntryForID</CODE> method with a compound filter doesn't
* match any attribute in the list.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testCompoundMismatch()
throws Exception
{
// Create the identity mapper with an appropriate configuration for this
// test.
"dn: cn=Exact Match,cn=Identity Mappers,cn=config",
"objectClass: top",
"objectClass: ds-cfg-identity-mapper",
"objectClass: ds-cfg-exact-match-identity-mapper",
"cn: Exact Match",
"ds-cfg-java-class: " +
"org.opends.server.extensions.ExactMatchIdentityMapper",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: uid",
"ds-cfg-match-attribute: cn");
// Create a user entry and add it to the directory.
"dn: uid=foo,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: foo",
"givenName: Foo",
"sn: Bar",
"cn: Bar",
"userPassword: password");
// Ensure that the identity mapper is able to establish the mapping
// successfully.
}
/**
* Tests that an internal modification to change the map attribute will take
* effect immediately.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testChangingMapAttribute()
throws Exception
{
// Create a user entry and add it to the directory.
"dn: uid=test,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test",
"givenName: Test",
"sn: User",
"cn: Test User",
"userPassword: password");
// Verify that "test" works for the initial configuration but "test user"
// does not.
// Create a modification to change the map attribute from uid to cn.
new LDAPAttribute("ds-cfg-match-attribute",
values)));
// Verify that "test" no longer works but "test user" does.
// Change the configuration back to the way it was.
// Verify that the original matching pattern is back.
}
/**
* Tests that an internal modification to change the map base DN will take
* effect immediately.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testChangingMapBaseDN()
throws Exception
{
// Create a user entry and add it to the directory.
"dn: uid=test,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test",
"givenName: Test",
"sn: User",
"cn: Test User",
"userPassword: password");
// Verify that we can retrieve the user.
// Create a modification to set the map base DN to "dc=example,dc=com".
new LDAPAttribute("ds-cfg-match-base-dn",
values)));
// Verify that we can't find the user anymore.
// Change the base DN to "o=test".
// Verify that we can retrieve the user again.
// Change the configuration back to its original setting.
// Verify that we can still retrieve the user.
}
/**
* Tests that an internal modification to remove the match attribute will be
* rejected.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testRejectChangingToNoMatchAttr()
throws Exception
{
// Create a modification to remove the match attribute.
new LDAPAttribute("ds-cfg-match-attribute")));
}
/**
* Tests that an internal modification to change the match attribute to an
* undefined type will be rejected.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testRejectChangingToInvalidMatchAttr()
throws Exception
{
// Create a modification to remove the match attribute.
new LDAPAttribute("ds-cfg-match-attribute",
values)));
}
/**
* Tests that an internal modification to change the match base DN to an
* invalid value will be rejected.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testRejectChangingToInvalidMatchBaseDN()
throws Exception
{
// Create a modification to remove the match attribute.
new LDAPAttribute("ds-cfg-match-base-dn",
values)));
}
}