Debian Codegraph @

dirsrvtests/tests/suites/chaining_plugin/anonymous_access_denied_basic_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2021 William Brown <[email protected]>
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 ldap
10 import pytest
11 import time
12 import shutil
13 from lib389.idm.account import Accounts, Account
14 from test389.topologies import topology_i2 as topology
15 from lib389.backend import Backends
16 from lib389._constants import DEFAULT_SUFFIX
17 from lib389.plugins import ChainingBackendPlugin
18 from lib389.chaining import ChainingLinks
19 from lib389.mappingTree import MappingTrees
20 from lib389.idm.services import ServiceAccounts, ServiceAccount
21 from lib389.idm.domain import Domain
22
23 PW = 'thnaoehtnuaoenhtuaoehtnu'
24
25 pytestmark = pytest.mark.tier1
26
27 def test_chaining_paged_search(topology):
28 """ Check that when the chaining target has anonymous access
29 disabled that the ping still functions and allows the search
30 to continue with an appropriate bind user.
31
32 :id: 00bf31db-d93b-4224-8e70-86abb2d4cd17
33 :setup: Two standalones in chaining.
34 :steps:
35 1. Configure chaining between the nodes
36 2. Do a chaining search (w anon allow) to assert it works
37 3. Configure anon dis allowed on st2
38 4. Restart both
39 5. Check search still works
40
41 :expectedresults:
42 1. Success
43 2. Success
44 3. Success
45 4. Success
46 5. Success
47 """
48 st1 = topology.ins["standalone1"]
49 st2 = topology.ins["standalone2"]
50
51 ### We setup so that st1 -> st2
52
53 # Setup a chaining user on st2 to authenticate to.
54 sa = ServiceAccounts(st2, DEFAULT_SUFFIX).create(properties = {
55 'cn': 'sa',
56 'userPassword': PW
57 })
58
59 # Add a proxy user.
60 sproxy = ServiceAccounts(st2, DEFAULT_SUFFIX).create(properties = {
61 'cn': 'proxy',
62 'userPassword': PW
63 })
64
65 # Add the read and proxy ACI
66 dc = Domain(st2, DEFAULT_SUFFIX)
67 dc.add('aci',
68 f"""(targetattr="objectClass || cn || uid")(version 3.0; acl "Enable sa read"; allow (read, search, compare)(userdn="ldap:///{sa.dn}");)"""
69 )
70 # Add the proxy ACI
71 dc.add('aci',
72 f"""(targetattr="*")(version 3.0; acl "Enable proxy access"; allow (proxy)(userdn="ldap:///{sproxy.dn}");)"""
73 )
74
75 # Clear all the BE in st1
76 bes1 = Backends(st1)
77 for be in bes1.list():
78 be.delete()
79
80 # Setup st1 to chain to st2
81 chain_plugin_1 = ChainingBackendPlugin(st1)
82 chain_plugin_1.enable()
83
84 # Chain with the proxy user.
85 chains = ChainingLinks(st1)
86 chain = chains.create(properties={
87 'cn': 'demochain',
88 'nsfarmserverurl': st2.toLDAPURL(),
89 'nsslapd-suffix': DEFAULT_SUFFIX,
90 'nsmultiplexorbinddn': sproxy.dn,
91 'nsmultiplexorcredentials': PW,
92 'nsCheckLocalACI': 'on',
93 'nsConnectionLife': '30',
94 })
95
96 mts = MappingTrees(st1)
97 # Due to a bug in lib389, we need to delete and recreate the mt.
98 for mt in mts.list():
99 mt.delete()
100 mts.ensure_state(properties={
101 'cn': DEFAULT_SUFFIX,
102 'nsslapd-state': 'backend',
103 'nsslapd-backend': 'demochain',
104 'nsslapd-distribution-plugin': 'libreplication-plugin',
105 'nsslapd-distribution-funct': 'repl_chain_on_update',
106 })
107
108 # Enable pwpolicy (Not sure if part of the issue).
109 st1.config.set('passwordIsGlobalPolicy', 'on')
110 st2.config.set('passwordIsGlobalPolicy', 'on')
111
112 # Restart to enable everything.
113 st1.restart()
114
115 # Get a proxy auth connection.
116 sa1 = ServiceAccount(st1, sa.dn)
117 sa1_conn = sa1.bind(password=PW)
118
119 # Now do a search from st1 -> st2
120 sa1_dc = Domain(sa1_conn, DEFAULT_SUFFIX)
121 assert sa1_dc.exists()
122
123 # Now on st2 disable anonymous access.
124 st2.config.set('nsslapd-allow-anonymous-access', 'rootdse')
125
126 # Stop st2 to force the connection to be dead.
127 st2.stop()
128 # Restart st1 - this means it must re-do the ping/keepalive.
129 st1.restart()
130
131 # do a bind - this should fail, and forces the conn offline.
132 with pytest.raises(ldap.OPERATIONS_ERROR):
133 sa1.bind(password=PW)
134
135 # Allow time to attach lldb if needed.
136 # print("🔥🔥🔥")
137 # time.sleep(45)
138
139 # Bring st2 online.
140 st2.start()
141
142 # Wait a bit
143 time.sleep(5)
144
145 # Get a proxy auth connection (again)
146 sa1_conn = sa1.bind(password=PW)
147 # Now do a search from st1 -> st2
148 sa1_dc = Domain(sa1_conn, DEFAULT_SUFFIX)
149 assert sa1_dc.exists()