rootdn_plugin_test.py 26 KB

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