Debian Codegraph @

dirsrvtests/tests/suites/replication/sasl_m2_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2022 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 logging
10 import os
11 import pytest
12 import ldap
13 import uuid
14 from lib389.utils import ds_is_older, valgrind_enable, valgrind_disable, valgrind_get_results_file, valgrind_check_file
15
16 from lib389.idm.services import ServiceAccounts
17 from lib389.idm.group import Groups
18 from lib389.config import CertmapLegacy, Config
19 from lib389._constants import DEFAULT_SUFFIX
20 from lib389.agreement import Agreements
21 from lib389._mapped_object import DSLdapObject
22 from lib389.replica import ReplicationManager, Replicas, BootstrapReplicationManager
23 from test389.topologies import topology_m2 as topo_m2
24
25 pytestmark = pytest.mark.tier1
26
27 DEBUGGING = os.getenv("DEBUGGING", default=False)
28 if DEBUGGING:
29 logging.getLogger(__name__).setLevel(logging.DEBUG)
30 else:
31 logging.getLogger(__name__).setLevel(logging.INFO)
32 log = logging.getLogger(__name__)
33
34 def set_sasl_md5_client_auth(inst, to):
35 # Create the certmap before we restart
36 cm = CertmapLegacy(to)
37 certmaps = cm.list()
38 certmaps['default']['nsSaslMapRegexString'] = '^dn:\\(.*\\)'
39 certmaps['default']['nsSaslMapBaseDNTemplate'] = 'cn=config'
40 certmaps['default']['nsSaslMapFilterTemplate'] = '(objectclass=*)'
41 cm.set(certmaps)
42
43 Config(to).replace("passwordStorageScheme", 'CLEAR')
44
45 # Create a repl manager on the replica
46 replication_manager_pwd = 'secret12'
47 brm = BootstrapReplicationManager(to)
48 try:
49 brm.delete()
50 except ldap.NO_SUCH_OBJECT:
51 pass
52 brm.create(properties={
53 'cn': brm.common_name,
54 'userPassword': replication_manager_pwd
55 })
56 replication_manager_dn = brm.dn
57
58 replica = Replicas(inst).get(DEFAULT_SUFFIX)
59 replica.set('nsDS5ReplicaBindDN', brm.dn)
60 replica.remove_all('nsDS5ReplicaBindDNgroup')
61 agmt = replica.get_agreements().list()[0]
62 agmt.replace_many(
63 ('nsDS5ReplicaBindMethod', 'SASL/DIGEST-MD5'),
64 ('nsDS5ReplicaTransportInfo', 'LDAP'),
65 ('nsDS5ReplicaPort', str(to.port)),
66 ('nsDS5ReplicaBindDN', replication_manager_dn),
67 ('nsDS5ReplicaCredentials', replication_manager_pwd),
68 )
69
70
71 def gen_valgrind_wrapper(dir):
72 name=f"{dir}/VALGRIND"
73 with open(name, 'w') as f:
74 f.write('#!/bin/sh\n')
75 f.write('export SASL_PATH=foo\n')
76 f.write(f'valgrind -q --tool=memcheck --leak-check=yes --leak-resolution=high --num-callers=50 --log-file=/var/tmp/slapd.vg.$$ {dir}/ns-slapd.original "$@"\n')
77 os.chmod(name, 0o755)
78 return name
79
80 @pytest.fixture
81 def use_valgrind(topo_m2, request):
82 """Adds entries to the supplier1"""
83
84 log.info("Enable valgrind")
85 m1 = topo_m2.ms['supplier1']
86 m2 = topo_m2.ms['supplier2']
87 if m1.has_asan():
88 pytest.skip('Tescase using valgring cannot run on asan enabled build')
89 return
90 set_sasl_md5_client_auth(m1, m2)
91 set_sasl_md5_client_auth(m2, m1)
92 m1.stop()
93 m2.stop()
94 m1.systemd_override = False
95 m2.systemd_override = False
96 valgrind_enable(m1.ds_paths.sbin_dir, gen_valgrind_wrapper(m1.ds_paths.sbin_dir))
97
98 def fin():
99 log.info("Disable valgrind")
100 valgrind_disable(m1.ds_paths.sbin_dir)
101
102 request.addfinalizer(fin)
103
104
105 def test_repl_sasl_md5_auth(topo_m2):
106 """Test replication with SASL digest-md5 authentication
107
108 :id: 922d16f8-662a-4915-a39e-0aecd7c8e6e2
109 :setup: Two supplier replication
110 :steps:
111 1. Set sasl digest/md4 on both suppliers
112 2. Restart the instance
113 3. Check that replication works
114 :expectedresults:
115 1. Success
116 2. Success
117 3. Replication works
118 """
119
120 m1 = topo_m2.ms['supplier1']
121 m2 = topo_m2.ms['supplier2']
122
123 set_sasl_md5_client_auth(m1, m2)
124 set_sasl_md5_client_auth(m2, m1)
125
126 m1.restart()
127 m2.restart()
128
129 repl = ReplicationManager(DEFAULT_SUFFIX)
130 repl.test_replication_topology(topo_m2)
131
132
133 @pytest.mark.skipif(not os.path.exists('/usr/bin/valgrind'), reason="valgrind is not installed.")
134 def test_repl_sasl_leak(topo_m2, use_valgrind):
135 """Test replication with SASL digest-md5 authentication
136
137 :id: 180e088e-841c-11ec-af4f-482ae39447e5
138 :setup: Two supplier replication, valgrind
139 :steps:
140 1. Set sasl digest/md4 on both suppliers
141 2. Break sasl by setting invalid PATH
142 3. Restart the instances
143 4. Perform a change
144 5. Poke replication 100 times
145 6. Stop server
146 7. Check presence of "SASL(-4): no mechanism available: No worthy mechs found" message in error log
147 8. Check that there is no leak about slapi_ldap_get_lderrno
148 :expectedresults:
149 1. Success
150 2. Success
151 3. Success
152 4. Success
153 5. Success
154 6. Success
155 7. Success
156 8. Success
157 """
158
159 m1 = topo_m2.ms['supplier1']
160 m2 = topo_m2.ms['supplier2']
161
162 os.environ["SASL_PATH"] = 'foo'
163
164 m1.start()
165 m2.start()
166
167 resfile=valgrind_get_results_file(m1)
168
169 # Perform a change
170 from_groups = Groups(m1, basedn=DEFAULT_SUFFIX, rdn=None)
171 from_group = from_groups.get('replication_managers')
172 change = str(uuid.uuid4())
173 from_group.replace('description', change)
174
175 # Poke replication to trigger thev leak
176 replica = Replicas(m1).get(DEFAULT_SUFFIX)
177 agmt = Agreements(m1, replica.dn).list()[0]
178 for i in range(0, 100):
179 agmt.pause()
180 agmt.resume()
181
182 m1.stop()
183 assert m1.searchErrorsLog("worthy")
184 assert not valgrind_check_file(resfile, 'slapi_ldap_get_lderrno');
185