Debian Codegraph @

dirsrvtests/tests/suites/plugins/referint_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2021 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 '''
10 Created on Dec 12, 2019
11
12 @author: tbordaz
13 '''
14 import logging
15 import pytest
16 from lib389 import Entry
17 from lib389.plugins import ReferentialIntegrityPlugin
18 from lib389._constants import DEFAULT_SUFFIX
19 from lib389.idm.user import UserAccounts
20 from lib389.idm.group import Groups
21 from test389.topologies import topology_st as topo
22
23 pytestmark = pytest.mark.tier1
24
25 log = logging.getLogger(__name__)
26
27 ESCAPED_RDN_BASE = "foo\\,oo"
28 def _user_get_dn(no):
29 uid = '%s%d' % (ESCAPED_RDN_BASE, no)
30 dn = 'uid=%s,%s' % (uid, DEFAULT_SUFFIX)
31 return (uid, dn)
32
33 def add_escaped_user(server, no):
34 (uid, dn) = _user_get_dn(no)
35 log.fatal('Adding user (%s): ' % dn)
36 users = UserAccounts(server, DEFAULT_SUFFIX, None)
37 user_properties = {
38 'objectclass': ['top', 'person', 'organizationalPerson', 'inetOrgPerson', 'posixAccount'],
39 'uid': uid,
40 'cn' : uid,
41 'sn' : uid,
42 'uidNumber' : '1000',
43 'gidNumber' : '2000',
44 'homeDirectory' : '/home/testuser',
45 }
46 users.create(properties=user_properties)
47 return dn
48
49 def test_referential_false_failure(topo):
50 """On MODRDN referential integrity can erroneously fail
51
52 :id: f77aeb80-c4c4-471b-8c1b-4733b714778b
53 :setup: Standalone Instance
54 :steps:
55 1. Configure the plugin
56 2. Create a group
57 - 1rst member the one that will be move
58 - more than 128 members
59 - last member is a DN containing escaped char
60 3. Rename the 1rst member
61 :expectedresults:
62 1. should succeed
63 2. should succeed
64 3. should succeed
65 """
66
67 inst = topo[0]
68
69 # stop the plugin, and start it
70 plugin = ReferentialIntegrityPlugin(inst)
71 plugin.disable()
72 plugin.enable()
73
74 ############################################################################
75 # Configure plugin
76 ############################################################################
77 GROUP_CONTAINER = "ou=groups,%s" % DEFAULT_SUFFIX
78 plugin.replace('referint-membership-attr', 'member')
79 plugin.replace('nsslapd-plugincontainerscope', GROUP_CONTAINER)
80
81 ############################################################################
82 # Creates a group with members having escaped DN
83 ############################################################################
84 # Add some users and a group
85 users = UserAccounts(inst, DEFAULT_SUFFIX, None)
86 user1 = users.create_test_user(uid=1001)
87 user2 = users.create_test_user(uid=1002)
88
89 groups = Groups(inst, GROUP_CONTAINER, None)
90 group = groups.create(properties={'cn': 'group'})
91 group.add('member', user2.dn)
92 group.add('member', user1.dn)
93
94 # Add more than 128 members so that referint follows the buggy path
95 for i in range(130):
96 escaped_user = add_escaped_user(inst, i)
97 group.add('member', escaped_user)
98
99 ############################################################################
100 # Check that the MODRDN succeeds
101 ###########################################################################
102 # Here we need to restart so that member values are taken in the right order
103 # the last value is the escaped one
104 inst.restart()
105
106 # Here if the bug is fixed, referential is able to update the member value
107 user1.rename('uid=new_test_user_1001', newsuperior=DEFAULT_SUFFIX, deloldrdn=False)
108
109
110 def test_invalid_referint_log(topo):
111 """If there is an invalid log line in the referint log, make sure the server
112 does not crash at startup
113
114 :id: 34807b5a-ab17-4281-ae48-4e3513e19145
115 :setup: Standalone Instance
116 :steps:
117 1. Set the referint log delay
118 2. Create invalid log
119 3. Start the server (no crash)
120 :expectedresults:
121 1. Success
122 2. Success
123 3. Success
124 """
125
126 inst = topo.standalone
127
128 # Set delay - required for log parsing at server startup
129 plugin = ReferentialIntegrityPlugin(inst)
130 plugin.enable()
131 plugin.set_update_delay('2')
132 logfile = plugin.get_log_file()
133 inst.restart()
134
135 # Create invalid log
136 inst.stop()
137 with open(logfile, 'w') as log_fh:
138 log_fh.write("CRASH\n")
139
140 # Start the instance
141 inst.start()
142 assert inst.status()
143
144
145 if __name__ == '__main__':
146 # Run isolated
147 # -s for DEBUG mode
148 CURRENT_FILE = os.path.realpath(__file__)
149 pytest.main("-s %s" % CURRENT_FILE)