File: ticket50234_test.py

package info (click to toggle)
389-ds-base 2.3.1%2Bdfsg1-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 37,536 kB
  • sloc: ansic: 306,972; python: 96,937; cpp: 10,257; perl: 2,854; makefile: 2,046; sh: 925; yacc: 806; xml: 379; lex: 366; javascript: 148; java: 50
file content (72 lines) | stat: -rw-r--r-- 2,473 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# --- BEGIN COPYRIGHT BLOCK ---
# Copyright (C) 2019 Red Hat, Inc.
# All rights reserved.
#
# License: GPL (version 3 or any later version).
# See LICENSE for details.
# --- END COPYRIGHT BLOCK ---
#
import logging
import time
import ldap
import pytest

from lib389.topologies import topology_st

from lib389._constants import DEFAULT_SUFFIX

from lib389.idm.user import UserAccount, UserAccounts
from lib389.idm.organizationalunit import OrganizationalUnit

pytestmark = pytest.mark.tier2

log = logging.getLogger(__name__)

def test_ticket50234(topology_st):
    """
    The fix for ticket 50234


    The test sequence is:
    - create more than 10 entries with objectclass organizational units ou=org{}
    - add an Account in one of them, eg below ou=org5
    - do searches with search base ou=org5 and search filter "objectclass=organizationalunit"
    - a subtree search should return 1 entry, the base entry
    - a onelevel search should return no entry
    """

    log.info('Testing Ticket 50234 - onelvel search returns not matching entry')

    for i in range(1,15):
        ou = OrganizationalUnit(topology_st.standalone, "ou=Org{},{}".format(i, DEFAULT_SUFFIX))
        ou.create(properties={'ou': 'Org'.format(i)})

    properties = {
            'uid': 'Jeff Vedder',
            'cn': 'Jeff Vedder',
            'sn': 'user',
            'uidNumber': '1000',
            'gidNumber': '2000',
            'homeDirectory': '/home/' + 'JeffVedder',
            'userPassword': 'password'
        }
    user = UserAccount(topology_st.standalone, "cn=Jeff Vedder,ou=org5,{}".format(DEFAULT_SUFFIX))
    user.create(properties=properties)

    # in a subtree search the entry used as search base matches the filter and shoul be returned
    ent = topology_st.standalone.getEntry("ou=org5,{}".format(DEFAULT_SUFFIX), ldap.SCOPE_SUBTREE, "(objectclass=organizationalunit)")

    # in a onelevel search the only child is an useraccount which does not match the filter
    # no entry should be returned, which would cause getEntry to raise an exception we need to handle
    found = 1
    try:
        ent = topology_st.standalone.getEntry("ou=org5,{}".format(DEFAULT_SUFFIX), ldap.SCOPE_ONELEVEL, "(objectclass=organizationalunit)")
    except ldap.NO_SUCH_OBJECT:
        found = 0
    assert (found == 0)

if __name__ == '__main__':
    # Run isolated
    # -s for DEBUG mode
    CURRENT_FILE = os.path.realpath(__file__)
    pytest.main("-s %s" % CURRENT_FILE)