dirsrvtests/tests/suites/paged_results/paged_results_test.py | 344 ++++++----- dirsrvtests/tests/tickets/ticket47664_test.py | 225 ------- 2 files changed, 188 insertions(+), 381 deletions(-)
New commits: commit 0532a630aa71c50c8886e9d78e3a077ab33f35f4 Author: Simon Pichugin spichugi@redhat.com Date: Tue May 10 16:45:43 2016 +0200
Ticket 47664 - Move CI test to the pr suite and refactor
Description: Verify that paging controls are not ignored if the effective rights control is specified. Refactor docstrings to RST format.
https://fedorahosted.org/389/ticket/47664
Reviewed by: nhosoi (Thanks!)
diff --git a/dirsrvtests/tests/suites/paged_results/paged_results_test.py b/dirsrvtests/tests/suites/paged_results/paged_results_test.py index 6fec5c7..9c1978e 100644 --- a/dirsrvtests/tests/suites/paged_results/paged_results_test.py +++ b/dirsrvtests/tests/suites/paged_results/paged_results_test.py @@ -11,7 +11,7 @@ import ldap import logging import pytest from random import sample -from ldap.controls import SimplePagedResultsControl +from ldap.controls import SimplePagedResultsControl, GetEffectiveRightsControl from lib389 import DirSrv, Entry, tools, tasks from lib389.tools import DirSrvTools from lib389._constants import * @@ -207,16 +207,15 @@ def test_search_success(topology, test_user, page_size, users_num): """Verify that search with a simple paged results control returns all entries it should without errors.
- @Feature: Simple paged results + :Feature: Simple paged results
- @Setup: Standalone instance, test user for binding, - variated number of users for the search base + :Setup: Standalone instance, test user for binding, + variated number of users for the search base
- @Steps: - 1. Bind as test user - 2. Search through added users with a simple paged control + :Steps: 1. Bind as test user + 2. Search through added users with a simple paged control
- @Assert: All users should be found + :Assert: All users should be found """
users_list = add_users(topology, users_num) @@ -258,18 +257,17 @@ def test_search_limits_fail(topology, test_user, page_size, users_num, throws expected exceptoins when corresponding limits are exceeded.
- @Feature: Simple paged results + :Feature: Simple paged results
- @Setup: Standalone instance, test user for binding, - variated number of users for the search base + :Setup: Standalone instance, test user for binding, + variated number of users for the search base
- @Steps: - 1. Bind as test user - 2. Set limit attribute to the value that will cause - an expected exception - 3. Search through added users with a simple paged control + :Steps: 1. Bind as test user + 2. Set limit attribute to the value that will cause + an expected exception + 3. Search through added users with a simple paged control
- @Assert: Should fail with appropriate exception + :Assert: Should fail with appropriate exception """
users_list = add_users(topology, users_num) @@ -347,17 +345,16 @@ def test_search_sort_success(topology, test_user): and a server side sort control returns all entries it should without errors.
- @Feature: Simple paged results + :Feature: Simple paged results
- @Setup: Standalone instance, test user for binding, - variated number of users for the search base + :Setup: Standalone instance, test user for binding, + variated number of users for the search base
- @Steps: - 1. Bind as test user - 2. Search through added users with a simple paged control - and a server side sort control + :Steps: 1. Bind as test user + 2. Search through added users with a simple paged control + and a server side sort control
- @Assert: All users should be found and sorted + :Assert: All users should be found and sorted """
users_num = 50 @@ -395,18 +392,17 @@ def test_search_abandon(topology, test_user): """Verify that search with simple paged results control can be abandon
- @Feature: Simple paged results + :Feature: Simple paged results
- @Setup: Standalone instance, test user for binding, - variated number of users for the search base + :Setup: Standalone instance, test user for binding, + variated number of users for the search base
- @Steps: - 1. Bind as test user - 2. Search through added users with a simple paged control - 3. Abandon the search + :Steps: 1. Bind as test user + 2. Search through added users with a simple paged control + 3. Abandon the search
- @Assert: It will throw an ldap.TIMEOUT exception, while trying - to get the rest of the search results + :Assert: It will throw an ldap.TIMEOUT exception, while trying + to get the rest of the search results """
users_num = 10 @@ -446,19 +442,18 @@ def test_search_with_timelimit(topology, test_user): to completion, each with a timelimit, it wouldn't fail, if we sleep for a time more than the timelimit.
- @Feature: Simple paged results + :Feature: Simple paged results
- @Setup: Standalone instance, test user for binding, - variated number of users for the search base + :Setup: Standalone instance, test user for binding, + variated number of users for the search base
- @Steps: - 1. Bind as test user - 2. Search through added users with a simple paged control - and timelimit set to 5 - 3. When the returned cookie is empty, wait 10 seconds - 4. Perform steps 2 and 3 three times in a row + :Steps: 1. Bind as test user + 2. Search through added users with a simple paged control + and timelimit set to 5 + 3. When the returned cookie is empty, wait 10 seconds + 4. Perform steps 2 and 3 three times in a row
- @Assert: No error happens + :Assert: No error happens """
users_num = 100 @@ -527,22 +522,21 @@ def test_search_dns_ip_aci(topology, test_user, aci_subject): """Verify that after performing multiple simple paged searches to completion on the suffix with DNS or IP based ACI
- @Feature: Simple paged results + :Feature: Simple paged results
- @Setup: Standalone instance, test user for binding, - variated number of users for the search base + :Setup: Standalone instance, test user for binding, + variated number of users for the search base
- @Steps: - 1. Back up and remove all previous ACI from suffix - 2. Add an anonymous ACI for DNS check - 3. Bind as test user - 4. Search through added users with a simple paged control - 5. Perform steps 4 three times in a row - 6. Return ACI to the initial state - 7. Go through all steps onece again, but use IP subjectdn - insted of DNS + :Steps: 1. Back up and remove all previous ACI from suffix + 2. Add an anonymous ACI for DNS check + 3. Bind as test user + 4. Search through added users with a simple paged control + 5. Perform steps 4 three times in a row + 6. Return ACI to the initial state + 7. Go through all steps onece again, but use IP subjectdn + insted of DNS
- @Assert: No error happens, all users should be found and sorted + :Assert: No error happens, all users should be found and sorted """
users_num = 100 @@ -602,18 +596,17 @@ def test_search_multiple_paging(topology, test_user): """Verify that after performing multiple simple paged searches on a single connection without a complition, it wouldn't fail.
- @Feature: Simple paged results + :Feature: Simple paged results
- @Setup: Standalone instance, test user for binding, - variated number of users for the search base + :Setup: Standalone instance, test user for binding, + variated number of users for the search base
- @Steps: - 1. Bind as test user - 2. Initiate the search with a simple paged control - 3. Acquire the returned cookie only one time - 4. Perform steps 2 and 3 three times in a row + :Steps: 1. Bind as test user + 2. Initiate the search with a simple paged control + 3. Acquire the returned cookie only one time + 4. Perform steps 2 and 3 three times in a row
- @Assert: No error happens + :Assert: No error happens """
users_num = 100 @@ -663,18 +656,17 @@ def test_search_invalid_cookie(topology, test_user, invalid_cookie): search with the simple paged results control throws a TypeError exception
- @Feature: Simple paged results + :Feature: Simple paged results
- @Setup: Standalone instance, test user for binding, - variated number of users for the search base + :Setup: Standalone instance, test user for binding, + variated number of users for the search base
- @Steps: - 1. Bind as test user - 2. Initiate the search with a simple paged control - 3. Put an invalid cookie (-1, 1000) to the control - 4. Continue the search + :Steps: 1. Bind as test user + 2. Initiate the search with a simple paged control + 3. Put an invalid cookie (-1, 1000) to the control + 4. Continue the search
- @Assert: It will throw an TypeError exception + :Assert: It will throw an TypeError exception """
users_num = 100 @@ -717,17 +709,16 @@ def test_search_abandon_with_zero_size(topology, test_user): """Verify that search with simple paged results control can be abandon using page_size = 0
- @Feature: Simple paged results + :Feature: Simple paged results
- @Setup: Standalone instance, test user for binding, - variated number of users for the search base + :Setup: Standalone instance, test user for binding, + variated number of users for the search base
- @Steps: - 1. Bind as test user - 2. Search through added users with a simple paged control - and page_size = 0 + :Steps: 1. Bind as test user + 2. Search through added users with a simple paged control + and page_size = 0
- @Assert: No cookie should be returned at all + :Assert: No cookie should be returned at all """
users_num = 10 @@ -767,18 +758,17 @@ def test_search_pagedsizelimit_success(topology, test_user): returns all entries it should without errors while valid value set to nsslapd-pagedsizelimit.
- @Feature: Simple paged results + :Feature: Simple paged results
- @Setup: Standalone instance, test user for binding, - 10 users for the search base + :Setup: Standalone instance, test user for binding, + 10 users for the search base
- @Steps: - 1. Set nsslapd-pagedsizelimit: 20 - 2. Bind as test user - 3. Search through added users with a simple paged control - using page_size = 10 + :Steps: 1. Set nsslapd-pagedsizelimit: 20 + 2. Bind as test user + 3. Search through added users with a simple paged control + using page_size = 10
- @Assert: All users should be found + :Assert: All users should be found """
users_num = 10 @@ -821,27 +811,27 @@ def test_search_nspagedsizelimit(topology, test_user, nsslapd-pagedsizelimit while performing search with the simple paged results control.
- @Feature: Simple paged results - - @Setup: Standalone instance, test user for binding, - 10 users for the search base - - @Steps: - 1. Set nsslapd-pagedsizelimit: 5 - 2. Set nsPagedSizeLimit: 15 - 3. Bind as test user - 4. Search through added users with a simple paged control - using page_size = 10 - 5. Bind as Directory Manager - 6. Restore all values - 7. Set nsslapd-pagedsizelimit: 15 - 8. Set nsPagedSizeLimit: 5 - 9. Bind as test user - 10. Search through added users with a simple paged control - using page_size = 10 - - @Assert: After the steps 1-4, it should PASS. - After the steps 7-10, it should throw SIZELIMIT_EXCEEDED exception + :Feature: Simple paged results + + :Setup: Standalone instance, test user for binding, + 10 users for the search base + + :Steps: 1. Set nsslapd-pagedsizelimit: 5 + 2. Set nsPagedSizeLimit: 15 + 3. Bind as test user + 4. Search through added users with a simple paged control + using page_size = 10 + 5. Bind as Directory Manager + 6. Restore all values + 7. Set nsslapd-pagedsizelimit: 15 + 8. Set nsPagedSizeLimit: 5 + 9. Bind as test user + 10. Search through added users with a simple paged control + using page_size = 10 + + :Assert: After the steps 1-4, it should PASS. + After the steps 7-10, it should throw + SIZELIMIT_EXCEEDED exception """
users_num = 10 @@ -892,27 +882,27 @@ def test_search_paged_limits(topology, test_user, conf_attr_values, expected_rs) nsslapd-lookthroughlimit can limit the administrator search abilities.
- @Feature: Simple paged results - - @Setup: Standalone instance, test user for binding, - 10 users for the search base - - @Steps: - 1. Set nsslapd-sizelimit and nsslapd-pagedsizelimit to 5000 - 2. Set nsslapd-idlistscanlimit: 120 - 3. Set nsslapd-lookthroughlimit: 122 - 4. Bind as test user - 5. Search through added users with a simple paged control - using page_size = 10 - 6. Bind as Directory Manager - 7. Set nsslapd-idlistscanlimit: 100 - 8. Set nsslapd-lookthroughlimit: 100 - 9. Bind as test user - 10. Search through added users with a simple paged control - using page_size = 10 - - @Assert: After the steps 1-4, it should PASS. - After the steps 7-10, it should throw ADMINLIMIT_EXCEEDED exception + :Feature: Simple paged results + + :Setup: Standalone instance, test user for binding, + 10 users for the search base + + :Steps: 1. Set nsslapd-sizelimit and nsslapd-pagedsizelimit to 5000 + 2. Set nsslapd-idlistscanlimit: 120 + 3. Set nsslapd-lookthroughlimit: 122 + 4. Bind as test user + 5. Search through added users with a simple paged control + using page_size = 10 + 6. Bind as Directory Manager + 7. Set nsslapd-idlistscanlimit: 100 + 8. Set nsslapd-lookthroughlimit: 100 + 9. Bind as test user + 10. Search through added users with a simple paged control + using page_size = 10 + + :Assert: After the steps 1-4, it should PASS. + After the steps 7-10, it should throw + ADMINLIMIT_EXCEEDED exception """
users_num = 101 @@ -970,28 +960,28 @@ def test_search_paged_user_limits(topology, test_user, conf_attr_values, expecte override nsslapd-idlistscanlimit and nsslapd-lookthroughlimit while performing search with the simple paged results control.
- @Feature: Simple paged results - - @Setup: Standalone instance, test user for binding, - 10 users for the search base - - @Steps: - 1. Set nsslapd-idlistscanlimit: 1000 - 2. Set nsslapd-lookthroughlimit: 1000 - 3. Set nsPagedIDListScanLimit: 120 - 4. Set nsPagedLookthroughLimit: 122 - 5. Bind as test user - 6. Search through added users with a simple paged control - using page_size = 10 - 7. Bind as Directory Manager - 8. Set nsPagedIDListScanLimit: 100 - 9. Set nsPagedLookthroughLimit: 100 - 10. Bind as test user - 11. Search through added users with a simple paged control - using page_size = 10 - - @Assert: After the steps 1-4, it should PASS. - After the steps 8-11, it should throw ADMINLIMIT_EXCEEDED exception + :Feature: Simple paged results + + :Setup: Standalone instance, test user for binding, + 10 users for the search base + + :Steps: 1. Set nsslapd-idlistscanlimit: 1000 + 2. Set nsslapd-lookthroughlimit: 1000 + 3. Set nsPagedIDListScanLimit: 120 + 4. Set nsPagedLookthroughLimit: 122 + 5. Bind as test user + 6. Search through added users with a simple paged control + using page_size = 10 + 7. Bind as Directory Manager + 8. Set nsPagedIDListScanLimit: 100 + 9. Set nsPagedLookthroughLimit: 100 + 10. Bind as test user + 11. Search through added users with a simple paged control + using page_size = 10 + + :Assert: After the steps 1-4, it should PASS. + After the steps 8-11, it should throw + ADMINLIMIT_EXCEEDED exception """
users_num = 101 @@ -1041,6 +1031,48 @@ def test_search_paged_user_limits(topology, test_user, conf_attr_values, expecte 'nsPagedLookthroughLimit', user_lookthrough_attr_bck)
+def test_ger_basic(topology, test_user): + """Verify that search with a simple paged results control + and get effective rights control returns all entries + it should without errors. + + :Feature: Simple paged results + + :Setup: Standalone instance, test user for binding, + variated number of users for the search base + + :Steps: 1. Search through added users with a simple paged control + and get effective rights control + + :Assert: All users should be found, every found entry should have + an 'attributeLevelRights' returned + """ + + users_list = add_users(topology, 20) + search_flt = r'(uid=test*)' + searchreq_attrlist = ['dn', 'sn'] + page_size = 4 + + try: + log.info('Set bind to directory manager') + topology.standalone.simple_bind_s(DN_DM, PASSWORD) + + log.info('Create simple paged results control instance') + spr_ctrl = SimplePagedResultsControl(True, size=page_size, cookie='') + ger_ctrl = GetEffectiveRightsControl(True, "dn: " + DN_DM) + + all_results = paged_search(topology, [spr_ctrl, ger_ctrl], + search_flt, searchreq_attrlist) + + log.info('{} results'.format(len(all_results))) + assert len(all_results) == len(users_list) + log.info('Check for attributeLevelRights') + assert all(attrs['attributeLevelRights'][0] for dn, attrs in all_results) + finally: + log.info('Remove added users') + del_users(topology, users_list) + + if __name__ == '__main__': # Run isolated # -s for DEBUG mode diff --git a/dirsrvtests/tests/tickets/ticket47664_test.py b/dirsrvtests/tests/tickets/ticket47664_test.py deleted file mode 100644 index 460828d..0000000 --- a/dirsrvtests/tests/tickets/ticket47664_test.py +++ /dev/null @@ -1,225 +0,0 @@ -# --- BEGIN COPYRIGHT BLOCK --- -# Copyright (C) 2015 Red Hat, Inc. -# All rights reserved. -# -# License: GPL (version 3 or any later version). -# See LICENSE for details. -# --- END COPYRIGHT BLOCK --- -# -import os -import sys -import time -import ldap -import logging -import pytest -from lib389 import DirSrv, Entry, tools, tasks -from lib389.tools import DirSrvTools -from lib389._constants import * -from lib389.properties import * -from lib389.tasks import * -from ldap.controls import SimplePagedResultsControl -from ldap.controls.simple import GetEffectiveRightsControl - -log = logging.getLogger(__name__) - -installation_prefix = None - -MYSUFFIX = 'o=ticket47664.org' -MYSUFFIXBE = 'ticket47664' - -_MYLDIF = 'ticket47664.ldif' - -SEARCHFILTER = '(objectclass=*)' - - -class TopologyStandalone(object): - def __init__(self, standalone): - standalone.open() - self.standalone = standalone - - -@pytest.fixture(scope="module") -def topology(request): - ''' - This fixture is used to standalone topology for the 'module'. - ''' - global installation_prefix - - if installation_prefix: - args_instance[SER_DEPLOYED_DIR] = installation_prefix - - standalone = DirSrv(verbose=False) - - # Args for the standalone instance - args_instance[SER_HOST] = HOST_STANDALONE - args_instance[SER_PORT] = PORT_STANDALONE - args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE - args_standalone = args_instance.copy() - standalone.allocate(args_standalone) - - # Get the status of the instance and restart it if it exists - instance_standalone = standalone.exists() - - # Remove the instance - if instance_standalone: - standalone.delete() - - # Create the instance - standalone.create() - - # Used to retrieve configuration information (dbdir, confdir...) - standalone.open() - - # clear the tmp directory - standalone.clearTmpDir(__file__) - - # Here we have standalone instance up and running - return TopologyStandalone(standalone) - - -def test_ticket47664_run(topology): - """ - Import 20 entries - Search with Simple Paged Results Control (pagesize = 4) + Get Effective Rights Control (attrs list = ['cn']) - If Get Effective Rights attribute (attributeLevelRights for 'cn') is returned 4 attrs / page AND - the page count == 20/4, then the fix is verified. - """ - log.info('Testing Ticket 47664 - paged results control is not working in some cases when we have a subsuffix') - - # bind as directory manager - topology.standalone.log.info("Bind as %s" % DN_DM) - topology.standalone.simple_bind_s(DN_DM, PASSWORD) - - topology.standalone.log.info("\n\n######################### SETUP SUFFIX o=ticket47664.org ######################\n") - - topology.standalone.backend.create(MYSUFFIX, {BACKEND_NAME: MYSUFFIXBE}) - topology.standalone.mappingtree.create(MYSUFFIX, bename=MYSUFFIXBE) - - topology.standalone.log.info("\n\n######################### Generate Test data ######################\n") - - # get tmp dir - mytmp = topology.standalone.getDir(__file__, TMP_DIR) - if mytmp is None: - mytmp = "/tmp" - - MYLDIF = '%s%s' % (mytmp, _MYLDIF) - os.system('ls %s' % MYLDIF) - os.system('rm -f %s' % MYLDIF) - if hasattr(topology.standalone, 'prefix'): - prefix = topology.standalone.prefix - else: - prefix = None - dbgen_prog = prefix + '/bin/dbgen.pl' - topology.standalone.log.info('dbgen_prog: %s' % dbgen_prog) - os.system('%s -s %s -o %s -n 14' % (dbgen_prog, MYSUFFIX, MYLDIF)) - cmdline = 'egrep dn: %s | wc -l' % MYLDIF - p = os.popen(cmdline, "r") - dnnumstr = p.readline() - dnnum = int(dnnumstr) - topology.standalone.log.info("We have %d entries.\n", dnnum) - - topology.standalone.log.info("\n\n######################### Import Test data ######################\n") - - args = {TASK_WAIT: True} - importTask = Tasks(topology.standalone) - importTask.importLDIF(MYSUFFIX, MYSUFFIXBE, MYLDIF, args) - - topology.standalone.log.info("\n\n######################### SEARCH ALL ######################\n") - topology.standalone.log.info("Bind as %s and add the READ/SEARCH SELFDN aci" % DN_DM) - topology.standalone.simple_bind_s(DN_DM, PASSWORD) - - entries = topology.standalone.search_s(MYSUFFIX, ldap.SCOPE_SUBTREE, SEARCHFILTER) - topology.standalone.log.info("Returned %d entries.\n", len(entries)) - - #print entries - - assert dnnum == len(entries) - - topology.standalone.log.info('%d entries are successfully imported.' % dnnum) - - topology.standalone.log.info("\n\n######################### SEARCH WITH SIMPLE PAGED RESULTS CONTROL ######################\n") - - page_size = 4 - spr_req_ctrl = SimplePagedResultsControl(True, size=page_size, cookie='') - ger_req_ctrl = GetEffectiveRightsControl(True, "dn: " + DN_DM) - - known_ldap_resp_ctrls = { - SimplePagedResultsControl.controlType: SimplePagedResultsControl, - } - - topology.standalone.log.info("Calling search_ext...") - msgid = topology.standalone.search_ext(MYSUFFIX, - ldap.SCOPE_SUBTREE, - SEARCHFILTER, - ['cn'], - serverctrls=[spr_req_ctrl, ger_req_ctrl]) - attrlevelrightscnt = 0 - pageddncnt = 0 - pages = 0 - while True: - pages += 1 - - topology.standalone.log.info("Getting page %d" % pages) - rtype, rdata, rmsgid, responcectrls = topology.standalone.result3(msgid, resp_ctrl_classes=known_ldap_resp_ctrls) - topology.standalone.log.info("%d results" % len(rdata)) - pageddncnt += len(rdata) - - topology.standalone.log.info("Results:") - for dn, attrs in rdata: - topology.standalone.log.info("dn: %s" % dn) - topology.standalone.log.info("attributeLevelRights: %s" % attrs['attributeLevelRights'][0]) - if attrs['attributeLevelRights'][0] != "": - attrlevelrightscnt += 1 - - pctrls = [ - c for c in responcectrls if c.controlType == SimplePagedResultsControl.controlType - ] - if not pctrls: - topology.standalone.log.info('Warning: Server ignores RFC 2696 control.') - break - - if pctrls[0].cookie: - spr_req_ctrl.cookie = pctrls[0].cookie - topology.standalone.log.info("cookie: %s" % spr_req_ctrl.cookie) - msgid = topology.standalone.search_ext(MYSUFFIX, - ldap.SCOPE_SUBTREE, - SEARCHFILTER, - ['cn'], - serverctrls=[spr_req_ctrl, ger_req_ctrl]) - else: - topology.standalone.log.info("No cookie") - break - - topology.standalone.log.info("Paged result search returned %d entries in %d pages.\n", pageddncnt, pages) - - assert dnnum == len(entries) - assert dnnum == attrlevelrightscnt - assert pages == (dnnum / page_size) - topology.standalone.log.info("ticket47664 was successfully verified.") - - -def test_ticket47664_final(topology): - topology.standalone.delete() - log.info('Testcase PASSED') - - -def run_isolated(): - ''' - run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..) - To run isolated without py.test, you need to - - edit this file and comment '@pytest.fixture' line before 'topology' function. - - set the installation prefix - - run this program - ''' - global installation_prefix - installation_prefix = None - - topo = topology(True) - test_ticket47664_run(topo) - - test_ticket47664_final(topo) - - -if __name__ == '__main__': - run_isolated() -
389-commits@lists.fedoraproject.org