| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2018 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 ldap |
| 13 |
from lib389._constants import * |
| 14 |
from lib389.replica import ReplicationManager |
| 15 |
from lib389.plugins import MemberOfPlugin |
| 16 |
from lib389.agreement import Agreements |
| 17 |
from lib389.idm.user import UserAccount, TEST_USER_PROPERTIES |
| 18 |
from lib389.idm.group import Groups |
| 19 |
from test389.topologies import topology_m1h1c1 as topo |
| 20 |
|
| 21 |
pytestmark = pytest.mark.tier1 |
| 22 |
|
| 23 |
DEBUGGING = os.getenv("DEBUGGING", default=False) |
| 24 |
if DEBUGGING: |
| 25 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 26 |
else: |
| 27 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 28 |
log = logging.getLogger(__name__) |
| 29 |
|
| 30 |
BIND_DN = 'uid=tuser1,ou=People,dc=example,dc=com' |
| 31 |
BIND_RDN = 'tuser1' |
| 32 |
|
| 33 |
|
| 34 |
def config_memberof(server): |
| 35 |
"""Configure memberOf plugin and configure fractional |
| 36 |
to prevent total init to send memberof |
| 37 |
""" |
| 38 |
|
| 39 |
memberof = MemberOfPlugin(server) |
| 40 |
memberof.enable() |
| 41 |
memberof.set_autoaddoc('nsMemberOf') |
| 42 |
server.restart() |
| 43 |
agmts = Agreements(server) |
| 44 |
for agmt in agmts.list(): |
| 45 |
log.info('update %s to add nsDS5ReplicatedAttributeListTotal' % agmt.dn) |
| 46 |
agmt.replace_many(('nsDS5ReplicatedAttributeListTotal', '(objectclass=*) $ EXCLUDE '), |
| 47 |
('nsDS5ReplicatedAttributeList', '(objectclass=*) $ EXCLUDE memberOf')) |
| 48 |
|
| 49 |
|
| 50 |
def test_basic_with_hub(topo): |
| 51 |
"""Check that basic operations work in cascading replication, this includes |
| 52 |
testing plugins that perform internal operatons, and replicated password |
| 53 |
policy state attributes. |
| 54 |
|
| 55 |
:id: 4ac85552-45bc-477b-89a4-226dfff8c6cc |
| 56 |
:setup: 1 supplier, 1 hub, 1 consumer |
| 57 |
:steps: |
| 58 |
1. Enable memberOf plugin and set password account lockout settings |
| 59 |
2. Restart the instance |
| 60 |
3. Add a user |
| 61 |
4. Add a group |
| 62 |
5. Test that the replication works |
| 63 |
6. Add the user as a member to the group |
| 64 |
7. Test that the replication works |
| 65 |
8. Issue bad binds to update passwordRetryCount |
| 66 |
9. Test that replicaton works |
| 67 |
10. Check that passwordRetyCount was replicated |
| 68 |
:expectedresults: |
| 69 |
1. Should be a success |
| 70 |
2. Should be a success |
| 71 |
3. Should be a success |
| 72 |
4. Should be a success |
| 73 |
5. Should be a success |
| 74 |
6. Should be a success |
| 75 |
7. Should be a success |
| 76 |
8. Should be a success |
| 77 |
9. Should be a success |
| 78 |
10. Should be a success |
| 79 |
""" |
| 80 |
|
| 81 |
repl_manager = ReplicationManager(DEFAULT_SUFFIX) |
| 82 |
supplier = topo.ms["supplier1"] |
| 83 |
consumer = topo.cs["consumer1"] |
| 84 |
hub = topo.hs["hub1"] |
| 85 |
|
| 86 |
for inst in topo: |
| 87 |
config_memberof(inst) |
| 88 |
inst.config.set('passwordlockout', 'on') |
| 89 |
inst.config.set('passwordlockoutduration', '60') |
| 90 |
inst.config.set('passwordmaxfailure', '3') |
| 91 |
inst.config.set('passwordIsGlobalPolicy', 'on') |
| 92 |
|
| 93 |
# Create user |
| 94 |
user1 = UserAccount(supplier, BIND_DN) |
| 95 |
user_props = TEST_USER_PROPERTIES.copy() |
| 96 |
user_props.update({'sn': BIND_RDN, |
| 97 |
'cn': BIND_RDN, |
| 98 |
'uid': BIND_RDN, |
| 99 |
'inetUserStatus': '1', |
| 100 |
'objectclass': 'extensibleObject', |
| 101 |
'userpassword': PASSWORD}) |
| 102 |
user1.create(properties=user_props, basedn=SUFFIX) |
| 103 |
|
| 104 |
# Create group |
| 105 |
groups = Groups(supplier, DEFAULT_SUFFIX) |
| 106 |
group = groups.create(properties={'cn': 'group'}) |
| 107 |
|
| 108 |
# Test replication |
| 109 |
repl_manager.test_replication(supplier, consumer) |
| 110 |
|
| 111 |
# Trigger memberOf plugin by adding user to group |
| 112 |
group.replace('member', user1.dn) |
| 113 |
|
| 114 |
# Test replication once more |
| 115 |
repl_manager.test_replication(supplier, consumer) |
| 116 |
|
| 117 |
# Issue bad password to update passwordRetryCount |
| 118 |
try: |
| 119 |
supplier.simple_bind_s(user1.dn, "badpassword") |
| 120 |
except: |
| 121 |
pass |
| 122 |
|
| 123 |
# Test replication one last time |
| 124 |
supplier.simple_bind_s(DN_DM, PASSWORD) |
| 125 |
repl_manager.test_replication(supplier, consumer) |
| 126 |
|
| 127 |
# Finally check if passwordRetyCount was replicated to the hub and consumer |
| 128 |
user1 = UserAccount(hub, BIND_DN) |
| 129 |
count = user1.get_attr_val_int('passwordRetryCount') |
| 130 |
if count is None: |
| 131 |
log.fatal('PasswordRetyCount was not replicated to hub') |
| 132 |
assert False |
| 133 |
if int(count) != 1: |
| 134 |
log.fatal('PasswordRetyCount has unexpected value: {}'.format(count)) |
| 135 |
assert False |
| 136 |
|
| 137 |
user1 = UserAccount(consumer, BIND_DN) |
| 138 |
count = user1.get_attr_val_int('passwordRetryCount') |
| 139 |
if count is None: |
| 140 |
log.fatal('PasswordRetyCount was not replicated to consumer') |
| 141 |
assert False |
| 142 |
if int(count) != 1: |
| 143 |
log.fatal('PasswordRetyCount has unexpected value: {}'.format(count)) |
| 144 |
assert False |
| 145 |
|
| 146 |
|
| 147 |
if __name__ == '__main__': |
| 148 |
# Run isolated |
| 149 |
# -s for DEBUG mode |
| 150 |
CURRENT_FILE = os.path.realpath(__file__) |
| 151 |
pytest.main(["-s", CURRENT_FILE]) |
| 152 |
|