| | |
| | | |
| | | import static org.opends.server.TestCaseUtils.*; |
| | | import static org.opends.server.config.ConfigConstants.*; |
| | | import static org.opends.server.protocols.internal.InternalClientConnection.getRootConnection; |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.opends.server.util.ServerConstants.*; |
| | | import static org.testng.Assert.*; |
| | |
| | | |
| | | import com.forgerock.opendj.ldap.tools.LDAPCompare; |
| | | import com.forgerock.opendj.ldap.tools.LDIFDiff; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.opends.server.TestCaseUtils; |
| | | import org.opends.server.core.DeleteOperation; |
| | | import org.opends.server.protocols.ldap.LDAPResultCode; |
| | | import com.forgerock.opendj.ldap.tools.LDAPModify; |
| | | import com.forgerock.opendj.ldap.tools.LDAPSearch; |
| | |
| | | import org.testng.annotations.Test; |
| | | |
| | | /** |
| | | * These are more functional tests than unit tests. They go directly over |
| | | * LDAP for all of their operations. We use the builtin LDAPModify, |
| | | * These functional tests exercise ACI behavior over LDAP. We use the builtin LDAPModify, |
| | | * LDAPSearch, etc. tools to do this, as well as the ones that can |
| | | * do similar operations directly on LDIF (e.g. LDIFDiff). This is |
| | | * probably the easiest way to test the code, and it makes it easy to test |
| | |
| | | private static final String PROXY_USER_DN = "cn=proxy user," + OU_BASE_DN; |
| | | |
| | | /** |
| | | * We need to delete all of these between each test. This list needs to be |
| | | * bottom up so that it can be handed to LDAPDelete. |
| | | * Test entries in deletion order, with child entries before their parents. |
| | | */ |
| | | private static final String[] ALL_TEST_ENTRY_DNS_BOTTOM_UP = { |
| | | SALES_USER_1, |
| | |
| | | |
| | | |
| | | @BeforeMethod |
| | | public void clearBackend() throws Exception { |
| | | deleteAllTestEntries(); |
| | | public void clearBackend() { |
| | | // Wait for post-response delete plugins before the next test reuses the same DNs. |
| | | // An LDAP delete can return while AuthenticatedUsers is still processing the deletion. |
| | | for (String dn : ALL_TEST_ENTRY_DNS_BOTTOM_UP) { |
| | | DeleteOperation delete = getRootConnection().processDelete(dn); |
| | | ResultCode result = delete.getResultCode(); |
| | | assertTrue(result == ResultCode.SUCCESS || result == ResultCode.NO_SUCH_OBJECT, |
| | | "Could not delete test entry " + dn + " (" + result + ") " + delete.getErrorMessage()); |
| | | } |
| | | } |
| | | |
| | | // ----------------------------------------------------------------------------- |
| | |
| | | |
| | | private void modEntries(String ldif, String bindDn, String bindPassword) |
| | | throws Exception { |
| | | modEntries(ldif, bindDn, bindPassword, null, true, false); |
| | | modEntries(ldif, bindDn, bindPassword, null, true); |
| | | } |
| | | |
| | | private void modEntries(String ldif, String bindDn, String bindPassword, String proxyDN) |
| | | throws Exception { |
| | | modEntries(ldif, bindDn, bindPassword, proxyDN, true, false); |
| | | modEntries(ldif, bindDn, bindPassword, proxyDN, true); |
| | | } |
| | | |
| | | private void modEntriesExpectFailure(String ldif, String bindDn, |
| | | String bindPassword) throws Exception { |
| | | modEntries(ldif, bindDn, bindPassword, null, false, false); |
| | | modEntries(ldif, bindDn, bindPassword, null, false); |
| | | } |
| | | |
| | | private void _modEntries(String ldif, String bindDn, String bindPassword, |
| | |
| | | } |
| | | |
| | | private void modEntries(String ldif, String bindDn, String bindPassword, |
| | | String proxyDN, boolean expectSuccess, |
| | | boolean contFlag) |
| | | String proxyDN, boolean expectSuccess) |
| | | throws Exception { |
| | | File tempFile = getTemporaryLdifFile(); |
| | | TestCaseUtils.writeFile(tempFile, ldif); |
| | |
| | | argList.add(bindPassword); |
| | | argList.add("-f"); |
| | | argList.add(tempFile.getAbsolutePath()); |
| | | if(contFlag) |
| | | { |
| | | argList.add("-c"); |
| | | } |
| | | if(proxyDN != null) { |
| | | argList.add("-Y"); |
| | | argList.add("dn:" + proxyDN); |
| | |
| | | ldapModify(argList.toArray(args), expectSuccess); |
| | | } |
| | | |
| | | private void deleteAllTestEntries() throws Exception { |
| | | deleteEntries(ALL_TEST_ENTRY_DNS_BOTTOM_UP); |
| | | } |
| | | |
| | | private void deleteAttrFromEntry(String dn, String attr, String val, |
| | | String bindDN, String pwd, |
| | | boolean errorOk) throws Exception { |
| | |
| | | "changetype: modify", |
| | | "delete: " + attr, |
| | | attr + ":" + val)); |
| | | modEntries(ldif.toString(), bindDN, pwd, null, errorOk, false); |
| | | modEntries(ldif.toString(), bindDN, pwd, null, errorOk); |
| | | } |
| | | |
| | | |
| | |
| | | "dn: " + dn, |
| | | "changetype: modify", |
| | | "delete: " + attr)); |
| | | modEntries(ldif.toString(), DIR_MGR_DN, DIR_MGR_PW, null, errorOk, false); |
| | | modEntries(ldif.toString(), DIR_MGR_DN, DIR_MGR_PW, null, errorOk); |
| | | } |
| | | |
| | | private void deleteEntries(String[] entries) throws Exception { |
| | | // TODO: make this actually do a search first! |
| | | StringBuilder ldif = new StringBuilder(); |
| | | for (String dn: entries) { |
| | | ldif.append(TestCaseUtils.makeLdif( |
| | | "dn: " + dn, |
| | | "changetype: delete" |
| | | )); |
| | | } |
| | | modEntries(ldif.toString(), DIR_MGR_DN, DIR_MGR_PW, null, true, true); |
| | | } |
| | | |
| | | /** |
| | | * Return the difference between two ldif files. |
| | | */ |