| 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 pytest |
| 11 |
import os |
| 12 |
import time |
| 13 |
from lib389._constants import DEFAULT_SUFFIX |
| 14 |
from test389.topologies import topology_m2 as topo |
| 15 |
from lib389.replica import BootstrapReplicationManager, Replicas |
| 16 |
from lib389.idm.user import TEST_USER_PROPERTIES, UserAccounts, UserAccount |
| 17 |
from lib389.idm.group import Group |
| 18 |
|
| 19 |
pytestmark = pytest.mark.tier1 |
| 20 |
|
| 21 |
DEBUGGING = os.getenv("DEBUGGING", default=False) |
| 22 |
if DEBUGGING: |
| 23 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 24 |
else: |
| 25 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 26 |
log = logging.getLogger(__name__) |
| 27 |
|
| 28 |
BOOTSTRAP_MGR_DN = 'uid=replication manager,cn=config' |
| 29 |
BOOTSTRAP_MGR_PWD = 'boostrap_manager_password' |
| 30 |
BIND_GROUP_DN = 'cn=replication_managers,' + DEFAULT_SUFFIX |
| 31 |
|
| 32 |
|
| 33 |
def test_repl_agmt_bootstrap_credentials(topo): |
| 34 |
"""Test that the agreement bootstrap credentials works if the default |
| 35 |
credentials fail for some reason. |
| 36 |
|
| 37 |
:id: 38c8095c-d958-415a-b602-74854b7882b3 |
| 38 |
:customerscenario: True |
| 39 |
:setup: 2 Supplier Instances |
| 40 |
:steps: |
| 41 |
1. Change the bind dn group member passwords |
| 42 |
2. Verify replication is not working |
| 43 |
3. Create a new repl manager on supplier 2 for bootstrapping |
| 44 |
4. Add bootstrap credentials to agmt on supplier 1 |
| 45 |
5. Verify replication is now working with bootstrap creds |
| 46 |
6. Trigger new repl session and default credentials are used first |
| 47 |
:expectedresults: |
| 48 |
1. Success |
| 49 |
2. Success |
| 50 |
3. Success |
| 51 |
4. Success |
| 52 |
5. Success |
| 53 |
6. Success |
| 54 |
""" |
| 55 |
|
| 56 |
# Gather all of our objects for the test |
| 57 |
m1 = topo.ms["supplier1"] |
| 58 |
m2 = topo.ms["supplier2"] |
| 59 |
supplier1_replica = Replicas(m1).get(DEFAULT_SUFFIX) |
| 60 |
supplier2_replica = Replicas(m2).get(DEFAULT_SUFFIX) |
| 61 |
supplier2_users = UserAccounts(m2, DEFAULT_SUFFIX) |
| 62 |
m1_agmt = supplier1_replica.get_agreements().list()[0] |
| 63 |
num_of_original_users = len(supplier2_users.list()) |
| 64 |
|
| 65 |
# Change the member's passwords which should break replication |
| 66 |
bind_group = Group(m2, dn=BIND_GROUP_DN) |
| 67 |
members = bind_group.list_members() |
| 68 |
for member_dn in members: |
| 69 |
member = UserAccount(m2, dn=member_dn) |
| 70 |
member.replace('userPassword', 'not_right') |
| 71 |
time.sleep(3) |
| 72 |
m1_agmt.pause() |
| 73 |
m1_agmt.resume() |
| 74 |
|
| 75 |
# Verify replication is not working, a new user should not be replicated |
| 76 |
users = UserAccounts(m1, DEFAULT_SUFFIX) |
| 77 |
test_user = users.ensure_state(properties=TEST_USER_PROPERTIES) |
| 78 |
time.sleep(3) |
| 79 |
assert len(supplier2_users.list()) == num_of_original_users |
| 80 |
|
| 81 |
# Create a repl manager on replica |
| 82 |
repl_mgr = BootstrapReplicationManager(m2, dn=BOOTSTRAP_MGR_DN) |
| 83 |
mgr_properties = { |
| 84 |
'uid': 'replication manager', |
| 85 |
'cn': 'replication manager', |
| 86 |
'userPassword': BOOTSTRAP_MGR_PWD, |
| 87 |
} |
| 88 |
repl_mgr.create(properties=mgr_properties) |
| 89 |
|
| 90 |
# Update supplier 2 config |
| 91 |
supplier2_replica.remove_all('nsDS5ReplicaBindDNGroup') |
| 92 |
supplier2_replica.remove_all('nsDS5ReplicaBindDnGroupCheckInterval') |
| 93 |
supplier2_replica.replace('nsDS5ReplicaBindDN', BOOTSTRAP_MGR_DN) |
| 94 |
|
| 95 |
# Add bootstrap credentials to supplier1 agmt, and restart agmt |
| 96 |
m1_agmt.replace('nsds5ReplicaBootstrapTransportInfo', 'LDAP') |
| 97 |
m1_agmt.replace('nsds5ReplicaBootstrapBindMethod', 'SIMPLE') |
| 98 |
m1_agmt.replace('nsds5ReplicaBootstrapCredentials', BOOTSTRAP_MGR_PWD) |
| 99 |
m1_agmt.replace('nsds5ReplicaBootstrapBindDN', BOOTSTRAP_MGR_DN) |
| 100 |
m1_agmt.pause() |
| 101 |
m1_agmt.resume() |
| 102 |
|
| 103 |
# Verify replication is working. The user should have been replicated |
| 104 |
time.sleep(3) |
| 105 |
assert len(supplier2_users.list()) > num_of_original_users |
| 106 |
|
| 107 |
# Finally check if the default credentials are used on the next repl |
| 108 |
# session. Clear out the logs, and disable log buffering. Then |
| 109 |
# trigger a replication update/session. |
| 110 |
m1_agmt.pause() |
| 111 |
m2.stop() |
| 112 |
m2.deleteLog(m2.accesslog) # Clear out the logs |
| 113 |
m2.start() |
| 114 |
m2.config.set('nsslapd-accesslog-logbuffering', 'off') |
| 115 |
m1_agmt.resume() |
| 116 |
test_user.delete() |
| 117 |
time.sleep(3) |
| 118 |
|
| 119 |
# We know if the default credentials are used it will fail (err=49) |
| 120 |
results = m2.ds_access_log.match('.* err=49 .*') |
| 121 |
assert len(results) > 0 |
| 122 |
|
| 123 |
|
| 124 |
if __name__ == '__main__': |
| 125 |
# Run isolated |
| 126 |
# -s for DEBUG mode |
| 127 |
CURRENT_FILE = os.path.realpath(__file__) |
| 128 |
pytest.main(["-s", CURRENT_FILE]) |
| 129 |
|