Debian Codegraph @

dirsrvtests/tests/suites/acl/enhanced_aci_modrnd_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2020 Red Hat, Inc.
3 # All rights reserved.
4 #
5 # License: GPL (version 3 or any later version).
6 # See LICENSE for details.
7 # --- END COPYRIGHT BLOCK ---
8 #
9 import pytest
10 from lib389.tasks import *
11 from lib389.utils import *
12 from test389.topologies import topology_st
13
14 pytestmark = pytest.mark.tier1
15
16 logging.getLogger(__name__).setLevel(logging.DEBUG)
17 log = logging.getLogger(__name__)
18
19 CONTAINER_1_OU = 'test_ou_1'
20 CONTAINER_2_OU = 'test_ou_2'
21 CONTAINER_1 = f'ou={CONTAINER_1_OU},dc=example,dc=com'
22 CONTAINER_2 = f'ou={CONTAINER_2_OU},dc=example,dc=com'
23 USER_CN = 'test_user'
24 USER_PWD = 'Secret123'
25 USER = f'cn={USER_CN},{CONTAINER_1}'
26
27
28 @pytest.fixture(scope="module")
29 def env_setup(topology_st):
30 """Adds two containers, one user and two ACI rules"""
31
32 log.info("Add a container: %s" % CONTAINER_1)
33 topology_st.standalone.add_s(Entry((CONTAINER_1,
34 {'objectclass': ['top','organizationalunit'],
35 'ou': CONTAINER_1_OU,
36 })))
37
38 log.info("Add a container: %s" % CONTAINER_2)
39 topology_st.standalone.add_s(Entry((CONTAINER_2,
40 {'objectclass': ['top', 'organizationalunit'],
41 'ou': CONTAINER_2_OU,
42 })))
43
44 log.info("Add a user: %s" % USER)
45 topology_st.standalone.add_s(Entry((USER,
46 {'objectclass': 'top person'.split(),
47 'cn': USER_CN,
48 'sn': USER_CN,
49 'userpassword': USER_PWD
50 })))
51
52 ACI_TARGET = '(targetattr="*")'
53 ACI_ALLOW = '(version 3.0; acl "All rights for %s"; allow (all) ' % USER
54 ACI_SUBJECT = 'userdn="ldap:///%s";)' % USER
55 ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
56 mod = [(ldap.MOD_ADD, 'aci', ensure_bytes(ACI_BODY))]
57
58 log.info("Add an ACI 'allow (all)' by %s to the %s" % (USER,
59 CONTAINER_1))
60 topology_st.standalone.modify_s(CONTAINER_1, mod)
61
62 log.info("Add an ACI 'allow (all)' by %s to the %s" % (USER,
63 CONTAINER_2))
64 topology_st.standalone.modify_s(CONTAINER_2, mod)
65
66
67 def test_enhanced_aci_modrnd(topology_st, env_setup):
68 """Tests, that MODRDN operation is allowed,
69 if user has ACI right '(all)' under superior entries,
70 but doesn't have '(modrdn)'
71
72 :id: 492cf2a9-2efe-4e3b-955e-85eca61d66b9
73 :setup: Standalone instance
74 :steps:
75 1. Create two containers
76 2. Create a user within "ou=test_ou_1,dc=example,dc=com"
77 3. Add an aci with a rule "cn=test_user is allowed all" within these containers
78 4. Run MODRDN operation on the "cn=test_user" and set "newsuperior" to
79 the "ou=test_ou_2,dc=example,dc=com"
80 5. Check there is no user under container one (ou=test_ou_1,dc=example,dc=com)
81 6. Check there is a user under container two (ou=test_ou_2,dc=example,dc=com)
82
83 :expectedresults:
84 1. Two containers should be created
85 2. User should be added successfully
86 3. This should pass
87 4. This should pass
88 5. User should not be found under container ou=test_ou_1,dc=example,dc=com
89 6. User should be found under container ou=test_ou_2,dc=example,dc=com
90 """
91
92 log.info("Bind as %s" % USER)
93
94 topology_st.standalone.simple_bind_s(USER, USER_PWD)
95
96 log.info("User MODRDN operation from %s to %s" % (CONTAINER_1,
97 CONTAINER_2))
98
99 topology_st.standalone.rename_s(USER, "cn=%s" % USER_CN,
100 newsuperior=CONTAINER_2, delold=1)
101
102 log.info("Check there is no user in %s" % CONTAINER_1)
103 entries = topology_st.standalone.search_s(CONTAINER_1,
104 ldap.SCOPE_ONELEVEL,
105 'cn=%s' % USER_CN)
106 assert not entries
107
108 log.info("Check there is our user in %s" % CONTAINER_2)
109 entries = topology_st.standalone.search_s(CONTAINER_2,
110 ldap.SCOPE_ONELEVEL,
111 'cn=%s' % USER_CN)
112 assert entries
113
114
115 if __name__ == '__main__':
116 # Run isolated
117 # -s for DEBUG mode
118 # -v for additional verbose
119 CURRENT_FILE = os.path.realpath(__file__)
120 pytest.main("-s -v %s" % CURRENT_FILE)