| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2025 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 pytest |
| 11 |
import os |
| 12 |
import re |
| 13 |
import time |
| 14 |
import ldap |
| 15 |
from lib389._constants import DEFAULT_SUFFIX, DN_DM, PW_DM |
| 16 |
from test389.topologies import topology_m2 as topo |
| 17 |
from lib389.idm.user import UserAccounts |
| 18 |
from lib389.dirsrv_log import DirsrvAuditJSONLog |
| 19 |
from lib389.plugins import ChainingBackendPlugin |
| 20 |
from lib389.chaining import ChainingLinks |
| 21 |
from lib389.agreement import Agreements |
| 22 |
from lib389.replica import ReplicationManager, Replicas |
| 23 |
from lib389.idm.directorymanager import DirectoryManager |
| 24 |
|
| 25 |
log = logging.getLogger(__name__) |
| 26 |
|
| 27 |
MASKED_PASSWORD = "**********************" |
| 28 |
TEST_PASSWORD = "MySecret123" |
| 29 |
TEST_PASSWORD_2 = "NewPassword789" |
| 30 |
TEST_PASSWORD_3 = "NewPassword101" |
| 31 |
|
| 32 |
|
| 33 |
def setup_audit_logging(inst, log_format='default', display_attrs=None): |
| 34 |
"""Configure audit logging settings""" |
| 35 |
inst.config.replace('nsslapd-auditlog-logbuffering', 'off') |
| 36 |
inst.config.replace('nsslapd-auditlog-logging-enabled', 'on') |
| 37 |
inst.config.replace('nsslapd-auditlog-log-format', log_format) |
| 38 |
|
| 39 |
if display_attrs is not None: |
| 40 |
inst.config.replace('nsslapd-auditlog-display-attrs', display_attrs) |
| 41 |
|
| 42 |
inst.deleteAuditLogs() |
| 43 |
|
| 44 |
|
| 45 |
def check_password_masked(inst, log_format, expected_password, actual_password): |
| 46 |
"""Helper function to check password masking in audit logs""" |
| 47 |
|
| 48 |
time.sleep(1) # Allow log to flush |
| 49 |
|
| 50 |
# List of all password/credential attributes that should be masked |
| 51 |
password_attributes = [ |
| 52 |
'userPassword', |
| 53 |
'nsslapd-rootpw', |
| 54 |
'nsmultiplexorcredentials', |
| 55 |
'nsDS5ReplicaCredentials', |
| 56 |
'nsDS5ReplicaBootstrapCredentials' |
| 57 |
] |
| 58 |
|
| 59 |
# Get password schemes to check for hash leakage |
| 60 |
user_password_scheme = inst.config.get_attr_val_utf8('passwordStorageScheme') |
| 61 |
root_password_scheme = inst.config.get_attr_val_utf8('nsslapd-rootpwstoragescheme') |
| 62 |
|
| 63 |
if log_format == 'json': |
| 64 |
# Check JSON format logs |
| 65 |
audit_log = DirsrvAuditJSONLog(inst) |
| 66 |
log_lines = audit_log.readlines() |
| 67 |
|
| 68 |
found_masked = False |
| 69 |
found_actual = False |
| 70 |
found_hashed = False |
| 71 |
|
| 72 |
for line in log_lines: |
| 73 |
# Check if any password attribute is present in the line |
| 74 |
for attr in password_attributes: |
| 75 |
if attr in line: |
| 76 |
if expected_password in line: |
| 77 |
found_masked = True |
| 78 |
if actual_password in line: |
| 79 |
found_actual = True |
| 80 |
# Check for password scheme indicators (hashed passwords) |
| 81 |
if user_password_scheme and f'{{{user_password_scheme}}}' in line: |
| 82 |
found_hashed = True |
| 83 |
if root_password_scheme and f'{{{root_password_scheme}}}' in line: |
| 84 |
found_hashed = True |
| 85 |
break # Found a password attribute, no need to check others for this line |
| 86 |
|
| 87 |
else: |
| 88 |
# Check LDIF format logs |
| 89 |
found_masked = False |
| 90 |
found_actual = False |
| 91 |
found_hashed = False |
| 92 |
|
| 93 |
# Check each password attribute for masked password |
| 94 |
for attr in password_attributes: |
| 95 |
if inst.ds_audit_log.match(f"{attr}: {re.escape(expected_password)}"): |
| 96 |
found_masked = True |
| 97 |
if inst.ds_audit_log.match(f"{attr}: {actual_password}"): |
| 98 |
found_actual = True |
| 99 |
|
| 100 |
# Check for hashed passwords in LDIF format |
| 101 |
if user_password_scheme: |
| 102 |
if inst.ds_audit_log.match(f"userPassword: {{{user_password_scheme}}}"): |
| 103 |
found_hashed = True |
| 104 |
if root_password_scheme: |
| 105 |
if inst.ds_audit_log.match(f"nsslapd-rootpw: {{{root_password_scheme}}}"): |
| 106 |
found_hashed = True |
| 107 |
|
| 108 |
# Delete audit logs to avoid interference with other tests |
| 109 |
# We need to reset the root password to default as deleteAuditLogs() |
| 110 |
# opens a new connection with the default password |
| 111 |
dm = DirectoryManager(inst) |
| 112 |
dm.change_password(PW_DM) |
| 113 |
inst.deleteAuditLogs() |
| 114 |
|
| 115 |
return found_masked, found_actual, found_hashed |
| 116 |
|
| 117 |
|
| 118 |
@pytest.mark.parametrize("log_format,display_attrs", [ |
| 119 |
("default", None), |
| 120 |
pytest.param("default", "*", marks=pytest.mark.xfail(reason="DS6886")), |
| 121 |
("default", "userPassword"), |
| 122 |
("json", None), |
| 123 |
pytest.param("json", "*", marks=pytest.mark.xfail(reason="DS6886")), |
| 124 |
("json", "userPassword") |
| 125 |
]) |
| 126 |
def test_password_masking_add_operation(topo, log_format, display_attrs): |
| 127 |
"""Test password masking in ADD operations |
| 128 |
|
| 129 |
:id: 4358bd75-bcc7-401c-b492-d3209b10412d |
| 130 |
:parametrized: yes |
| 131 |
:setup: Standalone Instance |
| 132 |
:steps: |
| 133 |
1. Configure audit logging format |
| 134 |
2. Add user with password |
| 135 |
3. Check that password is masked in audit log |
| 136 |
4. Verify actual password does not appear in log |
| 137 |
:expectedresults: |
| 138 |
1. Success |
| 139 |
2. Success |
| 140 |
3. Password should be masked with asterisks |
| 141 |
4. Actual password should not be found in log |
| 142 |
""" |
| 143 |
inst = topo.ms['supplier1'] |
| 144 |
setup_audit_logging(inst, log_format, display_attrs) |
| 145 |
|
| 146 |
users = UserAccounts(inst, DEFAULT_SUFFIX) |
| 147 |
user = None |
| 148 |
|
| 149 |
try: |
| 150 |
user = users.create(properties={ |
| 151 |
'uid': 'test_add_pwd_mask', |
| 152 |
'cn': 'Test Add User', |
| 153 |
'sn': 'User', |
| 154 |
'uidNumber': '1000', |
| 155 |
'gidNumber': '1000', |
| 156 |
'homeDirectory': '/home/test_add', |
| 157 |
'userPassword': TEST_PASSWORD |
| 158 |
}) |
| 159 |
|
| 160 |
found_masked, found_actual, found_hashed = check_password_masked(inst, log_format, MASKED_PASSWORD, TEST_PASSWORD) |
| 161 |
|
| 162 |
assert found_masked, f"Masked password not found in {log_format} ADD operation" |
| 163 |
assert not found_actual, f"Actual password found in {log_format} ADD log (should be masked)" |
| 164 |
assert not found_hashed, f"Hashed password found in {log_format} ADD log (should be masked)" |
| 165 |
|
| 166 |
finally: |
| 167 |
if user is not None: |
| 168 |
try: |
| 169 |
user.delete() |
| 170 |
except: |
| 171 |
pass |
| 172 |
|
| 173 |
|
| 174 |
@pytest.mark.parametrize("log_format,display_attrs", [ |
| 175 |
("default", None), |
| 176 |
pytest.param("default", "*", marks=pytest.mark.xfail(reason="DS6886")), |
| 177 |
("default", "userPassword"), |
| 178 |
("json", None), |
| 179 |
pytest.param("json", "*", marks=pytest.mark.xfail(reason="DS6886")), |
| 180 |
("json", "userPassword") |
| 181 |
]) |
| 182 |
def test_password_masking_modify_operation(topo, log_format, display_attrs): |
| 183 |
"""Test password masking in MODIFY operations |
| 184 |
|
| 185 |
:id: e6963aa9-7609-419c-aae2-1d517aa434bd |
| 186 |
:parametrized: yes |
| 187 |
:setup: Standalone Instance |
| 188 |
:steps: |
| 189 |
1. Configure audit logging format |
| 190 |
2. Add user without password |
| 191 |
3. Add password via MODIFY operation |
| 192 |
4. Check that password is masked in audit log |
| 193 |
5. Modify password to new value |
| 194 |
6. Check that new password is also masked |
| 195 |
7. Verify actual passwords do not appear in log |
| 196 |
:expectedresults: |
| 197 |
1. Success |
| 198 |
2. Success |
| 199 |
3. Success |
| 200 |
4. Password should be masked with asterisks |
| 201 |
5. Success |
| 202 |
6. New password should be masked with asterisks |
| 203 |
7. No actual password values should be found in log |
| 204 |
""" |
| 205 |
inst = topo.ms['supplier1'] |
| 206 |
setup_audit_logging(inst, log_format, display_attrs) |
| 207 |
|
| 208 |
users = UserAccounts(inst, DEFAULT_SUFFIX) |
| 209 |
user = None |
| 210 |
|
| 211 |
try: |
| 212 |
user = users.create(properties={ |
| 213 |
'uid': 'test_modify_pwd_mask', |
| 214 |
'cn': 'Test Modify User', |
| 215 |
'sn': 'User', |
| 216 |
'uidNumber': '2000', |
| 217 |
'gidNumber': '2000', |
| 218 |
'homeDirectory': '/home/test_modify' |
| 219 |
}) |
| 220 |
|
| 221 |
user.replace('userPassword', TEST_PASSWORD) |
| 222 |
|
| 223 |
found_masked, found_actual, found_hashed = check_password_masked(inst, log_format, MASKED_PASSWORD, TEST_PASSWORD) |
| 224 |
assert found_masked, f"Masked password not found in {log_format} MODIFY operation (first password)" |
| 225 |
assert not found_actual, f"Actual password found in {log_format} MODIFY log (should be masked)" |
| 226 |
assert not found_hashed, f"Hashed password found in {log_format} MODIFY log (should be masked)" |
| 227 |
|
| 228 |
user.replace('userPassword', TEST_PASSWORD_2) |
| 229 |
|
| 230 |
found_masked_2, found_actual_2, found_hashed_2 = check_password_masked(inst, log_format, MASKED_PASSWORD, TEST_PASSWORD_2) |
| 231 |
assert found_masked_2, f"Masked password not found in {log_format} MODIFY operation (second password)" |
| 232 |
assert not found_actual_2, f"Second actual password found in {log_format} MODIFY log (should be masked)" |
| 233 |
assert not found_hashed_2, f"Second hashed password found in {log_format} MODIFY log (should be masked)" |
| 234 |
|
| 235 |
finally: |
| 236 |
if user is not None: |
| 237 |
try: |
| 238 |
user.delete() |
| 239 |
except: |
| 240 |
pass |
| 241 |
|
| 242 |
|
| 243 |
@pytest.mark.parametrize("log_format,display_attrs", [ |
| 244 |
("default", None), |
| 245 |
pytest.param("default", "*", marks=pytest.mark.xfail(reason="DS6886")), |
| 246 |
("default", "nsslapd-rootpw"), |
| 247 |
("json", None), |
| 248 |
pytest.param("json", "*", marks=pytest.mark.xfail(reason="DS6886")), |
| 249 |
("json", "nsslapd-rootpw") |
| 250 |
]) |
| 251 |
def test_password_masking_rootpw_modify_operation(topo, log_format, display_attrs): |
| 252 |
"""Test password masking for nsslapd-rootpw MODIFY operations |
| 253 |
|
| 254 |
:id: ec8c9fd4-56ba-4663-ab65-58efb3b445e4 |
| 255 |
:parametrized: yes |
| 256 |
:setup: Standalone Instance |
| 257 |
:steps: |
| 258 |
1. Configure audit logging format |
| 259 |
2. Modify nsslapd-rootpw in configuration |
| 260 |
3. Check that root password is masked in audit log |
| 261 |
4. Modify root password to new value |
| 262 |
5. Check that new root password is also masked |
| 263 |
6. Verify actual root passwords do not appear in log |
| 264 |
:expectedresults: |
| 265 |
1. Success |
| 266 |
2. Success |
| 267 |
3. Root password should be masked with asterisks |
| 268 |
4. Success |
| 269 |
5. New root password should be masked with asterisks |
| 270 |
6. No actual root password values should be found in log |
| 271 |
""" |
| 272 |
inst = topo.ms['supplier1'] |
| 273 |
setup_audit_logging(inst, log_format, display_attrs) |
| 274 |
dm = DirectoryManager(inst) |
| 275 |
|
| 276 |
try: |
| 277 |
dm.change_password(TEST_PASSWORD) |
| 278 |
dm.rebind(TEST_PASSWORD) |
| 279 |
|
| 280 |
found_masked, found_actual, found_hashed = check_password_masked(inst, log_format, MASKED_PASSWORD, TEST_PASSWORD) |
| 281 |
assert found_masked, f"Masked root password not found in {log_format} MODIFY operation (first root password)" |
| 282 |
assert not found_actual, f"Actual root password found in {log_format} MODIFY log (should be masked)" |
| 283 |
assert not found_hashed, f"Hashed root password found in {log_format} MODIFY log (should be masked)" |
| 284 |
|
| 285 |
dm.change_password(TEST_PASSWORD_2) |
| 286 |
dm.rebind(TEST_PASSWORD_2) |
| 287 |
|
| 288 |
found_masked_2, found_actual_2, found_hashed_2 = check_password_masked(inst, log_format, MASKED_PASSWORD, TEST_PASSWORD_2) |
| 289 |
assert found_masked_2, f"Masked root password not found in {log_format} MODIFY operation (second root password)" |
| 290 |
assert not found_actual_2, f"Second actual root password found in {log_format} MODIFY log (should be masked)" |
| 291 |
assert not found_hashed_2, f"Second hashed root password found in {log_format} MODIFY log (should be masked)" |
| 292 |
|
| 293 |
finally: |
| 294 |
dm.change_password(PW_DM) |
| 295 |
dm.rebind(PW_DM) |
| 296 |
|
| 297 |
|
| 298 |
@pytest.mark.parametrize("log_format,display_attrs", [ |
| 299 |
("default", None), |
| 300 |
pytest.param("default", "*", marks=pytest.mark.xfail(reason="DS6886")), |
| 301 |
("default", "nsmultiplexorcredentials"), |
| 302 |
("json", None), |
| 303 |
pytest.param("json", "*", marks=pytest.mark.xfail(reason="DS6886")), |
| 304 |
("json", "nsmultiplexorcredentials") |
| 305 |
]) |
| 306 |
def test_password_masking_multiplexor_credentials(topo, log_format, display_attrs): |
| 307 |
"""Test password masking for nsmultiplexorcredentials in chaining/multiplexor configurations |
| 308 |
|
| 309 |
:id: 161a9498-b248-4926-90be-a696a36ed36e |
| 310 |
:parametrized: yes |
| 311 |
:setup: Standalone Instance |
| 312 |
:steps: |
| 313 |
1. Configure audit logging format |
| 314 |
2. Create a chaining backend configuration entry with nsmultiplexorcredentials |
| 315 |
3. Check that multiplexor credentials are masked in audit log |
| 316 |
4. Modify the credentials |
| 317 |
5. Check that updated credentials are also masked |
| 318 |
6. Verify actual credentials do not appear in log |
| 319 |
:expectedresults: |
| 320 |
1. Success |
| 321 |
2. Success |
| 322 |
3. Multiplexor credentials should be masked with asterisks |
| 323 |
4. Success |
| 324 |
5. Updated credentials should be masked with asterisks |
| 325 |
6. No actual credential values should be found in log |
| 326 |
""" |
| 327 |
inst = topo.ms['supplier1'] |
| 328 |
setup_audit_logging(inst, log_format, display_attrs) |
| 329 |
|
| 330 |
# Enable chaining plugin and create chaining link |
| 331 |
chain_plugin = ChainingBackendPlugin(inst) |
| 332 |
chain_plugin.enable() |
| 333 |
|
| 334 |
chains = ChainingLinks(inst) |
| 335 |
chain = None |
| 336 |
|
| 337 |
try: |
| 338 |
# Create chaining link with multiplexor credentials |
| 339 |
chain = chains.create(properties={ |
| 340 |
'cn': 'testchain', |
| 341 |
'nsfarmserverurl': 'ldap://localhost:389/', |
| 342 |
'nsslapd-suffix': 'dc=example,dc=com', |
| 343 |
'nsmultiplexorbinddn': 'cn=manager', |
| 344 |
'nsmultiplexorcredentials': TEST_PASSWORD, |
| 345 |
'nsCheckLocalACI': 'on', |
| 346 |
'nsConnectionLife': '30', |
| 347 |
}) |
| 348 |
|
| 349 |
found_masked, found_actual, found_hashed = check_password_masked(inst, log_format, MASKED_PASSWORD, TEST_PASSWORD) |
| 350 |
assert found_masked, f"Masked multiplexor credentials not found in {log_format} ADD operation" |
| 351 |
assert not found_actual, f"Actual multiplexor credentials found in {log_format} ADD log (should be masked)" |
| 352 |
assert not found_hashed, f"Hashed multiplexor credentials found in {log_format} ADD log (should be masked)" |
| 353 |
|
| 354 |
# Modify the credentials |
| 355 |
chain.replace('nsmultiplexorcredentials', TEST_PASSWORD_2) |
| 356 |
|
| 357 |
found_masked_2, found_actual_2, found_hashed_2 = check_password_masked(inst, log_format, MASKED_PASSWORD, TEST_PASSWORD_2) |
| 358 |
assert found_masked_2, f"Masked multiplexor credentials not found in {log_format} MODIFY operation" |
| 359 |
assert not found_actual_2, f"Actual multiplexor credentials found in {log_format} MODIFY log (should be masked)" |
| 360 |
assert not found_hashed_2, f"Hashed multiplexor credentials found in {log_format} MODIFY log (should be masked)" |
| 361 |
|
| 362 |
finally: |
| 363 |
chain_plugin.disable() |
| 364 |
if chain is not None: |
| 365 |
inst.delete_branch_s(chain.dn, ldap.SCOPE_ONELEVEL) |
| 366 |
chain.delete() |
| 367 |
|
| 368 |
|
| 369 |
@pytest.mark.parametrize("log_format,display_attrs", [ |
| 370 |
("default", None), |
| 371 |
pytest.param("default", "*", marks=pytest.mark.xfail(reason="DS6886")), |
| 372 |
("default", "nsDS5ReplicaCredentials"), |
| 373 |
("json", None), |
| 374 |
pytest.param("json", "*", marks=pytest.mark.xfail(reason="DS6886")), |
| 375 |
("json", "nsDS5ReplicaCredentials") |
| 376 |
]) |
| 377 |
def test_password_masking_replica_credentials(topo, log_format, display_attrs): |
| 378 |
"""Test password masking for nsDS5ReplicaCredentials in replication agreements |
| 379 |
|
| 380 |
:id: 7bf9e612-1b7c-49af-9fc0-de4c7df84b2a |
| 381 |
:parametrized: yes |
| 382 |
:setup: Standalone Instance |
| 383 |
:steps: |
| 384 |
1. Configure audit logging format |
| 385 |
2. Create a replication agreement entry with nsDS5ReplicaCredentials |
| 386 |
3. Check that replica credentials are masked in audit log |
| 387 |
4. Modify the credentials |
| 388 |
5. Check that updated credentials are also masked |
| 389 |
6. Verify actual credentials do not appear in log |
| 390 |
:expectedresults: |
| 391 |
1. Success |
| 392 |
2. Success |
| 393 |
3. Replica credentials should be masked with asterisks |
| 394 |
4. Success |
| 395 |
5. Updated credentials should be masked with asterisks |
| 396 |
6. No actual credential values should be found in log |
| 397 |
""" |
| 398 |
inst = topo.ms['supplier2'] |
| 399 |
setup_audit_logging(inst, log_format, display_attrs) |
| 400 |
agmt = None |
| 401 |
|
| 402 |
try: |
| 403 |
replicas = Replicas(inst) |
| 404 |
replica = replicas.get(DEFAULT_SUFFIX) |
| 405 |
agmts = replica.get_agreements() |
| 406 |
agmt = agmts.create(properties={ |
| 407 |
'cn': 'testagmt', |
| 408 |
'nsDS5ReplicaHost': 'localhost', |
| 409 |
'nsDS5ReplicaPort': '389', |
| 410 |
'nsDS5ReplicaBindDN': 'cn=replication manager,cn=config', |
| 411 |
'nsDS5ReplicaCredentials': TEST_PASSWORD, |
| 412 |
'nsDS5ReplicaRoot': DEFAULT_SUFFIX |
| 413 |
}) |
| 414 |
|
| 415 |
found_masked, found_actual, found_hashed = check_password_masked(inst, log_format, MASKED_PASSWORD, TEST_PASSWORD) |
| 416 |
assert found_masked, f"Masked replica credentials not found in {log_format} ADD operation" |
| 417 |
assert not found_actual, f"Actual replica credentials found in {log_format} ADD log (should be masked)" |
| 418 |
assert not found_hashed, f"Hashed replica credentials found in {log_format} ADD log (should be masked)" |
| 419 |
|
| 420 |
# Modify the credentials |
| 421 |
agmt.replace('nsDS5ReplicaCredentials', TEST_PASSWORD_2) |
| 422 |
|
| 423 |
found_masked_2, found_actual_2, found_hashed_2 = check_password_masked(inst, log_format, MASKED_PASSWORD, TEST_PASSWORD_2) |
| 424 |
assert found_masked_2, f"Masked replica credentials not found in {log_format} MODIFY operation" |
| 425 |
assert not found_actual_2, f"Actual replica credentials found in {log_format} MODIFY log (should be masked)" |
| 426 |
assert not found_hashed_2, f"Hashed replica credentials found in {log_format} MODIFY log (should be masked)" |
| 427 |
|
| 428 |
finally: |
| 429 |
if agmt is not None: |
| 430 |
agmt.delete() |
| 431 |
|
| 432 |
|
| 433 |
@pytest.mark.parametrize("log_format,display_attrs", [ |
| 434 |
("default", None), |
| 435 |
pytest.param("default", "*", marks=pytest.mark.xfail(reason="DS6886")), |
| 436 |
("default", "nsDS5ReplicaBootstrapCredentials"), |
| 437 |
("json", None), |
| 438 |
pytest.param("json", "*", marks=pytest.mark.xfail(reason="DS6886")), |
| 439 |
("json", "nsDS5ReplicaBootstrapCredentials") |
| 440 |
]) |
| 441 |
def test_password_masking_bootstrap_credentials(topo, log_format, display_attrs): |
| 442 |
"""Test password masking for nsDS5ReplicaCredentials and nsDS5ReplicaBootstrapCredentials in replication agreements |
| 443 |
|
| 444 |
:id: 248bd418-ffa4-4733-963d-2314c60b7c5b |
| 445 |
:parametrized: yes |
| 446 |
:setup: Standalone Instance |
| 447 |
:steps: |
| 448 |
1. Configure audit logging format |
| 449 |
2. Create a replication agreement entry with both nsDS5ReplicaCredentials and nsDS5ReplicaBootstrapCredentials |
| 450 |
3. Check that both credentials are masked in audit log |
| 451 |
4. Modify both credentials |
| 452 |
5. Check that both updated credentials are also masked |
| 453 |
6. Verify actual credentials do not appear in log |
| 454 |
:expectedresults: |
| 455 |
1. Success |
| 456 |
2. Success |
| 457 |
3. Both credentials should be masked with asterisks |
| 458 |
4. Success |
| 459 |
5. Both updated credentials should be masked with asterisks |
| 460 |
6. No actual credential values should be found in log |
| 461 |
""" |
| 462 |
inst = topo.ms['supplier2'] |
| 463 |
setup_audit_logging(inst, log_format, display_attrs) |
| 464 |
agmt = None |
| 465 |
|
| 466 |
try: |
| 467 |
replicas = Replicas(inst) |
| 468 |
replica = replicas.get(DEFAULT_SUFFIX) |
| 469 |
agmts = replica.get_agreements() |
| 470 |
agmt = agmts.create(properties={ |
| 471 |
'cn': 'testbootstrapagmt', |
| 472 |
'nsDS5ReplicaHost': 'localhost', |
| 473 |
'nsDS5ReplicaPort': '389', |
| 474 |
'nsDS5ReplicaBindDN': 'cn=replication manager,cn=config', |
| 475 |
'nsDS5ReplicaCredentials': TEST_PASSWORD, |
| 476 |
'nsDS5replicabootstrapbinddn': 'cn=bootstrap manager,cn=config', |
| 477 |
'nsDS5ReplicaBootstrapCredentials': TEST_PASSWORD_2, |
| 478 |
'nsDS5ReplicaRoot': DEFAULT_SUFFIX |
| 479 |
}) |
| 480 |
|
| 481 |
found_masked_bootstrap, found_actual_bootstrap, found_hashed_bootstrap = check_password_masked(inst, log_format, MASKED_PASSWORD, TEST_PASSWORD_2) |
| 482 |
assert found_masked_bootstrap, f"Masked bootstrap credentials not found in {log_format} ADD operation" |
| 483 |
assert not found_actual_bootstrap, f"Actual bootstrap credentials found in {log_format} ADD log (should be masked)" |
| 484 |
assert not found_hashed_bootstrap, f"Hashed bootstrap credentials found in {log_format} ADD log (should be masked)" |
| 485 |
|
| 486 |
agmt.replace('nsDS5ReplicaBootstrapCredentials', TEST_PASSWORD_3) |
| 487 |
|
| 488 |
found_masked_bootstrap_2, found_actual_bootstrap_2, found_hashed_bootstrap_2 = check_password_masked(inst, log_format, MASKED_PASSWORD, TEST_PASSWORD_3) |
| 489 |
assert found_masked_bootstrap_2, f"Masked bootstrap credentials not found in {log_format} MODIFY operation" |
| 490 |
assert not found_actual_bootstrap_2, f"Actual bootstrap credentials found in {log_format} MODIFY log (should be masked)" |
| 491 |
assert not found_hashed_bootstrap_2, f"Hashed bootstrap credentials found in {log_format} MODIFY log (should be masked)" |
| 492 |
|
| 493 |
finally: |
| 494 |
if agmt is not None: |
| 495 |
agmt.delete() |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
if __name__ == '__main__': |
| 500 |
CURRENT_FILE = os.path.realpath(__file__) |
| 501 |
pytest.main(["-s", CURRENT_FILE]) |