Пример #1
0
def test_search_sort_success(topology_st, create_user):
    """Verify that search with a simple paged results control
    and a server side sort control returns all entries
    it should without errors.

    :id: 17d8b150-ed43-41e1-b80f-ee9b4ce45155
    :customerscenario: True
    :setup: Standalone instance, test user for binding,
            varying 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
    :expectedresults:
        1. Bind should be successful
        2. All users should be found and sorted
    """

    users_num = 50
    page_size = 5
    users_list = add_users(topology_st, users_num, DEFAULT_SUFFIX)
    search_flt = r'(uid=test*)'
    searchreq_attrlist = ['dn', 'sn']

    try:
        conn = create_user.bind(TEST_USER_PWD)

        req_ctrl = SimplePagedResultsControl(True, size=page_size, cookie='')
        sort_ctrl = SSSRequestControl(True, ['sn'])

        log.info('Initiate ldapsearch with created control instance')
        log.info('Collect data with sorting')
        controls = [req_ctrl, sort_ctrl]
        results_sorted = paged_search(conn, DEFAULT_SUFFIX, controls,
                                      search_flt, searchreq_attrlist)

        log.info('Substring numbers from user DNs')
        # r_nums = map(lambda x: int(x[0][8:13]), results_sorted)
        r_nums = [int(x[0][8:13]) for x in results_sorted]

        log.info('Assert that list is sorted')
        assert all(r_nums[i] <= r_nums[i + 1] for i in range(len(r_nums) - 1))
    finally:
        del_users(users_list)
Пример #2
0
def test_sss_mr(topo):
    """Test matching rule/server side sort does not crash DS

    :id: 48c73d76-1694-420f-ab55-187135f2d260
    :setup: Standalone Instance
    :steps:
        1. Add sample entries to the database
        2. Perform search using server side control (uid:2.5.13.3)
    :expectedresults:
        1. Success
        2. Success
    """

    log.info("Creating LDIF...")
    ldif_dir = topo.standalone.get_ldif_dir()
    ldif_file = os.path.join(ldif_dir, 'mr-crash.ldif')
    dbgen_users(topo.standalone, 5, ldif_file, DEFAULT_SUFFIX)

    log.info("Importing LDIF...")
    topo.standalone.stop()
    assert topo.standalone.ldif2db(DEFAULT_BENAME, None, None, None, ldif_file)
    topo.standalone.start()

    log.info(
        'Search using server side sorting using undefined mr in the attr...')
    sort_ctrl = SSSRequestControl(True, ['uid:2.5.13.3'])
    controls = [sort_ctrl]
    msg_id = topo.standalone.search_ext(DEFAULT_SUFFIX,
                                        ldap.SCOPE_SUBTREE,
                                        "objectclass=*",
                                        serverctrls=controls)
    try:
        rtype, rdata, rmsgid, response_ctrl = topo.standalone.result3(msg_id)
    except ldap.OPERATIONS_ERROR:
        pass

    log.info("Test PASSED")
Пример #3
0
def test_search_limits_fail(topology_st, test_user, page_size, users_num,
                            suffix, attr_name, attr_value, expected_err):
    """Verify that search with a simple paged results control
    throws expected exceptoins when corresponding limits are
    exceeded.

    :id: e3067107-bd6d-493d-9989-3e641a9337b0
    :setup: Standalone instance, test user for binding,
            varying 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
    :expectedresults:
        1. Bind should be successful
        2. Operation should be successful
        3. Should fail with appropriate exception
    """

    users_list = add_users(topology_st, users_num, DEFAULT_SUFFIX)
    attr_value_bck = change_conf_attr(topology_st, suffix, attr_name,
                                      attr_value)
    conf_param_dict = {attr_name: attr_value}
    search_flt = r'(uid=test*)'
    searchreq_attrlist = ['dn', 'sn']
    controls = []

    try:
        log.info('Set user bind')
        conn = test_user.bind(TEST_USER_PWD)

        log.info('Create simple paged results control instance')
        req_ctrl = SimplePagedResultsControl(True, size=page_size, cookie='')
        controls.append(req_ctrl)
        if attr_name == 'nsslapd-idlistscanlimit':
            sort_ctrl = SSSRequestControl(True, ['sn'])
            controls.append(sort_ctrl)
        log.info('Initiate ldapsearch with created control instance')
        msgid = conn.search_ext(DEFAULT_SUFFIX,
                                ldap.SCOPE_SUBTREE,
                                search_flt,
                                searchreq_attrlist,
                                serverctrls=controls)

        time_val = conf_param_dict.get('nsslapd-timelimit')
        if time_val:
            time.sleep(int(time_val) + 10)

        pages = 0
        all_results = []
        pctrls = []
        while True:
            log.info('Getting page %d' % (pages, ))
            if pages == 0 and (time_val
                               or attr_name in ('nsslapd-lookthroughlimit',
                                                'nsslapd-pagesizelimit')):
                rtype, rdata, rmsgid, rctrls = conn.result3(msgid)
            else:
                with pytest.raises(expected_err):
                    rtype, rdata, rmsgid, rctrls = conn.result3(msgid)
                    all_results.extend(rdata)
                    pages += 1
                    pctrls = [
                        c for c in rctrls if c.controlType ==
                        SimplePagedResultsControl.controlType
                    ]

            if pctrls:
                if pctrls[0].cookie:
                    # Copy cookie from response control to request control
                    req_ctrl.cookie = pctrls[0].cookie
                    msgid = conn.search_ext(DEFAULT_SUFFIX,
                                            ldap.SCOPE_SUBTREE,
                                            search_flt,
                                            searchreq_attrlist,
                                            serverctrls=controls)
                else:
                    break  # No more pages available
            else:
                break
    finally:
        del_users(users_list)
        change_conf_attr(topology_st, suffix, attr_name, attr_value_bck)