AttributeValuePasswordValidatorTestCase.java revision 987a50dfe113ed235d28716ff080b59e8873655c
/*
* 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
* 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
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. 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
*
*
* Portions Copyright 2006-2007 Sun Microsystems, Inc.
*/
/**
* A set of test cases for the attribute value password validator.
*/
public class AttributeValuePasswordValidatorTestCase
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 the validator.
*
* @throws Exception If an unexpected problem occurs.
*/
public Object[][] getValidConfigs()
throws Exception
{
"dn: cn=Attribute Value,cn=Password Validators,cn=config",
"objectClass: top",
"objectClass: ds-cfg-password-validator",
"objectClass: ds-cfg-attribute-value-password-validator",
"cn: Attribute Value",
"ds-cfg-java-class: org.opends.server.extensions." +
"AttributeValuePasswordValidator",
"ds-cfg-enabled: true",
"ds-cfg-test-reversed-password: true",
"",
"dn: cn=Attribute Value,cn=Password Validators,cn=config",
"objectClass: top",
"objectClass: ds-cfg-password-validator",
"objectClass: ds-cfg-attribute-value-password-validator",
"cn: Attribute Value",
"ds-cfg-java-class: org.opends.server.extensions." +
"AttributeValuePasswordValidator",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: uid",
"ds-cfg-test-reversed-password: true",
"",
"dn: cn=Attribute Value,cn=Password Validators,cn=config",
"objectClass: top",
"objectClass: ds-cfg-password-validator",
"objectClass: ds-cfg-attribute-value-password-validator",
"cn: Attribute Value",
"ds-cfg-java-class: org.opends.server.extensions." +
"AttributeValuePasswordValidator",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: uid",
"ds-cfg-match-attribute: cn",
"ds-cfg-match-attribute: givenName",
"ds-cfg-match-attribute: sn",
"ds-cfg-test-reversed-password: true",
"",
"dn: cn=Attribute Value,cn=Password Validators,cn=config",
"objectClass: top",
"objectClass: ds-cfg-password-validator",
"objectClass: ds-cfg-attribute-value-password-validator",
"cn: Attribute Value",
"ds-cfg-java-class: org.opends.server.extensions." +
"AttributeValuePasswordValidator",
"ds-cfg-enabled: true",
"ds-cfg-test-reversed-password: false");
{
}
return array;
}
/**
* Tests the process of initializing the server with valid configurations.
*
* @param entry The configuration entry to use for the initialization.
*
* @throws Exception If an unexpected problem occurs.
*/
public void testInitializeWithValidConfigs(Entry e)
throws Exception
{
}
/**
* Retrieves a set of invalid configuration entries.
*
* @throws Exception If an unexpected problem occurs.
*/
public Object[][] getInvalidConfigs()
throws Exception
{
// Invalid test-reversed-password
"dn: cn=Attribute Value,cn=Password Validators,cn=config",
"objectClass: top",
"objectClass: ds-cfg-password-validator",
"objectClass: ds-cfg-attribute-value-password-validator",
"cn: Attribute Value",
"ds-cfg-java-class: org.opends.server.extensions." +
"AttributeValuePasswordValidator",
"ds-cfg-enabled: true",
"ds-cfg-test-reversed-password: invalid",
"",
// Invalid match attribute.
"dn: cn=Attribute Value,cn=Password Validators,cn=config",
"objectClass: top",
"objectClass: ds-cfg-password-validator",
"objectClass: ds-cfg-attribute-value-password-validator",
"cn: Attribute Value",
"ds-cfg-java-class: org.opends.server.extensions." +
"AttributeValuePasswordValidator",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: nosuchattribute",
"ds-cfg-test-reversed-password: true");
{
}
return array;
}
/**
* Tests the process of initializing the server with invalid configurations.
*
* @param entry The configuration entry to use for the initialization.
*
* @throws Exception If an unexpected problem occurs.
*/
expectedExceptions = { ConfigException.class,
InitializationException.class })
public void testInitializeWithInvalidConfigs(Entry e)
throws Exception
{
}
/**
* Retrieves a set of data to use when testing a given password with a
* provided configuration. Each element of the returned array should be an
* array of a configuration entry, a test password string, and an indication
* as to whether the provided password should be acceptable.
*
* @throws Exception If an unexpected problem occurs.
*/
public Object[][] getTestData()
throws Exception
{
return new Object[][]
{
// Default configuration, with a password that does not match an existing
// attribute value.
new Object[]
{
"dn: cn=Attribute Value,cn=Password Validators,cn=config",
"objectClass: top",
"objectClass: ds-cfg-password-validator",
"objectClass: ds-cfg-attribute-value-password-validator",
"cn: Attribute Value",
"ds-cfg-java-class: org.opends.server.extensions." +
"AttributeValuePasswordValidator",
"ds-cfg-enabled: true",
"ds-cfg-test-reversed-password: true"),
"password",
true
},
// Default configuration, with a password that matches an existing
// attribute value.
new Object[]
{
"dn: cn=Attribute Value,cn=Password Validators,cn=config",
"objectClass: top",
"objectClass: ds-cfg-password-validator",
"objectClass: ds-cfg-attribute-value-password-validator",
"cn: Attribute Value",
"ds-cfg-java-class: org.opends.server.extensions." +
"AttributeValuePasswordValidator",
"ds-cfg-enabled: true",
"ds-cfg-test-reversed-password: true"),
"test",
false
},
// Default configuration, with a password that matches the reverse of an
// existing attribute value with reverwse matching enabled
new Object[]
{
"dn: cn=Attribute Value,cn=Password Validators,cn=config",
"objectClass: top",
"objectClass: ds-cfg-password-validator",
"objectClass: ds-cfg-attribute-value-password-validator",
"cn: Attribute Value",
"ds-cfg-java-class: org.opends.server.extensions." +
"AttributeValuePasswordValidator",
"ds-cfg-enabled: true",
"ds-cfg-test-reversed-password: true"),
"tset",
false
},
// Default configuration, with a password that matches the reverse of an
// existing attribute value with reverwse matching disabled
new Object[]
{
"dn: cn=Attribute Value,cn=Password Validators,cn=config",
"objectClass: top",
"objectClass: ds-cfg-password-validator",
"objectClass: ds-cfg-attribute-value-password-validator",
"cn: Attribute Value",
"ds-cfg-java-class: org.opends.server.extensions." +
"AttributeValuePasswordValidator",
"ds-cfg-enabled: true",
"ds-cfg-test-reversed-password: false"),
"tset",
true
},
// Default configuration, with a password that matches one of the values
// of a specified set of attributes.
new Object[]
{
"dn: cn=Attribute Value,cn=Password Validators,cn=config",
"objectClass: top",
"objectClass: ds-cfg-password-validator",
"objectClass: ds-cfg-attribute-value-password-validator",
"cn: Attribute Value",
"ds-cfg-java-class: org.opends.server.extensions." +
"AttributeValuePasswordValidator",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: cn",
"ds-cfg-match-attribute: sn",
"ds-cfg-match-attribute: givenName",
"ds-cfg-test-reversed-password: true"),
"test",
false
},
// Default configuration, with a password that doesn't match any of the
// values of a specified set of attributes but does match the value of
// another attribute in the entry.
new Object[]
{
"dn: cn=Attribute Value,cn=Password Validators,cn=config",
"objectClass: top",
"objectClass: ds-cfg-password-validator",
"objectClass: ds-cfg-attribute-value-password-validator",
"cn: Attribute Value",
"ds-cfg-java-class: org.opends.server.extensions." +
"AttributeValuePasswordValidator",
"ds-cfg-enabled: true",
"ds-cfg-match-attribute: cn",
"ds-cfg-match-attribute: sn",
"ds-cfg-match-attribute: givenName",
"ds-cfg-test-reversed-password: true"),
"test.user",
true
},
};
}
/**
* Tests the {@code passwordIsAcceptable} method using the provided
* information.
*
* @param configEntry The configuration entry to use for the password
* validator.
* @param password The password to test with the validator.
* @param acceptable Indicates whether the provided password should be
* considered acceptable.
*
* @throws Exception If an unexpected problem occurs.
*/
boolean acceptable)
throws Exception
{
"dn: uid=test.user,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"uid: test.user",
"givenName: Test",
"sn: User",
"cn: Test User",
"userPassword: doesntmatter");
}
}