| | |
| | | */ |
| | | package org.forgerock.opendj.adapter.server3x; |
| | | |
| | | import static org.fest.assertions.Assertions.*; |
| | | import static org.fest.assertions.Fail.*; |
| | | |
| | | import java.security.GeneralSecurityException; |
| | | import java.util.NoSuchElementException; |
| | | |
| | |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | | import static org.fest.assertions.Assertions.*; |
| | | import static org.fest.assertions.Fail.*; |
| | | |
| | | /** |
| | | * This class defines a set of tests for the Adapters.class. |
| | | */ |
| | |
| | | @Test(sequential=true) |
| | | public class AdaptersTestCase extends DirectoryServerTestCase { |
| | | |
| | | private static final String USER_0_DN_STRING = "uid=user.0,o=test"; |
| | | |
| | | /** |
| | | * Provides an anonymous connection factories. |
| | | * |
| | |
| | | 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) { |
| | | if (i != 3) { |
| | | TestCaseUtils.deleteEntry(org.opends.server.types.DN.valueOf("uid=user." + i + ", o=test")); |
| | | } |
| | | } |
| | |
| | | */ |
| | | @Test |
| | | public void testSimpleLDAPConnectionFactorySimpleBind() throws LdapException { |
| | | final LDAPConnectionFactory factory = |
| | | new LDAPConnectionFactory("localhost", |
| | | getServerLdapPort()); |
| | | final LDAPConnectionFactory factory = new LDAPConnectionFactory("localhost", getServerLdapPort()); |
| | | Connection connection = null; |
| | | try { |
| | | connection = factory.getConnection(); |
| | |
| | | */ |
| | | @Test |
| | | public void testLDAPSASLBind() throws NumberFormatException, GeneralSecurityException, LdapException { |
| | | LDAPConnectionFactory factory = |
| | | new LDAPConnectionFactory("localhost", |
| | | getServerLdapPort()); |
| | | LDAPConnectionFactory factory = new LDAPConnectionFactory("localhost", getServerLdapPort()); |
| | | |
| | | Connection connection = factory.getConnection(); |
| | | PlainSASLBindRequest request = |
| | |
| | | connection.close(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Test |
| | | public void testAdapterConnectionSimpleBindAsAUser() throws Exception { |
| | | // user |
| | | final Connection connection = |
| | | Adapters.newConnectionForUser(DN.valueOf("uid=user.0,o=test")); |
| | | final BindResult result = |
| | | connection.bind("uid=user.0,o=test", "password".toCharArray()); |
| | | final Connection connection = Adapters.newConnectionForUser(DN.valueOf(USER_0_DN_STRING)); |
| | | final BindResult result = connection.bind(USER_0_DN_STRING, "password".toCharArray()); |
| | | assertThat(result.getResultCode()).isEqualTo(ResultCode.SUCCESS); |
| | | connection.close(); |
| | | } |
| | |
| | | */ |
| | | @Test(expectedExceptions = AuthenticationException.class) |
| | | public void testAdapterConnectionSimpleBindAsAUserWrongPassword() throws Exception { |
| | | // user |
| | | final Connection connection = |
| | | Adapters.newConnectionForUser(DN.valueOf("uid=user.0,o=test")); |
| | | final Connection connection = Adapters.newConnectionForUser(DN.valueOf(USER_0_DN_STRING)); |
| | | try { |
| | | // Invalid credentials |
| | | connection.bind("uid=user.0,o=test", "pass".toCharArray()); |
| | | connection.bind(USER_0_DN_STRING, "pass".toCharArray()); |
| | | } finally { |
| | | connection.close(); |
| | | } |
| | |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterCompareRequestTrue(final ConnectionFactory factory) throws LdapException { |
| | | final CompareRequest compareRequest = |
| | | Requests.newCompareRequest("uid=user.0,o=test", "uid", "user.0"); |
| | | Requests.newCompareRequest(USER_0_DN_STRING, "uid", "user.0"); |
| | | |
| | | final Connection connection = factory.getConnection(); |
| | | final CompareResult result = connection.compare(compareRequest); |
| | |
| | | @Test(dataProvider = "rootConnectionFactories") |
| | | public void testAdapterCompareRequestFalse(final ConnectionFactory factory) throws LdapException { |
| | | final CompareRequest compareRequest = |
| | | Requests.newCompareRequest("uid=user.0,o=test", "uid", "scarter"); |
| | | Requests.newCompareRequest(USER_0_DN_STRING, "uid", "scarter"); |
| | | |
| | | final Connection connection = factory.getConnection(); |
| | | final CompareResult result = connection.compare(compareRequest); |
| | |
| | | throws LdapException { |
| | | |
| | | final CompareRequest compareRequest = |
| | | Requests.newCompareRequest("uid=user.0,o=test", "uid", "user.0"); |
| | | Requests.newCompareRequest(USER_0_DN_STRING, "uid", "user.0"); |
| | | |
| | | final Connection connection = factory.getConnection(); |
| | | final CompareResult result = connection.compare(compareRequest); |
| | |
| | | assertThat(deleteResult.getReferralURIs()).isEqualTo(sdkDeleteResult.getReferralURIs()); |
| | | |
| | | // ConnectionEntryReader |
| | | SearchResultEntry entry = null; |
| | | SearchResultEntry sdkEntry = null; |
| | | while (reader.hasNext()) { |
| | | entry = reader.readEntry(); |
| | | sdkEntry = sdkReader.readEntry(); |
| | | SearchResultEntry entry = reader.readEntry(); |
| | | SearchResultEntry sdkEntry = sdkReader.readEntry(); |
| | | assertThat(entry.getName().toString()).isEqualTo(sdkEntry.getName().toString()); |
| | | assertThat(entry.getAttributeCount()).isEqualTo(sdkEntry.getAttributeCount()); |
| | | assertThat(entry.getAllAttributes().iterator().next().getAttributeDescription()) |