rootdn_plugin_test.py 25 KB

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