Debian Codegraph @

dirsrvtests/tests/suites/plugins/rootdn_plugin_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2019 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 socket
11 import ldap
12 import pytest
13 import uuid
14 import time
15 from lib389 import DirSrv
16 from lib389.utils import *
17 from lib389.tasks import *
18 from lib389.tools import DirSrvTools
19 from test389.topologies import topology_st
20 from lib389.idm.directorymanager import DirectoryManager
21 from lib389.plugins import RootDNAccessControlPlugin
22
23
24 pytestmark = pytest.mark.tier1
25
26 logging.getLogger(__name__).setLevel(logging.DEBUG)
27 log = logging.getLogger(__name__)
28
29 localhost = DirSrvTools.getLocalhost()
30 hostname = socket.gethostname()
31
32
33 @pytest.fixture(scope="function")
34 def rootdn_cleanup(topology_st):
35 """Do a cleanup of the config area before the test """
36 log.info('Cleaning up the config area')
37 plugin = RootDNAccessControlPlugin(topology_st.standalone)
38 plugin.remove_all_allow_host()
39 plugin.remove_all_deny_host()
40 plugin.remove_all_allow_ip()
41 plugin.remove_all_deny_ip()
42
43
44 @pytest.fixture(scope="module")
45 def rootdn_setup(topology_st):
46 """Initialize our setup to test the Root DN Access Control Plugin
47
48 Test the following access control type:
49
50 - Allowed IP address *
51 - Denied IP address *
52 - Specific time window
53 - Days allowed access
54 - Allowed host *
55 - Denied host *
56
57 * means multiple valued
58 """
59
60 log.info('Initializing root DN test suite...')
61
62 # Enable dynamic plugins
63 topology_st.standalone.config.set('nsslapd-dynamic-plugins', 'on')
64
65 # Enable the plugin
66 global plugin
67 plugin = RootDNAccessControlPlugin(topology_st.standalone)
68 plugin.enable()
69
70 log.info('test_rootdn_init: Initialized root DN test suite.')
71
72
73 def rootdn_bind(inst, uri=None, fail=False):
74 """Helper function to test root DN bind
75 """
76 newinst = DirSrv(verbose=False)
77 args = {SER_PORT: inst.port,
78 SER_SERVERID_PROP: inst.serverid}
79 newinst.allocate(args)
80 newinst.open(uri=uri, connOnly=True) # This binds as root dn
81
82
83 def test_rootdn_access_specific_time(topology_st, rootdn_setup, rootdn_cleanup, timeout=5):
84 """Test binding inside and outside of a specific time
85
86 :id: a0ef30e5-538b-46fa-9762-01a4435a15e8
87 :setup: Standalone instance, rootdn plugin set up
88 :steps:
89 1. Get the current time, and bump it ahead twohours
90 2. Bind as Root DN
91 3. Set config to allow the entire day
92 4. Bind as Root DN
93 5. Cleanup
94 :expectedresults:
95 1. Success
96 2. Should fail
97 3. Success
98 4. Success
99 5. Success
100 """
101
102 log.info('Running test_rootdn_access_specific_time...')
103 dm = DirectoryManager(topology_st.standalone)
104
105 # Get the current time, and bump it ahead twohours
106 current_hour = time.strftime("%H")
107 if int(current_hour) > 12:
108 open_time = '0200'
109 close_time = '0400'
110 else:
111 open_time = '1600'
112 close_time = '1800'
113
114 assert plugin.replace_many(('rootdn-open-time', open_time),
115 ('rootdn-close-time', close_time))
116
117 attr_updated = 0
118 for i in range(0, timeout):
119 if (plugin.get_attr_val_utf8('rootdn-open-time') == open_time) and (plugin.get_attr_val_utf8('rootdn-close-time') == close_time):
120 attr_updated = 1
121 break
122 else:
123 time.sleep(.5)
124
125 if not attr_updated :
126 raise Exception ("rootdn-open-time and rootdn-close-time were not updated")
127
128 # Bind as Root DN - should fail
129 for i in range(0, timeout):
130 try:
131 dm.bind()
132 except ldap.UNWILLING_TO_PERFORM:
133 break
134 else:
135 time.sleep(.5)
136
137
138 # Set config to allow the entire day
139 open_time = '0000'
140 close_time = '2359'
141 assert plugin.replace_many(('rootdn-open-time', open_time),
142 ('rootdn-close-time', close_time))
143
144 attr_updated = 0
145 for i in range(0, timeout):
146 if (plugin.get_attr_val_utf8('rootdn-open-time') == open_time) and (plugin.get_attr_val_utf8('rootdn-close-time') == close_time):
147 attr_updated = 1
148 break
149 else:
150 time.sleep(.5)
151
152 if not attr_updated :
153 raise Exception ("rootdn-open-time and rootdn-close-time were not updated")
154
155 # Bind as Root DN - should succeed
156 for i in range(0, timeout):
157 try:
158 dm.bind()
159 break
160 except:
161 time.sleep(.5)
162
163 # Cleanup - undo the changes we made so the next test has a clean slate
164 assert plugin.apply_mods([(ldap.MOD_DELETE, 'rootdn-open-time'),
165 (ldap.MOD_DELETE, 'rootdn-close-time')])
166
167
168 def test_rootdn_access_day_of_week(topology_st, rootdn_setup, rootdn_cleanup, timeout=5):
169 """Test the days of week feature
170
171 :id: a0ef30e5-538b-46fa-9762-01a4435a15e1
172 :setup: Standalone instance, rootdn plugin set up
173 :steps:
174 1. Set the deny days
175 2. Bind as Root DN
176 3. Set the allow days
177 4. Bind as Root DN
178 :expectedresults:
179 1. Success
180 2. Should fail
181 3. Success
182 4. Success
183 """
184
185 log.info('Running test_rootdn_access_day_of_week...')
186 dm = DirectoryManager(topology_st.standalone)
187
188 days = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat')
189 day = int(time.strftime("%w", time.gmtime()))
190
191 if day == 6:
192 # Handle the roll over from Saturday into Sunday
193 deny_days = days[1] + ', ' + days[2]
194 allow_days = days[6] + ',' + days[0]
195 elif day > 3:
196 deny_days = days[0] + ', ' + days[1]
197 allow_days = days[day] + ',' + days[day - 1]
198 else:
199 deny_days = days[4] + ',' + days[5]
200 allow_days = days[day] + ',' + days[day + 1]
201
202 log.info('Today: ' + days[day])
203 log.info('Allowed days: ' + allow_days)
204 log.info('Deny days: ' + deny_days)
205
206 # Set the deny days
207 plugin.set_days_allowed(deny_days)
208
209 attr_updated = 0
210 for i in range(0, timeout):
211 if (str(plugin.get_days_allowed()) == deny_days):
212 attr_updated = 1
213 break
214 else:
215 time.sleep(.5)
216
217 if not attr_updated :
218 raise Exception ("rootdn-days-allowed was not updated")
219
220 # Bind as Root DN - should fail
221 for i in range(0, timeout):
222 try:
223 dm.bind()
224 except ldap.UNWILLING_TO_PERFORM:
225 break
226 else:
227 time.sleep(.5)
228
229 # Set the allow days
230 plugin.set_days_allowed(allow_days)
231
232 attr_updated = 0
233 for i in range(0, timeout):
234 if (str(plugin.get_days_allowed()) == allow_days):
235 attr_updated = 1
236 break
237 else:
238 time.sleep(.5)
239
240 if not attr_updated :
241 raise Exception ("rootdn-days-allowed was not updated")
242
243 # Bind as Root DN - should succeed
244 for i in range(0, timeout):
245 try:
246 dm.bind()
247 break
248 except:
249 time.sleep(.5)
250
251 def test_rootdn_access_denied_ip(topology_st, rootdn_setup, rootdn_cleanup, timeout=5):
252 """Test denied IP feature - we can just test denying 127.0.0.1
253
254 :id: a0ef30e5-538b-46fa-9762-01a4435a15e2
255 :setup: Standalone instance, rootdn plugin set up
256 :steps:
257 1. Set rootdn-deny-ip to '127.0.0.1' and '::1'
258 2. Bind as Root DN
259 3. Change the denied IP so root DN succeeds
260 4. Bind as Root DN
261 :expectedresults:
262 1. Success
263 2. Should fail
264 3. Success
265 4. Success
266 """
267
268 log.info('Running test_rootdn_access_denied_ip...')
269 plugin.add_deny_ip('127.0.0.1')
270 plugin.add_deny_ip('::1')
271
272 attr_updated = 0
273 for i in range(0, timeout):
274 if ('127.0.0.1' in str(plugin.get_deny_ip())):
275 attr_updated = 1
276 break
277 else:
278 time.sleep(.5)
279
280 if not attr_updated :
281 raise Exception ("rootdn-deny-ip was not updated")
282
283 # Bind as Root DN - should fail
284 uri = 'ldap://{}:{}'.format('127.0.0.1', topology_st.standalone.port)
285 for i in range(0, timeout):
286 try:
287 rootdn_bind(topology_st.standalone, uri=uri)
288 except ldap.UNWILLING_TO_PERFORM:
289 break
290 else:
291 time.sleep(.5)
292
293 # Change the denied IP so root DN succeeds
294 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-deny-ip', '255.255.255.255')])
295
296 attr_updated = 0
297 for i in range(0, timeout):
298 if ('255.255.255.255' in str(plugin.get_deny_ip())):
299 attr_updated = 1
300 break
301 else:
302 time.sleep(.5)
303
304 if not attr_updated :
305 raise Exception ("rootdn-deny-ip was not updated")
306
307 # Bind as Root DN - should succeed
308 for i in range(0, timeout):
309 try:
310 rootdn_bind(topology_st.standalone, uri=uri)
311 break
312 except:
313 time.sleep(.5)
314
315
316 def test_rootdn_access_denied_host(topology_st, rootdn_setup, rootdn_cleanup, timeout=5):
317 """Test denied Host feature - we can just test denying localhost
318
319 :id: a0ef30e5-538b-46fa-9762-01a4435a15e3
320 :setup: Standalone instance, rootdn plugin set up
321 :steps:
322 1. Set rootdn-deny-host to hostname (localhost if not accessable)
323 2. Bind as Root DN
324 3. Change the denied host so root DN succeeds
325 4. Bind as Root DN
326 :expectedresults:
327 1. Success
328 2. Should fail
329 3. Success
330 4. Success
331 """
332
333 log.info('Running test_rootdn_access_denied_host...')
334 hostname = socket.gethostname()
335 plugin.add_deny_host(hostname)
336 if localhost != hostname:
337 plugin.add_deny_host(localhost)
338
339 attr_updated = 0
340 for i in range(0, timeout):
341 if (str(plugin.get_deny_host()) == hostname) or (str(plugin.get_deny_host()) == localhost):
342 attr_updated = 1
343 break
344 else:
345 time.sleep(.5)
346
347 if not attr_updated :
348 raise Exception ("rootdn-deny-host was not updated")
349
350 # Bind as Root DN - should fail
351 uri = 'ldap://{}:{}'.format(localhost, topology_st.standalone.port)
352 for i in range(0, timeout):
353 try:
354 rootdn_bind(topology_st.standalone, uri=uri)
355 except ldap.UNWILLING_TO_PERFORM:
356 break
357 else:
358 time.sleep(.5)
359
360 # Change the denied host so root DN bind succeeds
361 rand_host = 'i.dont.exist.{}'.format(uuid.uuid4())
362 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-deny-host', rand_host)])
363
364 attr_updated = 0
365 for i in range(0, timeout):
366 if (plugin.get_deny_host() == rand_host):
367 attr_updated = 1
368 break
369 else:
370 time.sleep(.5)
371
372 if not attr_updated :
373 raise Exception ("rootdn-deny-host was not updated")
374
375 # Bind as Root DN - should succeed
376 for i in range(0, timeout):
377 try:
378 rootdn_bind(topology_st.standalone, uri=uri)
379 break
380 except:
381 time.sleep(.5)
382
383 def test_rootdn_access_allowed_ip(topology_st, rootdn_setup, rootdn_cleanup, timeout=5):
384 """Test allowed ip feature
385
386 :id: a0ef30e5-538b-46fa-9762-01a4435a15e4
387 :setup: Standalone instance, rootdn plugin set up
388 :steps:
389 1. Set allowed ip to 255.255.255.255 - blocks the Root DN
390 2. Bind as Root DN
391 3. Allow localhost
392 4. Bind as Root DN
393 :expectedresults:
394 1. Success
395 2. Should fail
396 3. Success
397 4. Success
398 """
399
400 log.info('Running test_rootdn_access_allowed_ip...')
401
402 # Set allowed ip to 255.255.255.255 - blocks the Root DN
403 plugin.add_allow_ip('255.255.255.255')
404
405 attr_updated = 0
406 for i in range(0, timeout):
407 if ('255.255.255.255' in plugin.get_allow_ip()):
408 attr_updated = 1
409 break
410 else:
411 time.sleep(.5)
412
413 if not attr_updated :
414 raise Exception ("rootdn-allow-ip was not updated")
415
416 # Bind as Root DN - should fail
417 uri = 'ldap://{}:{}'.format(localhost, topology_st.standalone.port)
418 for i in range(0, timeout):
419 try:
420 rootdn_bind(topology_st.standalone, uri=uri)
421 except ldap.UNWILLING_TO_PERFORM:
422 break
423 else:
424 time.sleep(.5)
425
426 # Allow localhost
427 plugin.add_allow_ip('127.0.0.1')
428 plugin.add_allow_ip('::1')
429
430 attr_updated = 0
431 for i in range(0, timeout):
432 if ('127.0.0.1' in plugin.get_allow_ip()):
433 attr_updated = 1
434 break
435 else:
436 time.sleep(.5)
437
438 if not attr_updated :
439 raise Exception ("rootdn-allow-ip was not updated")
440
441 # Bind as Root DN - should succeed
442 for i in range(0, timeout):
443 try:
444 rootdn_bind(topology_st.standalone, uri=uri)
445 break
446 except:
447 time.sleep(.5)
448
449 def test_rootdn_access_allowed_host(topology_st, rootdn_setup, rootdn_cleanup, timeout=5):
450 """Test allowed host feature
451
452 :id: a0ef30e5-538b-46fa-9762-01a4435a15e5
453 :setup: Standalone instance, rootdn plugin set up
454 :steps:
455 1. Set allowed host to an unknown host - blocks the Root DN
456 2. Bind as Root DN
457 3. Allow localhost
458 4. Bind as Root DN
459 :expectedresults:
460 1. Success
461 2. Should fail
462 3. Success
463 4. Success
464 """
465
466 log.info('Running test_rootdn_access_allowed_host...')
467
468 # Set allowed host to an unknown host - blocks the Root DN
469 rand_host = 'i.dont.exist.{}'.format(uuid.uuid4())
470 plugin.add_allow_host(rand_host)
471
472 attr_updated = 0
473 for i in range(0, timeout):
474 if (str(plugin.get_allow_host()) == rand_host):
475 attr_updated = 1
476 break
477 else:
478 time.sleep(.5)
479
480 if not attr_updated :
481 raise Exception ("rootdn-allow-host was not updated")
482
483 # Bind as Root DN - should fail
484 uri = 'ldap://{}:{}'.format(localhost, topology_st.standalone.port)
485 for i in range(0, timeout):
486 try:
487 rootdn_bind(topology_st.standalone, uri=uri)
488 except ldap.UNWILLING_TO_PERFORM:
489 break
490 else:
491 time.sleep(.5)
492
493 # Allow localhost
494 plugin.remove_all_allow_host()
495 plugin.add_allow_host(localhost)
496 if hostname != localhost:
497 plugin.add_allow_host(hostname)
498
499 attr_updated = 0
500 for i in range(0, timeout):
501 if (str(plugin.get_allow_host()) == hostname) or (str(plugin.get_allow_host()) == localhost):
502 attr_updated = 1
503 break
504 else:
505 time.sleep(.5)
506
507 if not attr_updated :
508 raise Exception ("rootdn-allow-host was not updated")
509
510 # Bind as Root DN - should succeed
511 for i in range(0, timeout):
512 try:
513 rootdn_bind(topology_st.standalone, uri=uri)
514 break
515 except:
516 time.sleep(.5)
517
518 def test_rootdn_config_validate(topology_st, rootdn_setup, rootdn_cleanup):
519 """Test plugin configuration validation
520
521 :id: a0ef30e5-538b-46fa-9762-01a4435a15e6
522 :setup: Standalone instance, rootdn plugin set up
523 :steps:
524 1. Replace 'rootdn-open-time' with '0000'
525 2. Add 'rootdn-open-time': '0000' and 'rootdn-open-time': '0001'
526 3. Replace 'rootdn-open-time' with '-1' and 'rootdn-close-time' with '0000'
527 4. Replace 'rootdn-open-time' with '2400' and 'rootdn-close-time' with '0000'
528 5. Replace 'rootdn-open-time' with 'aaaaa' and 'rootdn-close-time' with '0000'
529 6. Replace 'rootdn-close-time' with '0000'
530 7. Add 'rootdn-close-time': '0000' and 'rootdn-close-time': '0001'
531 8. Replace 'rootdn-open-time' with '0000' and 'rootdn-close-time' with '-1'
532 9. Replace 'rootdn-open-time' with '0000' and 'rootdn-close-time' with '2400'
533 10. Replace 'rootdn-open-time' with '0000' and 'rootdn-close-time' with 'aaaaa'
534 11. Add 'rootdn-days-allowed': 'Mon' and 'rootdn-days-allowed': 'Tue'
535 12. Replace 'rootdn-days-allowed' with 'Mon1'
536 13. Replace 'rootdn-days-allowed' with 'Tue, Mon1'
537 14. Replace 'rootdn-days-allowed' with 'm111m'
538 15. Replace 'rootdn-days-allowed' with 'Gur'
539 16. Replace 'rootdn-allow-ip' with '12.12.Z.12'
540 17. Replace 'rootdn-allow-ip' with '123.234.345.456'
541 18. Replace 'rootdn-allow-ip' with ':::'
542 19. Replace 'rootdn-deny-ip' with '12.12.Z.12'
543 20. Replace 'rootdn-deny-ip' with '123.234.345.456'
544 21. Replace 'rootdn-deny-ip' with ':::'
545 22. Replace 'rootdn-allow-host' with 'host._.com'
546 23. Replace 'rootdn-deny-host' with 'host.####.com'
547 :expectedresults:
548 1. Should fail
549 2. Should fail
550 3. Should fail
551 4. Should fail
552 5. Should fail
553 6. Should fail
554 7. Should fail
555 8. Should fail
556 9. Should fail
557 10. Should fail
558 11. Should fail
559 12. Should fail
560 13. Should fail
561 14. Should fail
562 15. Should fail
563 16. Should fail
564 17. Should fail
565 18. Should fail
566 19. Should fail
567 20. Should fail
568 21. Should fail
569 22. Should fail
570 23. Should fail
571 """
572
573 # Test invalid values for all settings
574 with pytest.raises(ldap.UNWILLING_TO_PERFORM):
575 log.info('Add just "rootdn-open-time"')
576 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-open-time', '0000')])
577
578 log.info('Add multiple "rootdn-open-time"')
579 plugin.apply_mods([(ldap.MOD_ADD, 'rootdn-open-time', '0000'),
580 (ldap.MOD_ADD, 'rootdn-open-time', '0001')])
581
582 log.info('Add invalid "rootdn-open-time" -1 ')
583 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-open-time', '-1'),
584 (ldap.MOD_REPLACE, 'rootdn-close-time', '0000')])
585
586 log.info('Add invalid "rootdn-open-time" 2400')
587 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-open-time', '2400'),
588 (ldap.MOD_REPLACE, 'rootdn-close-time', '0000')])
589
590 log.info('Add invalid "rootdn-open-time" aaaaa')
591 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-open-time','aaaaa'),
592 (ldap.MOD_REPLACE, 'rootdn-close-time', '0000')])
593
594 # Test rootdn-close-time
595 log.info('Add just "rootdn-close-time"')
596 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-close-time', '0000')])
597
598 log.info('Add multiple "rootdn-close-time"')
599 plugin.apply_mods([(ldap.MOD_ADD, 'rootdn-close-time', '0000'),
600 (ldap.MOD_ADD, 'rootdn-close-time', '0001')])
601
602 log.info('Add invalid "rootdn-close-time" -1 ')
603 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-open-time', '0000'),
604 (ldap.MOD_REPLACE, 'rootdn-close-time', '-1')])
605
606 log.info('Add invalid "rootdn-close-time" 2400')
607 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-open-time', '0000'),
608 (ldap.MOD_REPLACE, 'rootdn-close-time', '2400')])
609
610 log.info('Add invalid "rootdn-open-time" aaaaa')
611 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-open-time','0000'),
612 (ldap.MOD_REPLACE, 'rootdn-close-time','aaaaa')])
613
614 # Test days allowed
615 log.info('Add multiple "rootdn-days-allowed"')
616 plugin.apply_mods([(ldap.MOD_ADD, 'rootdn-days-allowed', 'Mon'),
617 (ldap.MOD_ADD, 'rootdn-days-allowed', 'Tue')])
618
619 log.info('Add invalid "rootdn-days-allowed"')
620 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-days-allowed', 'Mon1')])
621 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-days-allowed', 'Tue, Mon1')])
622 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-days-allowed', 'm111m')])
623 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-days-allowed', 'Gur')])
624
625 # Test allow ips
626 log.info('Add invalid "rootdn-allow-ip"')
627 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-allow-ip', '12.12.Z.12')])
628 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-allow-ip', '123.234.345.456')])
629 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-allow-ip', ':::')])
630
631 # Test deny ips
632 log.info('Add invalid "rootdn-deny-ip"')
633 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-deny-ip', '12.12.Z.12')])
634 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-deny-ip', '123.234.345.456')])
635 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-deny-ip', ':::')])
636
637 # Test allow hosts
638 log.info('Add invalid "rootdn-allow-host"')
639 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-allow-host', 'host._.com')])
640
641 # Test deny hosts
642 log.info('Add invalid "rootdn-deny-host"')
643 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-deny-host', 'host.####.com')])
644
645
646 @pytest.mark.xfail(ds_is_older('1.3.11', '1.4.3.5'), reason="May fail because of bz1807537")
647 def test_rootdn_access_denied_ip_wildcard(topology_st, rootdn_setup, rootdn_cleanup, timeout=5):
648 """Test denied IP feature with a wildcard
649
650 :id: 73c74f62-9ac2-4bb6-8a63-bacc8d8bbf93
651 :setup: Standalone instance, rootdn plugin set up
652 :steps:
653 1. Set rootdn-deny-ip to '127.*'
654 2. Bind as Root DN
655 3. Change the denied IP so root DN succeeds
656 4. Bind as Root DN
657 :expectedresults:
658 1. Success
659 2. Should fail
660 3. Success
661 4. Success
662 """
663
664 log.info('Running test_rootdn_access_denied_ip_wildcard...')
665
666 plugin.add_deny_ip('127.*')
667
668 # Bind as Root DN - should fail
669 uri = 'ldap://{}:{}'.format('127.0.0.1', topology_st.standalone.port)
670 for i in range(0, timeout):
671 try:
672 rootdn_bind(topology_st.standalone, uri=uri)
673 except ldap.UNWILLING_TO_PERFORM:
674 break
675 else:
676 time.sleep(.5)
677
678 # Change the denied IP so root DN succeeds
679 plugin.apply_mods([(ldap.MOD_REPLACE, 'rootdn-deny-ip', '255.255.255.255')])
680
681 # Bind as Root DN - should succeed
682 for i in range(0, timeout):
683 try:
684 rootdn_bind(topology_st.standalone, uri=uri)
685 break
686 except:
687 time.sleep(.5)
688
689
690 @pytest.mark.xfail(ds_is_older('1.3.11', '1.4.3.5'), reason="May fail because of bz1807537")
691 def test_rootdn_access_allowed_ip_wildcard(topology_st, rootdn_setup, rootdn_cleanup, timeout=5):
692 """Test allowed ip feature
693
694 :id: c3e22c61-9ed2-4e89-8243-6ff686ecad9b
695 :setup: Standalone instance, rootdn plugin set up
696 :steps:
697 1. Set allowed ip to 255.255.255.255 - blocks the Root DN
698 2. Bind as Root DN
699 3. Allow 127.*
700 4. Bind as Root DN
701 :expectedresults:
702 1. Success
703 2. Should fail
704 3. Success
705 4. Success
706 """
707
708 log.info('Running test_rootdn_access_allowed_ip...')
709
710 # Set allowed ip to 255.255.255.255 - blocks the Root DN
711 plugin.add_allow_ip('255.255.255.255')
712 time.sleep(.5)
713
714 # Bind as Root DN - should fail
715 uri = 'ldap://{}:{}'.format('127.0.0.1', topology_st.standalone.port)
716 for i in range(0, timeout):
717 try:
718 rootdn_bind(topology_st.standalone, uri=uri)
719 except ldap.UNWILLING_TO_PERFORM:
720 break
721 else:
722 time.sleep(.5)
723
724 # Allow localhost
725 plugin.add_allow_ip('127.*')
726
727 # Bind as Root DN - should succeed
728 for i in range(0, timeout):
729 try:
730 rootdn_bind(topology_st.standalone, uri=uri)
731 break
732 except:
733 time.sleep(.5)
734
735
736 if __name__ == '__main__':
737 # Run isolated
738 # -s for DEBUG mode
739 CURRENT_FILE = os.path.realpath(__file__)
740 pytest.main("-s %s" % CURRENT_FILE)