rootdn_plugin_test.py 23 KB

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