LDAPCompareTestCase.java revision ea1068c292e9b341af6d6b563cd8988a96be20a9
/*
* 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.
* Portions Copyright 2013-2015 ForgeRock AS.
*/
/**
* A set of test cases for the LDAPCompare tool.
*/
@SuppressWarnings("javadoc")
public class LDAPCompareTestCase
extends ToolsTestCase
{
// The path to a file containing a valid bind password.
private String validPasswordFile;
/**
* Ensures that the Directory Server is running and performs other necessary
* setup.
*
* @throws Exception If an unexpected problem occurs.
*/
public void startServerAndCreatePasswordFiles()
throws Exception
{
"set-sasl-mechanism-handler-prop",
"--handler-name", "DIGEST-MD5",
"--set", "server-fqdn:" + "127.0.0.1");
fileWriter.close();
fileWriter.close();
}
"set-sasl-mechanism-handler-prop",
"--handler-name", "DIGEST-MD5",
"--remove", "server-fqdn:" + "127.0.0.1");
}
/**
* Retrieves sets of invalid arguments that may not be used to initialize
* the LDAPCompare tool.
*
* @return Sets of invalid arguments that may not be used to initialize the
* LDAPCompare tool.
*/
public Object[][] getInvalidArgumentLists()
{
{
"-D",
};
{
"-w",
};
{
"-j",
};
{
"-i",
};
{
"-K",
};
{
"-P",
};
{
"-W",
};
{
"-h",
};
{
"-p",
};
{
"-V",
};
{
"-f",
};
{
"-J",
};
{
"-o",
};
{
"--assertionFilter",
};
{
"-I"
};
{
"--invalidLongArgument"
};
{
"--assertionFilter", "(invalidfilter)",
"uid:test.user",
"uid=test.user,o=test"
};
{
"-D", "cn=Directory Manager",
"-j", "no.such.file",
"uid:test.user",
"uid=test.user,o=test"
};
{
"-D", "cn=Directory Manager",
"-w", "password",
"-j", validPasswordFile,
"uid:test.user",
"uid=test.user,o=test"
};
{
"-V", "nonnumeric",
"uid:test.user",
"uid=test.user,o=test"
};
{
"-V", "1",
"uid:test.user",
"uid=test.user,o=test"
};
{
"-f", "no.such.file",
"uid:test.user",
"uid=test.user,o=test"
};
{
"-J", "1.2.3.4:invalidcriticality",
"uid:test.user",
"uid=test.user,o=test"
};
{
"-p", "nonnumeric",
"uid:test.user",
"uid=test.user,o=test"
};
{
"-p", "999999",
"uid:test.user",
"uid=test.user,o=test"
};
{
"-r",
"-K", "key.store.file",
"uid:test.user",
"uid=test.user,o=test"
};
{
"-Z",
"-r",
"uid:test.user",
"uid=test.user,o=test"
};
{
"-D", "cn=Directory Manager",
"-w", "password"
};
{
"-D", "cn=Directory Manager",
"-w", "password",
"uid:test.user"
};
{
"-D", "cn=Directory Manager",
"-w", "password",
"malformed",
"uid=test.user,o=test"
};
{
}
return returnArray;
}
/**
* Tests the LDAPCompare tool with sets of invalid arguments.
*
* @param args The set of arguments to use for the LDAPCompare
* tool.
* @param invalidReason The reason the provided set of arguments is invalid.
*/
{
"Should have been invalid because: " + invalidReason);
}
/**
* Tests a simple LDAPv2 compare.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testSimpleLDAPv2Compare()
throws Exception
{
{
"-h", "127.0.0.1",
"-V", "2",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"o:test",
"o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-V", "2",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"--useCompareResultCode",
"o:test",
"o=test"
};
SUCCESS);
}
/**
* Tests a simple LDAPv3 compare in which the assertion is true.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testSimpleLDAPv3CompareTrue()
throws Exception
{
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"o:test",
"o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"--useCompareResultCode",
"o:test",
"o=test"
};
SUCCESS);
}
/**
* Tests a simple LDAPv3 compare in which the assertion is false.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testSimpleLDAPv3CompareFalse()
throws Exception
{
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"o:nottest",
"o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"--useCompareResultCode",
"o:nottest",
"o=test"
};
SUCCESS);
}
/**
* Tests two LDAPv3 compares in which the assertion is true for all.
*
* @throws Exception
* If an unexpected problem occurs.
*/
@Test
public void testMultipleCompareAllTrue() throws Exception
{
Backend<?> memoryBackend =
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"--continueOnError",
"arg:success",
dn1,
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"--useCompareResultCode",
"--continueOnError",
"arg:success",
dn1,
};
SUCCESS);
}
/**
* Tests two LDAPv3 compares in which one assertion is true and one is false.
*
* @throws Exception
* If an unexpected problem occurs.
*/
@Test
public void testMultipleCompareOneCompareIsFalse() throws Exception
{
Backend<?> memoryBackend =
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"--continueOnError",
"arg:success",
dn1,
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"--useCompareResultCode",
"--continueOnError",
"arg:success",
dn1,
};
SUCCESS);
}
/**
* Tests two LDAPv3 compares in which one assertion is true and one returns no
* such object.
*
* @throws Exception
* If an unexpected problem occurs.
*/
@Test
public void testMultipleCompareOneNoSuchObject() throws Exception
{
Backend<?> memoryBackend =
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"--continueOnError",
"arg:success",
dn1,
"arg=fail,o=test2,o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"--useCompareResultCode",
"--continueOnError",
"arg:success",
dn1,
"arg=fail,o=test2,o=test"
};
SUCCESS);
}
{
{
}
}
/**
* Tests a simple compare using SSL with blind trust.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testSSLBlindTrust()
throws Exception
{
{
"-h", "127.0.0.1",
"-Z",
"-X",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"o:test",
"o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-Z",
"-X",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"--useCompareResultCode",
"o:test",
"o=test"
};
SUCCESS);
}
/**
* Tests a simple compare using SSL with a trust store.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testSSLTrustStore()
throws Exception
{
{
"-h", "127.0.0.1",
"-Z",
"-P", trustStorePath,
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"o:test",
"o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-Z",
"-P", trustStorePath,
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"--useCompareResultCode",
"o:test",
"o=test"
};
SUCCESS);
}
/**
* Tests a simple compare using StartTLS with blind trust.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testStartTLSBlindTrust()
throws Exception
{
{
"-h", "127.0.0.1",
"-q",
"-X",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"o:test",
"o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-q",
"-X",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"--useCompareResultCode",
"o:test",
"o=test"
};
SUCCESS);
}
/**
* Tests a simple compare using StartTLS with a trust store.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testStartTLSTrustStore()
throws Exception
{
{
"-h", "127.0.0.1",
"-q",
"-P", trustStorePath,
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"o:test",
"o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-q",
"-P", trustStorePath,
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"--useCompareResultCode",
"o:test",
"o=test"
};
SUCCESS);
}
/**
* Tests a simple LDAP compare over SSL using a trust store and SASL EXTERNAL
* authentication.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testSimpleCompareSSLTrustStoreSASLExternal()
throws Exception
{
"dn: cn=Test User,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"cn: Test User",
"givenName: Test",
"ds-privilege-name: bypass-acl",
"sn: User");
{
"-h", "127.0.0.1",
"-Z",
"-K", keyStorePath,
"-W", "password",
"-P", trustStorePath,
"--noPropertiesFile",
"-r",
"cn:Test User",
"cn=Test User,o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-Z",
"-K", keyStorePath,
"-W", "password",
"-P", trustStorePath,
"--noPropertiesFile",
"--useCompareResultCode",
"-r",
"cn:Test User",
"cn=Test User,o=test"
};
SUCCESS);
}
/**
* Tests a simple LDAP compare over SSL using a trust store and SASL EXTERNAL
* authentication when explicitly specifying a valid client certificate.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
throws Exception
{
"dn: cn=Test User,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"cn: Test User",
"givenName: Test",
"ds-privilege-name: bypass-acl",
"sn: User");
{
"-h", "127.0.0.1",
"-Z",
"-K", keyStorePath,
"-W", "password",
"-N", "client-cert",
"-P", trustStorePath,
"--noPropertiesFile",
"-r",
"cn:Test User",
"cn=Test User,o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-Z",
"-K", keyStorePath,
"-W", "password",
"-N", "client-cert",
"-P", trustStorePath,
"--noPropertiesFile",
"--useCompareResultCode",
"-r",
"cn:Test User",
"cn=Test User,o=test"
};
SUCCESS);
}
/**
* Tests a simple LDAP compare over SSL using a trust store and SASL EXTERNAL
* authentication when explicitly specifying an invalid client certificate.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
throws Exception
{
"dn: cn=Test User,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"cn: Test User",
"givenName: Test",
"ds-privilege-name: bypass-acl",
"sn: User");
{
"-h", "127.0.0.1",
"-Z",
"-K", keyStorePath,
"-W", "password",
"-N", "invalid",
"-P", trustStorePath,
"--noPropertiesFile",
"-r",
"cn:Test User",
"cn=Test User,o=test"
};
}
/**
* Tests a simple LDAP compare using StartTLS with a trust store and SASL
* EXTERNAL authentication.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testSimpleCompareStartTLSTrustStoreSASLExternal()
throws Exception
{
"dn: cn=Test User,o=test",
"objectClass: top",
"objectClass: person",
"objectClass: organizationalPerson",
"objectClass: inetOrgPerson",
"cn: Test User",
"givenName: Test",
"ds-privilege-name: bypass-acl",
"sn: User");
{
"-h", "127.0.0.1",
"-q",
"-K", keyStorePath,
"-W", "password",
"-P", trustStorePath,
"--noPropertiesFile",
"-r",
"cn:Test User",
"cn=Test User,o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-q",
"-K", keyStorePath,
"-W", "password",
"-P", trustStorePath,
"--noPropertiesFile",
"--useCompareResultCode",
"-r",
"cn:Test User",
"cn=Test User,o=test"
};
SUCCESS);
}
/**
* Tests a simple compare operation using CRAM-MD5 authentication.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCRAMMD5()
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",
"ds-privilege-name: bypass-acl",
"userPassword: password",
"ds-pwp-password-policy-dn: cn=Clear UserPassword Policy," +
"cn=Password Policies,cn=config");
{
"-h", "127.0.0.1",
"-o", "mech=CRAM-MD5",
"-o", "authid=u:test.user",
"-w", "password",
"--noPropertiesFile",
"givenName:Test",
"uid=test.user,o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-o", "mech=CRAM-MD5",
"-o", "authid=u:test.user",
"-w", "password",
"--noPropertiesFile",
"--useCompareResultCode",
"givenName:Test",
"uid=test.user,o=test"
};
SUCCESS);
}
/**
* Tests a simple compare operation using DIGEST-MD5 authentication.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testDigestMD5()
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",
"ds-privilege-name: bypass-acl",
"ds-privilege-name: proxied-auth",
"userPassword: password",
"ds-pwp-password-policy-dn: cn=Clear UserPassword Policy," +
"cn=Password Policies,cn=config");
{
"-h", "127.0.0.1",
"-o", "mech=DIGEST-MD5",
"-o", "authid=u:test.user",
"-o", "authzid=u:test.user",
"-w", "password",
"--noPropertiesFile",
"givenName:Test",
"uid=test.user,o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-o", "mech=DIGEST-MD5",
"-o", "authid=u:test.user",
"-o", "authzid=u:test.user",
"-w", "password",
"--useCompareResultCode",
"--noPropertiesFile",
"givenName:Test",
"uid=test.user,o=test"
};
SUCCESS);
}
/**
* Tests a simple compare operation using PLAIN authentication.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testPLAIN()
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: password");
{
"-h", "127.0.0.1",
"-o", "mech=PLAIN",
"-o", "authid=dn:cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"givenName:Test",
"uid=test.user,o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-o", "mech=PLAIN",
"-o", "authid=dn:cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"--useCompareResultCode",
"givenName:Test",
"uid=test.user,o=test"
};
SUCCESS);
}
/**
* Tests a a comparison in which the assertion value is base64-encoded with a
* valid encoding.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCompareValidBase64Assertion()
throws Exception
{
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--useCompareResultCode",
"--noPropertiesFile",
"o=test"
};
SUCCESS);
}
/**
* Tests a a comparison in which the assertion value should be base64-encoded
* but uses an incorrect encoding.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCompareInvalidBase64Assertion()
throws Exception
{
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"o::***invalidencoding***",
"o=test"
};
}
/**
* Tests a a comparison in which the assertion value is contained in a file.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCompareAssertionValueFromFile()
throws Exception
{
f.deleteOnExit();
FileWriter w = new FileWriter(f);
w.write("test");
w.close();
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"o:<" + f.getAbsolutePath(),
"o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--useCompareResultCode",
"--noPropertiesFile",
"o:<" + f.getAbsolutePath(),
"o=test"
};
SUCCESS);
}
/**
* Tests a a comparison in which the assertion value is contained in a file
* that does not exist.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCompareAssertionValueFromNonExistentFile()
throws Exception
{
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--noPropertiesFile",
"o:<does.not.exist",
"o=test"
};
}
/**
* Tests a a comparison using the LDAP assertion control in which the
* assertion is true.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCompareLDAPAssertionControlTrue()
throws Exception
{
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--assertionFilter", "(o=test)",
"--noPropertiesFile",
"o:test",
"o=test"
};
String[] argsUseCompare =
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--assertionFilter", "(o=test)",
"--useCompareResultCode",
"--noPropertiesFile",
"o:test",
"o=test"
};
SUCCESS);
}
/**
* Tests a a comparison using the LDAP assertion control in which the
* assertion is not true.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCompareLDAPAssertionControlNotTrue()
throws Exception
{
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"--assertionFilter", "(o=notAMatch)",
"--noPropertiesFile",
"o:test",
"o=test"
};
}
/**
* Tests a a compare operation reading the DNs to compare from a file. Some
* of the compares will succeed and others will not.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCompareDNsFromFile()
throws Exception
{
"o=test",
"dc=example,dc=com",
"o=nonexistentsuffix",
"malformed",
"o=nonexistent,o=test");
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"-c",
"-f", path,
"--noPropertiesFile",
"o:test",
};
}
/**
* Tests a a compare operation reading the DNs to compare from a file that
* doesn't exist.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test
public void testCompareDNsFromNonExistentFile()
throws Exception
{
{
"-h", "127.0.0.1",
"-V", "3",
"-D", "cn=Directory Manager",
"-w", "password",
"-c",
"-f", "does.not.exist",
"--noPropertiesFile",
"o:test",
};
}
/**
* Tests the LDAPCompare tool with the "--help" option.
*/
@Test
public void testHelp()
{
}
public Object[][] getAggregateResultCodeParamsAndResults()
{
}
/**
* Test the results of calling function
* {@link LDAPCompare#aggregateResultCode(int, int)}.
*/
public void testAggregateResultCode(int currentAggregatedResult,
int newResultCode, int finalAggregatedResult)
{
}
}