rootdn_plugin_test.py 25 KB

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