rootdn_plugin_test.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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. try:
  317. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_ADD,
  318. 'rootdn-deny-host',
  319. hostname)])
  320. except ldap.LDAPError as e:
  321. log.fatal('test_rootdn_access_denied_host: Failed to set deny host: error ' +
  322. e.message['desc'])
  323. assert False
  324. #
  325. # Bind as Root DN - should fail
  326. #
  327. try:
  328. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  329. succeeded = True
  330. except ldap.LDAPError as e:
  331. succeeded = False
  332. if succeeded:
  333. log.fatal('test_rootdn_access_denied_host: Root DN was incorrectly able to bind')
  334. assert False
  335. #
  336. # Change the denied host so root DN succeeds
  337. #
  338. try:
  339. topology.standalone.simple_bind_s(USER1_DN, PASSWORD)
  340. except ldap.LDAPError as e:
  341. log.fatal('test_rootdn_access_denied_host: : failed to bind as user1')
  342. assert False
  343. try:
  344. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-deny-host', 'i.dont.exist.com')])
  345. except ldap.LDAPError as e:
  346. log.fatal('test_rootdn_access_denied_host: Failed to set rootDN plugin config: error ' +
  347. e.message['desc'])
  348. assert False
  349. try:
  350. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  351. except ldap.LDAPError as e:
  352. log.fatal('test_rootdn_access_denied_host: Root DN bind failed unexpectedly failed: error ' +
  353. e.message['desc'])
  354. assert False
  355. #
  356. # Cleanup - undo the changes we made so the next test has a clean slate
  357. #
  358. try:
  359. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_DELETE, 'rootdn-deny-host', None)])
  360. except ldap.LDAPError as e:
  361. log.fatal('test_rootdn_access_denied_host: Failed to set rootDN plugin config: error ' +
  362. e.message['desc'])
  363. assert False
  364. try:
  365. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  366. except ldap.LDAPError as e:
  367. log.fatal('test_rootdn_access_denied_host: Root DN bind failed unexpectedly failed: error ' +
  368. e.message['desc'])
  369. assert False
  370. log.info('test_rootdn_access_denied_host: PASSED')
  371. def test_rootdn_access_allowed_ip(topology):
  372. '''
  373. Test allowed ip feature
  374. '''
  375. log.info('Running test_rootdn_access_allowed_ip...')
  376. #
  377. # Set allowed host to an unknown host - blocks the Root DN
  378. #
  379. try:
  380. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-allow-ip', '255.255.255.255')])
  381. except ldap.LDAPError as e:
  382. log.fatal('test_rootdn_access_allowed_ip: Failed to set allowed host: error ' +
  383. e.message['desc'])
  384. assert False
  385. #
  386. # Bind as Root DN - should fail
  387. #
  388. try:
  389. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  390. succeeded = True
  391. except ldap.LDAPError as e:
  392. succeeded = False
  393. if succeeded:
  394. log.fatal('test_rootdn_access_allowed_ip: Root DN was incorrectly able to bind')
  395. assert False
  396. #
  397. # Allow localhost
  398. #
  399. try:
  400. topology.standalone.simple_bind_s(USER1_DN, PASSWORD)
  401. except ldap.LDAPError as e:
  402. log.fatal('test_rootdn_access_allowed_ip: : failed to bind as user1')
  403. assert False
  404. try:
  405. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-allow-ip', '127.0.0.1'),
  406. (ldap.MOD_ADD, 'rootdn-allow-ip', '::1')])
  407. except ldap.LDAPError as e:
  408. log.fatal('test_rootdn_access_allowed_ip: Failed to set allowed host: error ' +
  409. e.message['desc'])
  410. assert False
  411. try:
  412. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  413. except ldap.LDAPError as e:
  414. log.fatal('test_rootdn_access_allowed_ip: Root DN bind failed unexpectedly failed: error ' +
  415. e.message['desc'])
  416. assert False
  417. #
  418. # Cleanup - undo everything we did so the next test has a clean slate
  419. #
  420. try:
  421. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_DELETE, 'rootdn-allow-ip', None)])
  422. except ldap.LDAPError as e:
  423. log.fatal('test_rootdn_access_allowed_ip: Failed to delete(rootdn-allow-ip): error ' +
  424. e.message['desc'])
  425. assert False
  426. try:
  427. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  428. except ldap.LDAPError as e:
  429. log.fatal('test_rootdn_access_allowed_ip: Root DN bind failed unexpectedly failed: error ' +
  430. e.message['desc'])
  431. assert False
  432. log.info('test_rootdn_access_allowed_ip: PASSED')
  433. def test_rootdn_access_allowed_host(topology):
  434. '''
  435. Test allowed ip feature
  436. '''
  437. log.info('Running test_rootdn_access_allowed_host...')
  438. #
  439. # Set allowed host to an unknown host - blocks the Root DN
  440. #
  441. try:
  442. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-allow-host', 'i.dont.exist.com')])
  443. except ldap.LDAPError as e:
  444. log.fatal('test_rootdn_access_allowed_host: Failed to set allowed host: error ' +
  445. e.message['desc'])
  446. assert False
  447. #
  448. # Bind as Root DN - should fail
  449. #
  450. try:
  451. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  452. succeeded = True
  453. except ldap.LDAPError as e:
  454. succeeded = False
  455. if succeeded:
  456. log.fatal('test_rootdn_access_allowed_host: Root DN was incorrectly able to bind')
  457. assert False
  458. #
  459. # Allow localhost
  460. #
  461. try:
  462. topology.standalone.simple_bind_s(USER1_DN, PASSWORD)
  463. except ldap.LDAPError as e:
  464. log.fatal('test_rootdn_access_allowed_host: : failed to bind as user1')
  465. assert False
  466. try:
  467. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_ADD, 'rootdn-allow-host', 'localhost.localdomain')])
  468. except ldap.LDAPError as e:
  469. log.fatal('test_rootdn_access_allowed_host: Failed to set allowed host: error ' +
  470. e.message['desc'])
  471. assert False
  472. try:
  473. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  474. except ldap.LDAPError as e:
  475. log.fatal('test_rootdn_access_allowed_host: Root DN bind failed unexpectedly failed: error ' +
  476. e.message['desc'])
  477. assert False
  478. #
  479. # Cleanup - undo everything we did so the next test has a clean slate
  480. #
  481. try:
  482. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_DELETE, 'rootdn-allow-host', None)])
  483. except ldap.LDAPError as e:
  484. log.fatal('test_rootdn_access_allowed_host: Failed to delete(rootdn-allow-host): error ' +
  485. e.message['desc'])
  486. assert False
  487. try:
  488. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  489. except ldap.LDAPError as e:
  490. log.fatal('test_rootdn_access_allowed_host: Root DN bind failed unexpectedly failed: error ' +
  491. e.message['desc'])
  492. assert False
  493. log.info('test_rootdn_access_allowed_host: PASSED')
  494. def test_rootdn_config_validate(topology):
  495. '''
  496. Test configuration validation
  497. test single valued attributes: rootdn-open-time,
  498. rootdn-close-time,
  499. rootdn-days-allowed
  500. '''
  501. log.info('Running test_rootdn_config_validate...')
  502. #
  503. # Test rootdn-open-time
  504. #
  505. try:
  506. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-open-time', '0000')])
  507. log.fatal('test_rootdn_config_validate: Incorrectly allowed to just add "rootdn-open-time" ')
  508. assert False
  509. except ldap.LDAPError:
  510. pass
  511. try:
  512. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_ADD, 'rootdn-open-time', '0000'),
  513. (ldap.MOD_ADD, 'rootdn-open-time', '0001')])
  514. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add multiple "rootdn-open-time"')
  515. assert False
  516. except ldap.LDAPError:
  517. pass
  518. try:
  519. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-open-time', '-1'),
  520. (ldap.MOD_REPLACE, 'rootdn-close-time', '0000')])
  521. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-open-time: -1"')
  522. assert False
  523. except ldap.LDAPError:
  524. pass
  525. try:
  526. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-open-time', '2400'),
  527. (ldap.MOD_REPLACE, 'rootdn-close-time', '0000')])
  528. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-open-time: 2400"')
  529. assert False
  530. except ldap.LDAPError:
  531. pass
  532. try:
  533. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-open-time', 'aaaaa'),
  534. (ldap.MOD_REPLACE, 'rootdn-close-time', '0000')])
  535. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-open-time: aaaaa"')
  536. assert False
  537. except ldap.LDAPError:
  538. pass
  539. #
  540. # Test rootdn-close-time
  541. #
  542. try:
  543. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-close-time', '0000')])
  544. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add just "rootdn-close-time"')
  545. assert False
  546. except ldap.LDAPError:
  547. pass
  548. try:
  549. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_ADD, 'rootdn-close-time', '0000'),
  550. (ldap.MOD_ADD, 'rootdn-close-time', '0001')])
  551. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add multiple "rootdn-open-time"')
  552. assert False
  553. except ldap.LDAPError:
  554. pass
  555. try:
  556. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-open-time', '0000'),
  557. (ldap.MOD_REPLACE, 'rootdn-close-time', '-1')])
  558. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-close-time: -1"')
  559. assert False
  560. except ldap.LDAPError:
  561. pass
  562. try:
  563. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-open-time', '0000'),
  564. (ldap.MOD_REPLACE, 'rootdn-close-time', '2400')])
  565. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-close-time: 2400"')
  566. assert False
  567. except ldap.LDAPError:
  568. pass
  569. try:
  570. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-open-time', '0000'),
  571. (ldap.MOD_REPLACE, 'rootdn-close-time', 'aaaaa')])
  572. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-close-time: aaaaa"')
  573. assert False
  574. except ldap.LDAPError:
  575. pass
  576. #
  577. # Test days allowed
  578. #
  579. try:
  580. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_ADD, 'rootdn-days-allowed', 'Mon'),
  581. (ldap.MOD_ADD, 'rootdn-days-allowed', 'Tue')])
  582. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add two "rootdn-days-allowed"')
  583. assert False
  584. except ldap.LDAPError:
  585. pass
  586. try:
  587. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-days-allowed', 'Mon1')])
  588. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-days-allowed: Mon1"')
  589. assert False
  590. except ldap.LDAPError:
  591. pass
  592. try:
  593. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-days-allowed', 'Tue, Mon1')])
  594. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-days-allowed: Tue, Mon1"')
  595. assert False
  596. except ldap.LDAPError:
  597. pass
  598. try:
  599. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-days-allowed', 'm111m')])
  600. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-days-allowed: 111"')
  601. assert False
  602. except ldap.LDAPError:
  603. pass
  604. try:
  605. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-days-allowed', 'Gur')])
  606. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-days-allowed: Gur"')
  607. assert False
  608. except ldap.LDAPError:
  609. pass
  610. #
  611. # Test allow ips
  612. #
  613. try:
  614. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-allow-ip', '12.12.Z.12')])
  615. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-allow-ip: 12.12.Z.12"')
  616. assert False
  617. except ldap.LDAPError:
  618. pass
  619. #
  620. # Test deny ips
  621. #
  622. try:
  623. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-deny-ip', '12.12.Z.12')])
  624. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-deny-ip: 12.12.Z.12"')
  625. assert False
  626. except ldap.LDAPError:
  627. pass
  628. #
  629. # Test allow hosts
  630. #
  631. try:
  632. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-allow-host', 'host._.com')])
  633. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-allow-host: host._.com"')
  634. assert False
  635. except ldap.LDAPError:
  636. pass
  637. #
  638. # Test deny hosts
  639. #
  640. try:
  641. topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_REPLACE, 'rootdn-deny-host', 'host.####.com')])
  642. log.fatal('test_rootdn_config_validate: Incorrectly allowed to add invalid "rootdn-deny-host: host.####.com"')
  643. assert False
  644. except ldap.LDAPError:
  645. pass
  646. log.info('test_rootdn_config_validate: PASSED')
  647. if __name__ == '__main__':
  648. # Run isolated
  649. # -s for DEBUG mode
  650. CURRENT_FILE = os.path.realpath(__file__)
  651. pytest.main("-s %s" % CURRENT_FILE)