AdaptersTestCase.java revision b531af710f30dbd69732f9803a55dd2c91f9d055
/*
* 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 2013-2015 ForgeRock AS
*/
/**
* This class defines a set of tests for the Adapters.class.
*/
@SuppressWarnings("javadoc")
@Test(sequential=true)
public class AdaptersTestCase extends DirectoryServerTestCase {
/**
* Provides an anonymous connection factories.
*
* @return Anonymous connection factories.
*/
public Object[][] anonymousConnectionFactories() {
return new Object[][] {
{ Adapters.newAnonymousConnectionFactory() } };
}
private Integer getServerLdapPort() {
return TestCaseUtils.getServerLdapPort();
}
/**
* Provides root connection factories.
*
* @return Root connection factories.
*/
public Object[][] rootConnectionFactories() {
return new Object[][] {
{ new LDAPConnectionFactory("localhost",
newSimpleBindRequest("cn=directory manager",
"password".toCharArray()))) },
}
/**
* Launched before the tests, this function starts the server and adds data.
*
* @throws Exception
* If the server could not be initialized.
*/
public void startServer() throws Exception {
// Creates a root connection to add data
// @formatter:off
"dn: uid=user.0, o=test",
"objectClass: top",
"objectClass: person",
"objectClass: inetOrgPerson",
"objectClass: organizationalPerson",
"cn: Aaccf Amar",
"sn:user.0",
"uid:user.0",
"description: This is the description for Aaccf Amar.",
"userPassword:: cGFzc3dvcmQ=",
"postalAddress: Aaccf Amar$01251 Chestnut Street$Panama City, DE 50369",
"postalCode: 50369");
"dn: uid=user.1, o=test",
"objectClass: top",
"objectClass: person",
"objectClass: inetOrgPerson",
"objectClass: organizationalPerson",
"cn: Aaren Atp",
"sn:user.1",
"uid:user.1",
"description: This is the description for Aaren Atp.",
"postalAddress: Aaren Atp$70110 Fourth Street$New Haven, OH 93694",
"postalCode: 93694");
"dn: uid=user.2, o=test",
"objectClass: top",
"objectClass: person",
"objectClass: inetOrgPerson",
"objectClass: organizationalPerson",
"cn: Aarika Atpco",
"sn: user.2",
"uid:user.2",
"description: This is the description for Aarika Atpco.",
"userPassword:: cGFzc3dvcmQ=",
"postalAddress: Aarika Atpco$00900 Maple Street$New Orleans, KS 10857",
"postalCode: 10857");
"dn: uid=user.3, o=test",
"objectClass: top",
"objectClass: person",
"objectClass: inetOrgPerson",
"objectClass: organizationalPerson",
"cn: Aaron Atrc",
"sn:user.3",
"uid:user.3",
"description: This is the description for Aaron Atrc.",
"postalAddress: Aaron Atrc$59748 Willow Street$Green Bay, TN 66239",
"postalCode: 66239");
"dn: uid=user.4, o=test",
"objectClass: top",
"objectClass: person",
"objectClass: inetOrgPerson",
"objectClass: organizationalPerson",
"cn: Samantha Carter",
"sn: Carter",
"uid:user.4",
"description: This is the description for Samantha Carter.",
"postalAddress: 59748 Willow Street$Green Bay, TN 66000",
"postalCode: 66000");
// @formatter:on
connection.close();
}
/**
* Clean up data at the end of tests.
*/
public void shutDownEmbeddedServerServer() throws Exception {
// Delete all added entries but user.3 which is already removed in one test
for (int i = 0; i < 5; i++) {
if (i != 3) {
}
}
}
/**
* A simple LDAP connection.
*
* @throws LdapException
*/
@Test
public void testSimpleLDAPConnectionFactorySimpleBind() throws LdapException {
try {
} finally {
if (connection != null) {
connection.close();
}
}
}
/**
* Tests a SASL Bind with an LDAP connection.
*
* @throws NumberFormatException
* @throws GeneralSecurityException
* @throws LdapException
*/
@Test
public void testLDAPSASLBind() throws NumberFormatException, GeneralSecurityException, LdapException {
try {
} finally {
if (connection != null) {
connection.close();
}
}
}
/**
* Tests an SASL connection with the adapter.
*
* @throws LdapException
*/
@Test
public void testAdapterConnectionSASLBindRequest() throws LdapException,
try {
} finally {
if (connection != null) {
connection.close();
}
}
}
/**
* This type of connection is not supported. Anonymous SASL Mechanisms is
* disabled in the config.ldif file.
*
* @throws LdapException
*/
public void testConnectionAnonymousSASLBindRequest(final ConnectionFactory factory) throws LdapException {
try {
} finally {
connection.close();
}
}
/**
* Binds as a root.
*
* @throws Exception
*/
@Test
public void testAdapterConnectionSimpleBindAsRoot() throws Exception {
connection.close();
}
/**
* Binds as a known user.
*
* @throws Exception
*/
@Test
public void testAdapterConnectionSimpleBindAsAUser() throws Exception {
connection.close();
}
/**
* Binds as a known user but using the wrong password.
*
* @throws Exception
*/
public void testAdapterConnectionSimpleBindAsAUserWrongPassword() throws Exception {
try {
// Invalid credentials
} finally {
connection.close();
}
}
/**
* Tries to bind as anonymous.
*
* @throws Exception
*/
@Test
public void testAdapterConnectionSimpleBind() throws Exception {
// Anonymous
connection.close();
}
/**
* Testing the adapters with a simple add request.
*
* @throws Exception
*/
@Test
public void testAdapterAddRequest() throws Exception {
// @formatter:off
"dn: sn=carter,o=test",
"objectClass: top",
"objectClass: person",
"cn: scarter");
// @formatter:on
// We find the added entry :
final SearchResultEntry srEntry =
connection.close();
}
/**
* Tries an add request but the entry already exists.
*
* @throws Exception
*/
// @formatter:off
"dn: sn=bjensen,o=test",
"objectClass: top",
"objectClass: person",
"cn: bjensen");
// @formatter:on
// First add :
// Second :
try {
} finally {
connection.close();
}
}
/**
* Uses the adapter to perform a search request.
*
* @throws Exception
*/
@Test
public void testAdapterSearchRequest() throws Exception {
final SearchRequest request =
"(sn=user.1)");
// Performs the search :
"objectClass: person", "objectClass: inetOrgPerson",
"objectClass: organizationalPerson", "sn:user.1", "uid:user.1",
"cn: Aaren Atp", "description: This is the description for Aaren Atp.",
"postalAddress: Aaren Atp$70110 Fourth Street$New Haven, OH 93694",
"postalCode: 93694");
// No differences expected.
"This is the description for Aaren Atp.");
"Aaren Atp$70110 Fourth Street$New Haven, OH 93694");
// top - person - inetOrgPerson - organizationalPerson.
connection.close();
}
/**
* Tries to perform a search with the adapter. No result expected.
*
* @throws Exception
*/
throws Exception {
final SearchRequest request =
"(uid=unknown)").addControl(
connection.close();
}
/**
* Tries to perform a search single entry. Exception expected.
*
* @param factory
* The connection factory.
* @throws Exception
*/
expectedExceptions = EntryNotFoundException.class)
throws Exception {
try {
} finally {
connection.close();
}
}
/**
* Performs a search with a sub entries request control. Sub-entries are
* included and the normal entries are excluded. No result expected.
*
* @throws LdapException
* @throws SearchResultReferenceIOException
*/
expectedExceptions = NoSuchElementException.class)
try {
final SearchRequest request =
"cn=*", "cn", "subtreeSpecification")
// sub-entries included, normal entries excluded.
} finally {
connection.close();
}
}
/**
* Performs a search with a sub entries request control. Sub-entries are
* excluded this time and the normal entries are included.
*
* @throws LdapException
* @throws SearchResultReferenceIOException
*/
final SearchRequest request =
"cn", "subtreeSpecification")
// sub-entries excluded, normal entries included.
// All the entries are present.
int nbEntries = 0;
nbEntries++;
}
connection.close();
}
/**
* Deletes an inexistent entry.
*
* @throws LdapException
*/
expectedExceptions = EntryNotFoundException.class)
public void testAdapterDeleteRequestNoSuchEntry(final ConnectionFactory factory) throws LdapException {
try {
} finally {
connection.close();
}
}
/**
* Deletes an existing entry with the 'no-op' control.
*
* @throws LdapException
*/
public void testAdapterDeleteRequestNoOpControl(final ConnectionFactory factory) throws LdapException {
final DeleteRequest deleteRequest =
// The no-op control is specified with his OID.
// Verifies that the delete has no impact in this case (due to no_operation control)
final SearchResultEntry srEntry =
connection.close();
}
/**
* Deletes an existing entry.
*
* @throws LdapException
*/
@Test
public void testAdapterDeleteRequest() throws LdapException {
// Checks if the entry exists.
final DeleteRequest deleteRequest =
// Verifies if the entry was correctly deleted.
try {
fail("Expected EntryNotFoundException to be thrown");
} catch (EntryNotFoundException ex) {
// Expected - no result.
} finally {
connection.close();
}
}
/**
* Modifies an existing entry.
*
* @throws LdapException
* @throws DecodeException
*/
@Test
final ModifyRequest changeRequest =
assertThat(result.getControls().get(0).getOID()).isEqualTo("1.3.6.1.1.13.1"); // pre read control OID.
// Pre read control sends a copy of the target entry exactly as it was
// immediately before the processing for that operation - mail attribute doesn't exist.
//Verifies that entry has been correctly modified.
final SearchResultEntry srEntry =
"modified@example.com");
}
/**
* Tries to modify the existing entry with the same values but using the
* permissive modify control.
*
* @throws LdapException
*/
public void testAdapterUsePermissiveModifyRequest(final ConnectionFactory factory) throws LdapException {
final ModifyRequest changeRequest =
// Verifies that entry has been correctly modified.
final SearchResultEntry srEntry =
}
/**
* Tries to modify the existing entry with the same values.
*
* @throws LdapException
*/
final ModifyRequest changeRequest =
}
/**
* Modifies the DN.
*
* @throws LdapException
*/
// Verifies that entry has been correctly modified.
final SearchResultEntry srEntryExists =
// Modifying the DN.
.setDeleteOldRDN(true);
// Checks previous mod.
final SearchResultEntry srEntry =
"(uid=user.test)"));
// Modify again the DN as previously.
.setDeleteOldRDN(true);
}
/**
* Compare request. The comparison returns true.
*
* @throws LdapException
*/
final CompareRequest compareRequest =
}
/**
* Compare request. The comparison returns false.
*
* @throws LdapException
*/
final CompareRequest compareRequest =
}
/**
* Use the Who Am I? extended request.
*
* @throws LdapException
*/
try {
} finally {
connection.close();
}
}
/**
* If an anonymous tries to delete, sends a result code : insufficient
* access rights.
*
* @throws LdapException
*/
expectedExceptions = AuthorizationException.class)
throws LdapException {
final DeleteRequest deleteRequest =
try {
} finally {
connection.close();
}
}
/**
* If an anonymous tries to do an add request, sends a result code :
* insufficient access rights.
*
* @throws LdapException
*/
expectedExceptions = AuthorizationException.class)
throws LdapException {
// @formatter:off
"dn: sn=scarter,o=test",
"objectClass: top",
"objectClass: person",
"cn: scarter");
// @formatter:on
try {
} finally {
connection.close();
}
}
/**
* If an anonymous tries to do a modify DN request, sends a result code :
* insufficient access rights.
*
* @throws LdapException
*/
expectedExceptions = AuthorizationException.class)
throws LdapException {
final ModifyDNRequest changeRequest =
.setDeleteOldRDN(true);
try {
} finally {
connection.close();
}
}
/**
* If an anonymous tries to do a modify request, sends a result code :
* insufficient access rights.
*
* @throws LdapException
*/
expectedExceptions = LdapException.class)
throws LdapException {
final ModifyRequest changeRequest =
try {
} finally {
connection.close();
}
}
/**
* The anonymous connection is allowed to perform compare request.
*
* @throws LdapException
*/
throws LdapException {
final CompareRequest compareRequest =
connection.close();
}
/**
* The anonymous connection is allowed to perform search request.
*
* @throws Exception
*/
throws Exception {
final SearchRequest request =
"(uid=user.1)");
}
/**
* The anonymous connection is not allowed to perform search request
* associated with a control.
* <p>
* Unavailable Critical Extension: The request control with Object
* Identifier (OID) "x.x.x" cannot be used due to insufficient access
* rights.
*
* @throws Exception
*/
final SearchRequest request =
}
/**
* Creates an LDAP Connection and performs some basic calls like
* doing the same.
*
* @throws LdapException
* @throws SearchResultReferenceIOException
*/
@Test
public void testLDAPConnectionAndAdapterComparison() throws LdapException, SearchResultReferenceIOException {
// @formatter:off
"dn: sn=babs,o=test",
"objectClass: top",
"objectClass: person",
"cn: bjensen");
// @formatter:on
final SearchRequest searchRequest =
"(uid=user.*)").addControl(
// LDAP Connection
final LDAPConnectionFactory factory =
// SDK Adapter connection
// Compare the results :
// AddRequest
// DeleteRequest
// ConnectionEntryReader
}
}
}