1
0

rootdn_plugin_test.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2015 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 os
  10. import sys
  11. import time
  12. import ldap
  13. import logging
  14. import pytest
  15. from lib389 import DirSrv, Entry, tools, tasks
  16. from lib389.tools import DirSrvTools
  17. from lib389._constants import *
  18. from lib389.properties import *
  19. from lib389.tasks import *
  20. logging.getLogger(__name__).setLevel(logging.DEBUG)
  21. log = logging.getLogger(__name__)
  22. installation1_prefix = None
  23. PLUGIN_DN = 'cn=' + PLUGIN_ROOTDN_ACCESS + ',cn=plugins,cn=config'
  24. USER1_DN = 'uid=user1,' + DEFAULT_SUFFIX
  25. class TopologyStandalone(object):
  26. def __init__(self, standalone):
  27. standalone.open()
  28. self.standalone = standalone
  29. @pytest.fixture(scope="module")
  30. def topology(request):
  31. global installation1_prefix
  32. if installation1_prefix:
  33. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  34. # Creating standalone instance ...
  35. standalone = DirSrv(verbose=False)
  36. args_instance[SER_HOST] = HOST_STANDALONE
  37. args_instance[SER_PORT] = PORT_STANDALONE
  38. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  39. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  40. args_standalone = args_instance.copy()
  41. standalone.allocate(args_standalone)
  42. instance_standalone = standalone.exists()
  43. if instance_standalone:
  44. standalone.delete()
  45. standalone.create()
  46. standalone.open()
  47. # Clear out the tmp dir
  48. standalone.clearTmpDir(__file__)
  49. return TopologyStandalone(standalone)
  50. def test_rootdn_init(topology):
  51. '''
  52. Initialize our setup to test the ROot DN Access Control Plugin
  53. Test the following access control type:
  54. - Allowed IP address *
  55. - Denied IP address *
  56. - Specific time window
  57. - Days allowed access
  58. - Allowed host *
  59. - Denied host *
  60. * means mulitple valued
  61. '''
  62. log.info('Initializing root DN test suite...')
  63. #
  64. # Set an aci so we can modify the plugin after we deny the Root DN
  65. #
  66. ACI = ('(target ="ldap:///cn=config")(targetattr = "*")(version 3.0' +
  67. ';acl "all access";allow (all)(userdn="ldap:///anyone");)')
  68. try:
  69. topology.standalone.modify_s(DN_CONFIG, [(ldap.MOD_ADD, 'aci', ACI)])
  70. except ldap.LDAPError as e:
  71. log.fatal('test_rootdn_init: Failed to add aci to config: error ' +
  72. e.message['desc'])
  73. assert False
  74. #
  75. # Create a user to modify the config
  76. #
  77. try:
  78. topology.standalone.add_s(Entry((USER1_DN, {'objectclass': "top extensibleObject".split(),
  79. 'uid': 'user1',
  80. 'userpassword': PASSWORD})))
  81. except ldap.LDAPError as e:
  82. log.fatal('test_rootdn_init: Failed to add test user ' + USER1_DN + ': error ' +
  83. e.message['desc'])
  84. assert False
  85. #
  86. # Enable dynamic plugins
  87. #
  88. try:
  89. topology.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-dynamic-plugins', 'on')])
  90. except ldap.LDAPError as e:
  91. log.fatal('test_rootdn_init: Failed to set dynamic plugins: error ' + e.message['desc'])
  92. assert False
  93. #
  94. # Enable the plugin (aftewr enabling dynamic plugins)
  95. #
  96. topology.standalone.plugins.enable(PLUGIN_ROOTDN_ACCESS)
  97. log.info('test_rootdn_init: Initialized root DN test suite.')
  98. def test_rootdn_access_specific_time(topology):
  99. '''
  100. Test binding inside and outside of a specific time
  101. '''
  102. log.info('Running test_rootdn_access_specific_time...')
  103. # Get the current time, and bump it ahead twohours
  104. current_hour = time.strftime("%H")
  105. if int(current_hour) > 12:
  106. open_time = '0200'
  107. close_time = '0400'
  108. else:
  109. open_time = '1600'
  110. close_time = '1800'
  111. try:
  112. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_ADD, 'rootdn-open-time', open_time),
  113. (ldap.MOD_ADD, 'rootdn-close-time', close_time)])
  114. except ldap.LDAPError as e:
  115. log.fatal('test_rootdn_access_specific_time: Failed to set (blocking) open/close times: error ' +
  116. e.message['desc'])
  117. assert False
  118. #
  119. # Bind as Root DN - should fail
  120. #
  121. try:
  122. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  123. succeeded = True
  124. except ldap.LDAPError as e:
  125. succeeded = False
  126. if succeeded:
  127. log.fatal('test_rootdn_access_specific_time: Root DN was incorrectly able to bind')
  128. assert False
  129. #
  130. # Set config to allow the entire day
  131. #
  132. try:
  133. topology.standalone.simple_bind_s(USER1_DN, PASSWORD)
  134. except ldap.LDAPError as e:
  135. log.fatal('test_rootdn_access_specific_time: test_rootdn: failed to bind as user1')
  136. assert False
  137. try:
  138. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-open-time', '0000'),
  139. (ldap.MOD_REPLACE, 'rootdn-close-time', '2359')])
  140. except ldap.LDAPError as e:
  141. log.fatal('test_rootdn_access_specific_time: Failed to set (open) open/close times: error ' +
  142. e.message['desc'])
  143. assert False
  144. try:
  145. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  146. except ldap.LDAPError as e:
  147. log.fatal('test_rootdn_access_specific_time: Root DN bind failed unexpectedly failed: error ' +
  148. e.message['desc'])
  149. assert False
  150. #
  151. # Cleanup - undo the changes we made so the next test has a clean slate
  152. #
  153. try:
  154. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_DELETE, 'rootdn-open-time', None),
  155. (ldap.MOD_DELETE, 'rootdn-close-time', None)])
  156. except ldap.LDAPError as e:
  157. log.fatal('test_rootdn_access_specific_time: Failed to delete open and close time: error ' +
  158. e.message['desc'])
  159. assert False
  160. try:
  161. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  162. except ldap.LDAPError as e:
  163. log.fatal('test_rootdn_access_specific_time: Root DN bind failed unexpectedly failed: error ' +
  164. e.message['desc'])
  165. assert False
  166. log.info('test_rootdn_access_specific_time: PASSED')
  167. def test_rootdn_access_day_of_week(topology):
  168. '''
  169. Test the days of week feature
  170. '''
  171. log.info('Running test_rootdn_access_day_of_week...')
  172. days = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat')
  173. day = int(time.strftime("%w", time.gmtime()))
  174. if day > 3:
  175. deny_days = days[0] + ', ' + days[1]
  176. allow_days = days[day] + ',' + days[day - 1]
  177. else:
  178. deny_days = days[4] + ',' + days[5]
  179. allow_days = days[day] + ',' + days[day + 1]
  180. #
  181. # Set the deny days
  182. #
  183. try:
  184. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-days-allowed',
  185. deny_days)])
  186. except ldap.LDAPError as e:
  187. log.fatal('test_rootdn_access_day_of_week: Failed to set the deny days: error ' +
  188. e.message['desc'])
  189. assert False
  190. #
  191. # Bind as Root DN - should fail
  192. #
  193. try:
  194. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  195. succeeded = True
  196. except ldap.LDAPError as e:
  197. succeeded = False
  198. if succeeded:
  199. log.fatal('test_rootdn_access_day_of_week: Root DN was incorrectly able to bind')
  200. assert False
  201. #
  202. # Set the allow days
  203. #
  204. try:
  205. topology.standalone.simple_bind_s(USER1_DN, PASSWORD)
  206. except ldap.LDAPError as e:
  207. log.fatal('test_rootdn_access_day_of_week: : failed to bind as user1')
  208. assert False
  209. try:
  210. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-days-allowed',
  211. allow_days)])
  212. except ldap.LDAPError as e:
  213. log.fatal('test_rootdn_access_day_of_week: Failed to set the deny days: error ' +
  214. e.message['desc'])
  215. assert False
  216. try:
  217. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  218. except ldap.LDAPError as e:
  219. log.fatal('test_rootdn_access_day_of_week: Root DN bind failed unexpectedly failed: error ' +
  220. e.message['desc'])
  221. assert False
  222. #
  223. # Cleanup - undo the changes we made so the next test has a clean slate
  224. #
  225. try:
  226. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_DELETE, 'rootdn-days-allowed', None)])
  227. except ldap.LDAPError as e:
  228. log.fatal('test_rootdn_access_day_of_week: Failed to set rootDN plugin config: error ' +
  229. e.message['desc'])
  230. assert False
  231. try:
  232. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  233. except ldap.LDAPError as e:
  234. log.fatal('test_rootdn_access_day_of_week: Root DN bind failed unexpectedly failed: error ' +
  235. e.message['desc'])
  236. assert False
  237. log.info('test_rootdn_access_day_of_week: PASSED')
  238. def test_rootdn_access_denied_ip(topology):
  239. '''
  240. Test denied IP feature - we can just test denying 127.0.01
  241. '''
  242. log.info('Running test_rootdn_access_denied_ip...')
  243. try:
  244. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-deny-ip', '127.0.0.1'),
  245. (ldap.MOD_ADD, 'rootdn-deny-ip', '::1')])
  246. except ldap.LDAPError as e:
  247. log.fatal('test_rootdn_access_denied_ip: Failed to set rootDN plugin config: error ' +
  248. e.message['desc'])
  249. assert False
  250. #
  251. # Bind as Root DN - should fail
  252. #
  253. try:
  254. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  255. succeeded = True
  256. except ldap.LDAPError as e:
  257. succeeded = False
  258. if succeeded:
  259. log.fatal('test_rootdn_access_denied_ip: Root DN was incorrectly able to bind')
  260. assert False
  261. #
  262. # Change the denied IP so root DN succeeds
  263. #
  264. try:
  265. topology.standalone.simple_bind_s(USER1_DN, PASSWORD)
  266. except ldap.LDAPError as e:
  267. log.fatal('test_rootdn_access_denied_ip: : failed to bind as user1')
  268. assert False
  269. try:
  270. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-deny-ip', '255.255.255.255')])
  271. except ldap.LDAPError as e:
  272. log.fatal('test_rootdn_access_denied_ip: Failed to set rootDN plugin config: error ' +
  273. e.message['desc'])
  274. assert False
  275. try:
  276. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  277. except ldap.LDAPError as e:
  278. log.fatal('test_rootdn_access_denied_ip: Root DN bind failed unexpectedly failed: error ' +
  279. e.message['desc'])
  280. assert False
  281. #
  282. # Cleanup - undo the changes we made so the next test has a clean slate
  283. #
  284. try:
  285. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_DELETE, 'rootdn-deny-ip', None)])
  286. except ldap.LDAPError as e:
  287. log.fatal('test_rootdn_access_denied_ip: Failed to set rootDN plugin config: error ' +
  288. e.message['desc'])
  289. assert False
  290. try:
  291. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  292. except ldap.LDAPError as e:
  293. log.fatal('test_rootdn_access_denied_ip: Root DN bind failed unexpectedly failed: error ' +
  294. e.message['desc'])
  295. assert False
  296. log.info('test_rootdn_access_denied_ip: PASSED')
  297. def test_rootdn_access_denied_host(topology):
  298. '''
  299. Test denied Host feature - we can just test denying localhost
  300. '''
  301. log.info('Running test_rootdn_access_denied_host...')
  302. try:
  303. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_ADD, 'rootdn-deny-host', 'localhost.localdomain')])
  304. except ldap.LDAPError as e:
  305. log.fatal('test_rootdn_access_denied_host: Failed to set deny host: error ' +
  306. e.message['desc'])
  307. assert False
  308. #
  309. # Bind as Root DN - should fail
  310. #
  311. try:
  312. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  313. succeeded = True
  314. except ldap.LDAPError as e:
  315. succeeded = False
  316. if succeeded:
  317. log.fatal('test_rootdn_access_denied_host: Root DN was incorrectly able to bind')
  318. assert False
  319. #
  320. # Change the denied host so root DN succeeds
  321. #
  322. try:
  323. topology.standalone.simple_bind_s(USER1_DN, PASSWORD)
  324. except ldap.LDAPError as e:
  325. log.fatal('test_rootdn_access_denied_host: : failed to bind as user1')
  326. assert False
  327. try:
  328. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-deny-host', 'i.dont.exist.com')])
  329. except ldap.LDAPError as e:
  330. log.fatal('test_rootdn_access_denied_host: Failed to set rootDN plugin config: error ' +
  331. e.message['desc'])
  332. assert False
  333. try:
  334. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  335. except ldap.LDAPError as e:
  336. log.fatal('test_rootdn_access_denied_host: Root DN bind failed unexpectedly failed: error ' +
  337. e.message['desc'])
  338. assert False
  339. #
  340. # Cleanup - undo the changes we made so the next test has a clean slate
  341. #
  342. try:
  343. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_DELETE, 'rootdn-deny-host', None)])
  344. except ldap.LDAPError as e:
  345. log.fatal('test_rootdn_access_denied_host: Failed to set rootDN plugin config: error ' +
  346. e.message['desc'])
  347. assert False
  348. try:
  349. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  350. except ldap.LDAPError as e:
  351. log.fatal('test_rootdn_access_denied_host: Root DN bind failed unexpectedly failed: error ' +
  352. e.message['desc'])
  353. assert False
  354. log.info('test_rootdn_access_denied_host: PASSED')
  355. def test_rootdn_access_allowed_ip(topology):
  356. '''
  357. Test allowed ip feature
  358. '''
  359. log.info('Running test_rootdn_access_allowed_ip...')
  360. #
  361. # Set allowed host to an unknown host - blocks the Root DN
  362. #
  363. try:
  364. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-allow-ip', '255.255.255.255')])
  365. except ldap.LDAPError as e:
  366. log.fatal('test_rootdn_access_allowed_ip: Failed to set allowed host: error ' +
  367. e.message['desc'])
  368. assert False
  369. #
  370. # Bind as Root DN - should fail
  371. #
  372. try:
  373. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  374. succeeded = True
  375. except ldap.LDAPError as e:
  376. succeeded = False
  377. if succeeded:
  378. log.fatal('test_rootdn_access_allowed_ip: Root DN was incorrectly able to bind')
  379. assert False
  380. #
  381. # Allow localhost
  382. #
  383. try:
  384. topology.standalone.simple_bind_s(USER1_DN, PASSWORD)
  385. except ldap.LDAPError as e:
  386. log.fatal('test_rootdn_access_allowed_ip: : failed to bind as user1')
  387. assert False
  388. try:
  389. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-allow-ip', '127.0.0.1'),
  390. (ldap.MOD_ADD, 'rootdn-allow-ip', '::1')])
  391. except ldap.LDAPError as e:
  392. log.fatal('test_rootdn_access_allowed_ip: Failed to set allowed host: error ' +
  393. e.message['desc'])
  394. assert False
  395. try:
  396. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  397. except ldap.LDAPError as e:
  398. log.fatal('test_rootdn_access_allowed_ip: Root DN bind failed unexpectedly failed: error ' +
  399. e.message['desc'])
  400. assert False
  401. #
  402. # Cleanup - undo everything we did so the next test has a clean slate
  403. #
  404. try:
  405. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_DELETE, 'rootdn-allow-ip', None)])
  406. except ldap.LDAPError as e:
  407. log.fatal('test_rootdn_access_allowed_ip: Failed to delete(rootdn-allow-ip): error ' +
  408. e.message['desc'])
  409. assert False
  410. try:
  411. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  412. except ldap.LDAPError as e:
  413. log.fatal('test_rootdn_access_allowed_ip: Root DN bind failed unexpectedly failed: error ' +
  414. e.message['desc'])
  415. assert False
  416. log.info('test_rootdn_access_allowed_ip: PASSED')
  417. def test_rootdn_access_allowed_host(topology):
  418. '''
  419. Test allowed ip feature
  420. '''
  421. log.info('Running test_rootdn_access_allowed_host...')
  422. #
  423. # Set allowed host to an unknown host - blocks the Root DN
  424. #
  425. try:
  426. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-allow-host', 'i.dont.exist.com')])
  427. except ldap.LDAPError as e:
  428. log.fatal('test_rootdn_access_allowed_host: Failed to set allowed host: error ' +
  429. e.message['desc'])
  430. assert False
  431. #
  432. # Bind as Root DN - should fail
  433. #
  434. try:
  435. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  436. succeeded = True
  437. except ldap.LDAPError as e:
  438. succeeded = False
  439. if succeeded:
  440. log.fatal('test_rootdn_access_allowed_host: Root DN was incorrectly able to bind')
  441. assert False
  442. #
  443. # Allow localhost
  444. #
  445. try:
  446. topology.standalone.simple_bind_s(USER1_DN, PASSWORD)
  447. except ldap.LDAPError as e:
  448. log.fatal('test_rootdn_access_allowed_host: : failed to bind as user1')
  449. assert False
  450. try:
  451. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_ADD, 'rootdn-allow-host', 'localhost.localdomain')])
  452. except ldap.LDAPError as e:
  453. log.fatal('test_rootdn_access_allowed_host: Failed to set allowed host: error ' +
  454. e.message['desc'])
  455. assert False
  456. try:
  457. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  458. except ldap.LDAPError as e:
  459. log.fatal('test_rootdn_access_allowed_host: Root DN bind failed unexpectedly failed: error ' +
  460. e.message['desc'])
  461. assert False
  462. #
  463. # Cleanup - undo everything we did so the next test has a clean slate
  464. #
  465. try:
  466. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_DELETE, 'rootdn-allow-host', None)])
  467. except ldap.LDAPError as e:
  468. log.fatal('test_rootdn_access_allowed_host: Failed to delete(rootdn-allow-host): error ' +
  469. e.message['desc'])
  470. assert False
  471. try:
  472. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  473. except ldap.LDAPError as e:
  474. log.fatal('test_rootdn_access_allowed_host: Root DN bind failed unexpectedly failed: error ' +
  475. e.message['desc'])
  476. assert False
  477. log.info('test_rootdn_access_allowed_host: PASSED')
  478. def test_rootdn_config_validate(topology):
  479. '''
  480. Test configuration validation
  481. test single valued attributes: rootdn-open-time,
  482. rootdn-close-time,
  483. rootdn-days-allowed
  484. '''
  485. log.info('Running test_rootdn_config_validate...')
  486. #
  487. # Test rootdn-open-time
  488. #
  489. try:
  490. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-open-time', '0000')])
  491. log.fatal('test_rootdn_config_validate: Incorrectly allowed to just add "rootdn-open-time" ')
  492. assert False
  493. except ldap.LDAPError:
  494. pass
  495. try:
  496. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_ADD, 'rootdn-open-time', '0000'),
  497. (ldap.MOD_ADD, 'rootdn-open-time', '0001')])
  498. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add multiple "rootdn-open-time"')
  499. assert False
  500. except ldap.LDAPError:
  501. pass
  502. try:
  503. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-open-time', '-1'),
  504. (ldap.MOD_REPLACE, 'rootdn-close-time', '0000')])
  505. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-open-time: -1"')
  506. assert False
  507. except ldap.LDAPError:
  508. pass
  509. try:
  510. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-open-time', '2400'),
  511. (ldap.MOD_REPLACE, 'rootdn-close-time', '0000')])
  512. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-open-time: 2400"')
  513. assert False
  514. except ldap.LDAPError:
  515. pass
  516. try:
  517. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-open-time', 'aaaaa'),
  518. (ldap.MOD_REPLACE, 'rootdn-close-time', '0000')])
  519. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-open-time: aaaaa"')
  520. assert False
  521. except ldap.LDAPError:
  522. pass
  523. #
  524. # Test rootdn-close-time
  525. #
  526. try:
  527. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-close-time', '0000')])
  528. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add just "rootdn-close-time"')
  529. assert False
  530. except ldap.LDAPError:
  531. pass
  532. try:
  533. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_ADD, 'rootdn-close-time', '0000'),
  534. (ldap.MOD_ADD, 'rootdn-close-time', '0001')])
  535. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add multiple "rootdn-open-time"')
  536. assert False
  537. except ldap.LDAPError:
  538. pass
  539. try:
  540. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-open-time', '0000'),
  541. (ldap.MOD_REPLACE, 'rootdn-close-time', '-1')])
  542. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-close-time: -1"')
  543. assert False
  544. except ldap.LDAPError:
  545. pass
  546. try:
  547. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-open-time', '0000'),
  548. (ldap.MOD_REPLACE, 'rootdn-close-time', '2400')])
  549. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-close-time: 2400"')
  550. assert False
  551. except ldap.LDAPError:
  552. pass
  553. try:
  554. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-open-time', '0000'),
  555. (ldap.MOD_REPLACE, 'rootdn-close-time', 'aaaaa')])
  556. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-close-time: aaaaa"')
  557. assert False
  558. except ldap.LDAPError:
  559. pass
  560. #
  561. # Test days allowed
  562. #
  563. try:
  564. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_ADD, 'rootdn-days-allowed', 'Mon'),
  565. (ldap.MOD_ADD, 'rootdn-days-allowed', 'Tue')])
  566. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add two "rootdn-days-allowed"')
  567. assert False
  568. except ldap.LDAPError:
  569. pass
  570. try:
  571. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-days-allowed', 'Mon1')])
  572. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-days-allowed: Mon1"')
  573. assert False
  574. except ldap.LDAPError:
  575. pass
  576. try:
  577. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-days-allowed', 'Tue, Mon1')])
  578. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-days-allowed: Tue, Mon1"')
  579. assert False
  580. except ldap.LDAPError:
  581. pass
  582. try:
  583. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-days-allowed', 'm111m')])
  584. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-days-allowed: 111"')
  585. assert False
  586. except ldap.LDAPError:
  587. pass
  588. try:
  589. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-days-allowed', 'Gur')])
  590. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-days-allowed: Gur"')
  591. assert False
  592. except ldap.LDAPError:
  593. pass
  594. #
  595. # Test allow ips
  596. #
  597. try:
  598. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-allow-ip', '12.12.Z.12')])
  599. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-allow-ip: 12.12.Z.12"')
  600. assert False
  601. except ldap.LDAPError:
  602. pass
  603. #
  604. # Test deny ips
  605. #
  606. try:
  607. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-deny-ip', '12.12.Z.12')])
  608. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-deny-ip: 12.12.Z.12"')
  609. assert False
  610. except ldap.LDAPError:
  611. pass
  612. #
  613. # Test allow hosts
  614. #
  615. try:
  616. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-allow-host', 'host._.com')])
  617. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-allow-host: host._.com"')
  618. assert False
  619. except ldap.LDAPError:
  620. pass
  621. #
  622. # Test deny hosts
  623. #
  624. try:
  625. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-deny-host', 'host.####.com')])
  626. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-deny-host: host.####.com"')
  627. assert False
  628. except ldap.LDAPError:
  629. pass
  630. log.info('test_rootdn_config_validate: PASSED')
  631. def test_rootdn_final(topology):
  632. topology.standalone.delete()
  633. log.info('Root DN Access Control test suite PASSED')
  634. def run_isolated():
  635. global installation1_prefix
  636. installation1_prefix = None
  637. topo = topology(True)
  638. test_rootdn_init(topo)
  639. test_rootdn_access_specific_time(topo)
  640. test_rootdn_access_day_of_week(topo)
  641. test_rootdn_access_allowed_ip(topo)
  642. test_rootdn_access_denied_ip(topo)
  643. test_rootdn_access_allowed_host(topo)
  644. test_rootdn_access_denied_host(topo)
  645. test_rootdn_config_validate(topo)
  646. test_rootdn_final(topo)
  647. if __name__ == '__main__':
  648. run_isolated()