ticket47828_test.py 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. import os
  2. import sys
  3. import time
  4. import ldap
  5. import logging
  6. import socket
  7. import pytest
  8. import shutil
  9. from lib389 import DirSrv, Entry, tools
  10. from lib389.tools import DirSrvTools
  11. from lib389._constants import *
  12. from lib389.properties import *
  13. from constants import *
  14. log = logging.getLogger(__name__)
  15. installation_prefix = None
  16. ACCT_POLICY_CONFIG_DN = 'cn=config,cn=%s,cn=plugins,cn=config' % PLUGIN_ACCT_POLICY
  17. ACCT_POLICY_DN = 'cn=Account Inactivation Pplicy,%s' % SUFFIX
  18. INACTIVITY_LIMIT = '9'
  19. SEARCHFILTER = '(objectclass=*)'
  20. DUMMY_CONTAINER = 'cn=dummy container,%s' % SUFFIX
  21. PROVISIONING = 'cn=provisioning,%s' % SUFFIX
  22. ACTIVE_USER1_CN = 'active user1'
  23. ACTIVE_USER1_DN = 'cn=%s,%s' % (ACTIVE_USER1_CN, SUFFIX)
  24. STAGED_USER1_CN = 'staged user1'
  25. STAGED_USER1_DN = 'cn=%s,%s' % (STAGED_USER1_CN, PROVISIONING)
  26. DUMMY_USER1_CN = 'dummy user1'
  27. DUMMY_USER1_DN = 'cn=%s,%s' % (DUMMY_USER1_CN, DUMMY_CONTAINER)
  28. ALLOCATED_ATTR = 'employeeNumber'
  29. class TopologyStandalone(object):
  30. def __init__(self, standalone):
  31. standalone.open()
  32. self.standalone = standalone
  33. @pytest.fixture(scope="module")
  34. def topology(request):
  35. '''
  36. This fixture is used to standalone topology for the 'module'.
  37. At the beginning, It may exists a standalone instance.
  38. It may also exists a backup for the standalone instance.
  39. Principle:
  40. If standalone instance exists:
  41. restart it
  42. If backup of standalone exists:
  43. create/rebind to standalone
  44. restore standalone instance from backup
  45. else:
  46. Cleanup everything
  47. remove instance
  48. remove backup
  49. Create instance
  50. Create backup
  51. '''
  52. global installation_prefix
  53. if installation_prefix:
  54. args_instance[SER_DEPLOYED_DIR] = installation_prefix
  55. standalone = DirSrv(verbose=False)
  56. # Args for the standalone instance
  57. args_instance[SER_HOST] = HOST_STANDALONE
  58. args_instance[SER_PORT] = PORT_STANDALONE
  59. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  60. args_standalone = args_instance.copy()
  61. standalone.allocate(args_standalone)
  62. # Get the status of the backups
  63. backup_standalone = standalone.checkBackupFS()
  64. # Get the status of the instance and restart it if it exists
  65. instance_standalone = standalone.exists()
  66. if instance_standalone:
  67. # assuming the instance is already stopped, just wait 5 sec max
  68. standalone.stop(timeout=5)
  69. try:
  70. standalone.start(timeout=10)
  71. except ldap.SERVER_DOWN:
  72. pass
  73. if backup_standalone:
  74. # The backup exist, assuming it is correct
  75. # we just re-init the instance with it
  76. if not instance_standalone:
  77. standalone.create()
  78. # Used to retrieve configuration information (dbdir, confdir...)
  79. standalone.open()
  80. # restore standalone instance from backup
  81. standalone.stop(timeout=10)
  82. standalone.restoreFS(backup_standalone)
  83. standalone.start(timeout=10)
  84. else:
  85. # We should be here only in two conditions
  86. # - This is the first time a test involve standalone instance
  87. # - Something weird happened (instance/backup destroyed)
  88. # so we discard everything and recreate all
  89. # Remove the backup. So even if we have a specific backup file
  90. # (e.g backup_standalone) we clear backup that an instance may have created
  91. if backup_standalone:
  92. standalone.clearBackupFS()
  93. # Remove the instance
  94. if instance_standalone:
  95. standalone.delete()
  96. # Create the instance
  97. standalone.create()
  98. # Used to retrieve configuration information (dbdir, confdir...)
  99. standalone.open()
  100. # Time to create the backups
  101. standalone.stop(timeout=10)
  102. standalone.backupfile = standalone.backupFS()
  103. standalone.start(timeout=10)
  104. #
  105. # Here we have standalone instance up and running
  106. # Either coming from a backup recovery
  107. # or from a fresh (re)init
  108. # Time to return the topology
  109. return TopologyStandalone(standalone)
  110. def _header(topology, label):
  111. topology.standalone.log.info("\n\n###############################################")
  112. topology.standalone.log.info("#######")
  113. topology.standalone.log.info("####### %s" % label)
  114. topology.standalone.log.info("#######")
  115. topology.standalone.log.info("###############################################")
  116. def test_ticket47828_init(topology):
  117. """
  118. Enable DNA
  119. """
  120. topology.standalone.plugins.enable(name=PLUGIN_DNA)
  121. topology.standalone.add_s(Entry((PROVISIONING,{'objectclass': "top nscontainer".split(),
  122. 'cn': 'provisioning'})))
  123. topology.standalone.add_s(Entry((DUMMY_CONTAINER,{'objectclass': "top nscontainer".split(),
  124. 'cn': 'dummy container'})))
  125. dn_config = "cn=excluded scope, cn=%s, %s" % (PLUGIN_DNA, DN_PLUGIN)
  126. topology.standalone.add_s(Entry((dn_config, {'objectclass': "top extensibleObject".split(),
  127. 'cn': 'excluded scope',
  128. 'dnaType': ALLOCATED_ATTR,
  129. 'dnaNextValue': str(1000),
  130. 'dnaMaxValue': str(2000),
  131. 'dnaMagicRegen': str(-1),
  132. 'dnaFilter': '(&(objectClass=person)(objectClass=organizationalPerson)(objectClass=inetOrgPerson))',
  133. 'dnaScope': SUFFIX})))
  134. topology.standalone.restart(timeout=10)
  135. def test_ticket47828_run_0(topology):
  136. """
  137. NO exclude scope: Add an active entry and check its ALLOCATED_ATTR is set
  138. """
  139. _header(topology, 'NO exclude scope: Add an active entry and check its ALLOCATED_ATTR is set')
  140. topology.standalone.add_s(Entry((ACTIVE_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  141. 'cn': ACTIVE_USER1_CN,
  142. 'sn': ACTIVE_USER1_CN,
  143. ALLOCATED_ATTR: str(-1)})))
  144. ent = topology.standalone.getEntry(ACTIVE_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  145. assert ent.hasAttr(ALLOCATED_ATTR)
  146. assert ent.getValue(ALLOCATED_ATTR) != str(-1)
  147. topology.standalone.log.debug('%s.%s=%s' % (ACTIVE_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  148. topology.standalone.delete_s(ACTIVE_USER1_DN)
  149. def test_ticket47828_run_1(topology):
  150. """
  151. NO exclude scope: Add an active entry and check its ALLOCATED_ATTR is unchanged (!= magic)
  152. """
  153. _header(topology, 'NO exclude scope: Add an active entry and check its ALLOCATED_ATTR is unchanged (!= magic)')
  154. topology.standalone.add_s(Entry((ACTIVE_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  155. 'cn': ACTIVE_USER1_CN,
  156. 'sn': ACTIVE_USER1_CN,
  157. ALLOCATED_ATTR: str(20)})))
  158. ent = topology.standalone.getEntry(ACTIVE_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  159. assert ent.hasAttr(ALLOCATED_ATTR)
  160. assert ent.getValue(ALLOCATED_ATTR) == str(20)
  161. topology.standalone.log.debug('%s.%s=%s' % (ACTIVE_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  162. topology.standalone.delete_s(ACTIVE_USER1_DN)
  163. def test_ticket47828_run_2(topology):
  164. """
  165. NO exclude scope: Add a staged entry and check its ALLOCATED_ATTR is set
  166. """
  167. _header(topology, 'NO exclude scope: Add a staged entry and check its ALLOCATED_ATTR is set')
  168. topology.standalone.add_s(Entry((STAGED_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  169. 'cn': STAGED_USER1_CN,
  170. 'sn': STAGED_USER1_CN,
  171. ALLOCATED_ATTR: str(-1)})))
  172. ent = topology.standalone.getEntry(STAGED_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  173. assert ent.hasAttr(ALLOCATED_ATTR)
  174. assert ent.getValue(ALLOCATED_ATTR) != str(-1)
  175. topology.standalone.log.debug('%s.%s=%s' % (STAGED_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  176. topology.standalone.delete_s(STAGED_USER1_DN)
  177. def test_ticket47828_run_3(topology):
  178. """
  179. NO exclude scope: Add a staged entry and check its ALLOCATED_ATTR is unchanged (!= magic)
  180. """
  181. _header(topology, 'NO exclude scope: Add a staged entry and check its ALLOCATED_ATTR is unchanged (!= magic)')
  182. topology.standalone.add_s(Entry((STAGED_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  183. 'cn': STAGED_USER1_CN,
  184. 'sn': STAGED_USER1_CN,
  185. ALLOCATED_ATTR: str(20)})))
  186. ent = topology.standalone.getEntry(STAGED_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  187. assert ent.hasAttr(ALLOCATED_ATTR)
  188. assert ent.getValue(ALLOCATED_ATTR) == str(20)
  189. topology.standalone.log.debug('%s.%s=%s' % (STAGED_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  190. topology.standalone.delete_s(STAGED_USER1_DN)
  191. def test_ticket47828_run_4(topology):
  192. '''
  193. Exclude the provisioning container
  194. '''
  195. _header(topology, 'Exclude the provisioning container')
  196. dn_config = "cn=excluded scope, cn=%s, %s" % (PLUGIN_DNA, DN_PLUGIN)
  197. mod = [(ldap.MOD_REPLACE, 'dnaExcludeScope', PROVISIONING)]
  198. topology.standalone.modify_s(dn_config, mod)
  199. def test_ticket47828_run_5(topology):
  200. """
  201. Provisioning excluded scope: Add an active entry and check its ALLOCATED_ATTR is set
  202. """
  203. _header(topology, 'Provisioning excluded scope: Add an active entry and check its ALLOCATED_ATTR is set')
  204. topology.standalone.add_s(Entry((ACTIVE_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  205. 'cn': ACTIVE_USER1_CN,
  206. 'sn': ACTIVE_USER1_CN,
  207. ALLOCATED_ATTR: str(-1)})))
  208. ent = topology.standalone.getEntry(ACTIVE_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  209. assert ent.hasAttr(ALLOCATED_ATTR)
  210. assert ent.getValue(ALLOCATED_ATTR) != str(-1)
  211. topology.standalone.log.debug('%s.%s=%s' % (ACTIVE_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  212. topology.standalone.delete_s(ACTIVE_USER1_DN)
  213. def test_ticket47828_run_6(topology):
  214. """
  215. Provisioning excluded scope: Add an active entry and check its ALLOCATED_ATTR is unchanged (!= magic)
  216. """
  217. _header(topology, 'Provisioning excluded scope: Add an active entry and check its ALLOCATED_ATTR is unchanged (!= magic)')
  218. topology.standalone.add_s(Entry((ACTIVE_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  219. 'cn': ACTIVE_USER1_CN,
  220. 'sn': ACTIVE_USER1_CN,
  221. ALLOCATED_ATTR: str(20)})))
  222. ent = topology.standalone.getEntry(ACTIVE_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  223. assert ent.hasAttr(ALLOCATED_ATTR)
  224. assert ent.getValue(ALLOCATED_ATTR) == str(20)
  225. topology.standalone.log.debug('%s.%s=%s' % (ACTIVE_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  226. topology.standalone.delete_s(ACTIVE_USER1_DN)
  227. def test_ticket47828_run_7(topology):
  228. """
  229. Provisioning excluded scope: Add a staged entry and check its ALLOCATED_ATTR is not set
  230. """
  231. _header(topology, 'Provisioning excluded scope: Add a staged entry and check its ALLOCATED_ATTR is not set')
  232. topology.standalone.add_s(Entry((STAGED_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  233. 'cn': STAGED_USER1_CN,
  234. 'sn': STAGED_USER1_CN,
  235. ALLOCATED_ATTR: str(-1)})))
  236. ent = topology.standalone.getEntry(STAGED_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  237. assert ent.hasAttr(ALLOCATED_ATTR)
  238. assert ent.getValue(ALLOCATED_ATTR) == str(-1)
  239. topology.standalone.log.debug('%s.%s=%s' % (STAGED_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  240. topology.standalone.delete_s(STAGED_USER1_DN)
  241. def test_ticket47828_run_8(topology):
  242. """
  243. Provisioning excluded scope: Add a staged entry and check its ALLOCATED_ATTR is unchanged (!= magic)
  244. """
  245. _header(topology, 'Provisioning excluded scope: Add a staged entry and check its ALLOCATED_ATTR is unchanged (!= magic)')
  246. topology.standalone.add_s(Entry((STAGED_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  247. 'cn': STAGED_USER1_CN,
  248. 'sn': STAGED_USER1_CN,
  249. ALLOCATED_ATTR: str(20)})))
  250. ent = topology.standalone.getEntry(STAGED_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  251. assert ent.hasAttr(ALLOCATED_ATTR)
  252. assert ent.getValue(ALLOCATED_ATTR) == str(20)
  253. topology.standalone.log.debug('%s.%s=%s' % (STAGED_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  254. topology.standalone.delete_s(STAGED_USER1_DN)
  255. def test_ticket47828_run_9(topology):
  256. """
  257. Provisioning excluded scope: Add an dummy entry and check its ALLOCATED_ATTR is set
  258. """
  259. _header(topology, 'Provisioning excluded scope: Add an dummy entry and check its ALLOCATED_ATTR is set')
  260. topology.standalone.add_s(Entry((DUMMY_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  261. 'cn': DUMMY_USER1_CN,
  262. 'sn': DUMMY_USER1_CN,
  263. ALLOCATED_ATTR: str(-1)})))
  264. ent = topology.standalone.getEntry(DUMMY_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  265. assert ent.hasAttr(ALLOCATED_ATTR)
  266. assert ent.getValue(ALLOCATED_ATTR) != str(-1)
  267. topology.standalone.log.debug('%s.%s=%s' % (DUMMY_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  268. topology.standalone.delete_s(DUMMY_USER1_DN)
  269. def test_ticket47828_run_10(topology):
  270. """
  271. Provisioning excluded scope: Add an dummy entry and check its ALLOCATED_ATTR is unchanged (!= magic)
  272. """
  273. _header(topology, 'Provisioning excluded scope: Add an dummy entry and check its ALLOCATED_ATTR is unchanged (!= magic)')
  274. topology.standalone.add_s(Entry((DUMMY_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  275. 'cn': DUMMY_USER1_CN,
  276. 'sn': DUMMY_USER1_CN,
  277. ALLOCATED_ATTR: str(20)})))
  278. ent = topology.standalone.getEntry(DUMMY_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  279. assert ent.hasAttr(ALLOCATED_ATTR)
  280. assert ent.getValue(ALLOCATED_ATTR) == str(20)
  281. topology.standalone.log.debug('%s.%s=%s' % (DUMMY_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  282. topology.standalone.delete_s(DUMMY_USER1_DN)
  283. def test_ticket47828_run_11(topology):
  284. '''
  285. Exclude (in addition) the dummy container
  286. '''
  287. _header(topology, 'Exclude (in addition) the dummy container')
  288. dn_config = "cn=excluded scope, cn=%s, %s" % (PLUGIN_DNA, DN_PLUGIN)
  289. mod = [(ldap.MOD_ADD, 'dnaExcludeScope', DUMMY_CONTAINER)]
  290. topology.standalone.modify_s(dn_config, mod)
  291. def test_ticket47828_run_12(topology):
  292. """
  293. Provisioning/Dummy excluded scope: Add an active entry and check its ALLOCATED_ATTR is set
  294. """
  295. _header(topology, 'Provisioning/Dummy excluded scope: Add an active entry and check its ALLOCATED_ATTR is set')
  296. topology.standalone.add_s(Entry((ACTIVE_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  297. 'cn': ACTIVE_USER1_CN,
  298. 'sn': ACTIVE_USER1_CN,
  299. ALLOCATED_ATTR: str(-1)})))
  300. ent = topology.standalone.getEntry(ACTIVE_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  301. assert ent.hasAttr(ALLOCATED_ATTR)
  302. assert ent.getValue(ALLOCATED_ATTR) != str(-1)
  303. topology.standalone.log.debug('%s.%s=%s' % (ACTIVE_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  304. topology.standalone.delete_s(ACTIVE_USER1_DN)
  305. def test_ticket47828_run_13(topology):
  306. """
  307. Provisioning/Dummy excluded scope: Add an active entry and check its ALLOCATED_ATTR is unchanged (!= magic)
  308. """
  309. _header(topology, 'Provisioning/Dummy excluded scope: Add an active entry and check its ALLOCATED_ATTR is unchanged (!= magic)')
  310. topology.standalone.add_s(Entry((ACTIVE_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  311. 'cn': ACTIVE_USER1_CN,
  312. 'sn': ACTIVE_USER1_CN,
  313. ALLOCATED_ATTR: str(20)})))
  314. ent = topology.standalone.getEntry(ACTIVE_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  315. assert ent.hasAttr(ALLOCATED_ATTR)
  316. assert ent.getValue(ALLOCATED_ATTR) == str(20)
  317. topology.standalone.log.debug('%s.%s=%s' % (ACTIVE_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  318. topology.standalone.delete_s(ACTIVE_USER1_DN)
  319. def test_ticket47828_run_14(topology):
  320. """
  321. Provisioning/Dummy excluded scope: Add a staged entry and check its ALLOCATED_ATTR is not set
  322. """
  323. _header(topology, 'Provisioning/Dummy excluded scope: Add a staged entry and check its ALLOCATED_ATTR is not set')
  324. topology.standalone.add_s(Entry((STAGED_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  325. 'cn': STAGED_USER1_CN,
  326. 'sn': STAGED_USER1_CN,
  327. ALLOCATED_ATTR: str(-1)})))
  328. ent = topology.standalone.getEntry(STAGED_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  329. assert ent.hasAttr(ALLOCATED_ATTR)
  330. assert ent.getValue(ALLOCATED_ATTR) == str(-1)
  331. topology.standalone.log.debug('%s.%s=%s' % (STAGED_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  332. topology.standalone.delete_s(STAGED_USER1_DN)
  333. def test_ticket47828_run_15(topology):
  334. """
  335. Provisioning/Dummy excluded scope: Add a staged entry and check its ALLOCATED_ATTR is unchanged (!= magic)
  336. """
  337. _header(topology, 'Provisioning/Dummy excluded scope: Add a staged entry and check its ALLOCATED_ATTR is unchanged (!= magic)')
  338. topology.standalone.add_s(Entry((STAGED_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  339. 'cn': STAGED_USER1_CN,
  340. 'sn': STAGED_USER1_CN,
  341. ALLOCATED_ATTR: str(20)})))
  342. ent = topology.standalone.getEntry(STAGED_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  343. assert ent.hasAttr(ALLOCATED_ATTR)
  344. assert ent.getValue(ALLOCATED_ATTR) == str(20)
  345. topology.standalone.log.debug('%s.%s=%s' % (STAGED_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  346. topology.standalone.delete_s(STAGED_USER1_DN)
  347. def test_ticket47828_run_16(topology):
  348. """
  349. Provisioning/Dummy excluded scope: Add an dummy entry and check its ALLOCATED_ATTR is not set
  350. """
  351. _header(topology, 'Provisioning/Dummy excluded scope: Add an dummy entry and check its ALLOCATED_ATTR not is set')
  352. topology.standalone.add_s(Entry((DUMMY_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  353. 'cn': DUMMY_USER1_CN,
  354. 'sn': DUMMY_USER1_CN,
  355. ALLOCATED_ATTR: str(-1)})))
  356. ent = topology.standalone.getEntry(DUMMY_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  357. assert ent.hasAttr(ALLOCATED_ATTR)
  358. assert ent.getValue(ALLOCATED_ATTR) == str(-1)
  359. topology.standalone.log.debug('%s.%s=%s' % (DUMMY_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  360. topology.standalone.delete_s(DUMMY_USER1_DN)
  361. def test_ticket47828_run_17(topology):
  362. """
  363. Provisioning/Dummy excluded scope: Add an dummy entry and check its ALLOCATED_ATTR is unchanged (!= magic)
  364. """
  365. _header(topology, 'Provisioning/Dummy excluded scope: Add an dummy entry and check its ALLOCATED_ATTR is unchanged (!= magic)')
  366. topology.standalone.add_s(Entry((DUMMY_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  367. 'cn': DUMMY_USER1_CN,
  368. 'sn': DUMMY_USER1_CN,
  369. ALLOCATED_ATTR: str(20)})))
  370. ent = topology.standalone.getEntry(DUMMY_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  371. assert ent.hasAttr(ALLOCATED_ATTR)
  372. assert ent.getValue(ALLOCATED_ATTR) == str(20)
  373. topology.standalone.log.debug('%s.%s=%s' % (DUMMY_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  374. topology.standalone.delete_s(DUMMY_USER1_DN)
  375. def test_ticket47828_run_18(topology):
  376. '''
  377. Exclude PROVISIONING and a wrong container
  378. '''
  379. _header(topology, 'Exclude PROVISIONING and a wrong container')
  380. dn_config = "cn=excluded scope, cn=%s, %s" % (PLUGIN_DNA, DN_PLUGIN)
  381. mod = [(ldap.MOD_REPLACE, 'dnaExcludeScope', PROVISIONING)]
  382. topology.standalone.modify_s(dn_config, mod)
  383. try:
  384. mod = [(ldap.MOD_ADD, 'dnaExcludeScope', "invalidDN,%s" % SUFFIX)]
  385. topology.standalone.modify_s(dn_config, mod)
  386. raise ValueError("invalid dnaExcludeScope value (not a DN)")
  387. except ldap.INVALID_SYNTAX:
  388. pass
  389. def test_ticket47828_run_19(topology):
  390. """
  391. Provisioning+wrong container excluded scope: Add an active entry and check its ALLOCATED_ATTR is set
  392. """
  393. _header(topology, 'Provisioning+wrong container excluded scope: Add an active entry and check its ALLOCATED_ATTR is set')
  394. topology.standalone.add_s(Entry((ACTIVE_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  395. 'cn': ACTIVE_USER1_CN,
  396. 'sn': ACTIVE_USER1_CN,
  397. ALLOCATED_ATTR: str(-1)})))
  398. ent = topology.standalone.getEntry(ACTIVE_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  399. assert ent.hasAttr(ALLOCATED_ATTR)
  400. assert ent.getValue(ALLOCATED_ATTR) != str(-1)
  401. topology.standalone.log.debug('%s.%s=%s' % (ACTIVE_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  402. topology.standalone.delete_s(ACTIVE_USER1_DN)
  403. def test_ticket47828_run_20(topology):
  404. """
  405. Provisioning+wrong container excluded scope: Add an active entry and check its ALLOCATED_ATTR is unchanged (!= magic)
  406. """
  407. _header(topology, 'Provisioning+wrong container excluded scope: Add an active entry and check its ALLOCATED_ATTR is unchanged (!= magic)')
  408. topology.standalone.add_s(Entry((ACTIVE_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  409. 'cn': ACTIVE_USER1_CN,
  410. 'sn': ACTIVE_USER1_CN,
  411. ALLOCATED_ATTR: str(20)})))
  412. ent = topology.standalone.getEntry(ACTIVE_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  413. assert ent.hasAttr(ALLOCATED_ATTR)
  414. assert ent.getValue(ALLOCATED_ATTR) == str(20)
  415. topology.standalone.log.debug('%s.%s=%s' % (ACTIVE_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  416. topology.standalone.delete_s(ACTIVE_USER1_DN)
  417. def test_ticket47828_run_21(topology):
  418. """
  419. Provisioning+wrong container excluded scope: Add a staged entry and check its ALLOCATED_ATTR is not set
  420. """
  421. _header(topology, 'Provisioning+wrong container excluded scope: Add a staged entry and check its ALLOCATED_ATTR is not set')
  422. topology.standalone.add_s(Entry((STAGED_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  423. 'cn': STAGED_USER1_CN,
  424. 'sn': STAGED_USER1_CN,
  425. ALLOCATED_ATTR: str(-1)})))
  426. ent = topology.standalone.getEntry(STAGED_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  427. assert ent.hasAttr(ALLOCATED_ATTR)
  428. assert ent.getValue(ALLOCATED_ATTR) == str(-1)
  429. topology.standalone.log.debug('%s.%s=%s' % (STAGED_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  430. topology.standalone.delete_s(STAGED_USER1_DN)
  431. def test_ticket47828_run_22(topology):
  432. """
  433. Provisioning+wrong container excluded scope: Add a staged entry and check its ALLOCATED_ATTR is unchanged (!= magic)
  434. """
  435. _header(topology, 'Provisioning+wrong container excluded scope: Add a staged entry and check its ALLOCATED_ATTR is unchanged (!= magic)')
  436. topology.standalone.add_s(Entry((STAGED_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  437. 'cn': STAGED_USER1_CN,
  438. 'sn': STAGED_USER1_CN,
  439. ALLOCATED_ATTR: str(20)})))
  440. ent = topology.standalone.getEntry(STAGED_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  441. assert ent.hasAttr(ALLOCATED_ATTR)
  442. assert ent.getValue(ALLOCATED_ATTR) == str(20)
  443. topology.standalone.log.debug('%s.%s=%s' % (STAGED_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  444. topology.standalone.delete_s(STAGED_USER1_DN)
  445. def test_ticket47828_run_23(topology):
  446. """
  447. Provisioning+wrong container excluded scope: Add an dummy entry and check its ALLOCATED_ATTR is set
  448. """
  449. _header(topology, 'Provisioning+wrong container excluded scope: Add an dummy entry and check its ALLOCATED_ATTR is set')
  450. topology.standalone.add_s(Entry((DUMMY_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  451. 'cn': DUMMY_USER1_CN,
  452. 'sn': DUMMY_USER1_CN,
  453. ALLOCATED_ATTR: str(-1)})))
  454. ent = topology.standalone.getEntry(DUMMY_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  455. assert ent.hasAttr(ALLOCATED_ATTR)
  456. assert ent.getValue(ALLOCATED_ATTR) != str(-1)
  457. topology.standalone.log.debug('%s.%s=%s' % (DUMMY_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  458. topology.standalone.delete_s(DUMMY_USER1_DN)
  459. def test_ticket47828_run_24(topology):
  460. """
  461. Provisioning+wrong container excluded scope: Add an dummy entry and check its ALLOCATED_ATTR is unchanged (!= magic)
  462. """
  463. _header(topology, 'Provisioning+wrong container excluded scope: Add an dummy entry and check its ALLOCATED_ATTR is unchanged (!= magic)')
  464. topology.standalone.add_s(Entry((DUMMY_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  465. 'cn': DUMMY_USER1_CN,
  466. 'sn': DUMMY_USER1_CN,
  467. ALLOCATED_ATTR: str(20)})))
  468. ent = topology.standalone.getEntry(DUMMY_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  469. assert ent.hasAttr(ALLOCATED_ATTR)
  470. assert ent.getValue(ALLOCATED_ATTR) == str(20)
  471. topology.standalone.log.debug('%s.%s=%s' % (DUMMY_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  472. topology.standalone.delete_s(DUMMY_USER1_DN)
  473. def test_ticket47828_run_25(topology):
  474. '''
  475. Exclude a wrong container
  476. '''
  477. _header(topology, 'Exclude a wrong container')
  478. dn_config = "cn=excluded scope, cn=%s, %s" % (PLUGIN_DNA, DN_PLUGIN)
  479. try:
  480. mod = [(ldap.MOD_REPLACE, 'dnaExcludeScope', "invalidDN,%s" % SUFFIX)]
  481. topology.standalone.modify_s(dn_config, mod)
  482. raise ValueError("invalid dnaExcludeScope value (not a DN)")
  483. except ldap.INVALID_SYNTAX:
  484. pass
  485. def test_ticket47828_run_26(topology):
  486. """
  487. Wrong container excluded scope: Add an active entry and check its ALLOCATED_ATTR is set
  488. """
  489. _header(topology, 'Wrong container excluded scope: Add an active entry and check its ALLOCATED_ATTR is set')
  490. topology.standalone.add_s(Entry((ACTIVE_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  491. 'cn': ACTIVE_USER1_CN,
  492. 'sn': ACTIVE_USER1_CN,
  493. ALLOCATED_ATTR: str(-1)})))
  494. ent = topology.standalone.getEntry(ACTIVE_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  495. assert ent.hasAttr(ALLOCATED_ATTR)
  496. assert ent.getValue(ALLOCATED_ATTR) != str(-1)
  497. topology.standalone.log.debug('%s.%s=%s' % (ACTIVE_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  498. topology.standalone.delete_s(ACTIVE_USER1_DN)
  499. def test_ticket47828_run_27(topology):
  500. """
  501. Wrong container excluded scope: Add an active entry and check its ALLOCATED_ATTR is unchanged (!= magic)
  502. """
  503. _header(topology, 'Wrong container excluded scope: Add an active entry and check its ALLOCATED_ATTR is unchanged (!= magic)')
  504. topology.standalone.add_s(Entry((ACTIVE_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  505. 'cn': ACTIVE_USER1_CN,
  506. 'sn': ACTIVE_USER1_CN,
  507. ALLOCATED_ATTR: str(20)})))
  508. ent = topology.standalone.getEntry(ACTIVE_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  509. assert ent.hasAttr(ALLOCATED_ATTR)
  510. assert ent.getValue(ALLOCATED_ATTR) == str(20)
  511. topology.standalone.log.debug('%s.%s=%s' % (ACTIVE_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  512. topology.standalone.delete_s(ACTIVE_USER1_DN)
  513. def test_ticket47828_run_28(topology):
  514. """
  515. Wrong container excluded scope: Add a staged entry and check its ALLOCATED_ATTR is not set
  516. """
  517. _header(topology, 'Wrong container excluded scope: Add a staged entry and check its ALLOCATED_ATTR is not set')
  518. topology.standalone.add_s(Entry((STAGED_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  519. 'cn': STAGED_USER1_CN,
  520. 'sn': STAGED_USER1_CN,
  521. ALLOCATED_ATTR: str(-1)})))
  522. ent = topology.standalone.getEntry(STAGED_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  523. assert ent.hasAttr(ALLOCATED_ATTR)
  524. assert ent.getValue(ALLOCATED_ATTR) == str(-1)
  525. topology.standalone.log.debug('%s.%s=%s' % (STAGED_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  526. topology.standalone.delete_s(STAGED_USER1_DN)
  527. def test_ticket47828_run_29(topology):
  528. """
  529. Wrong container excluded scope: Add a staged entry and check its ALLOCATED_ATTR is unchanged (!= magic)
  530. """
  531. _header(topology, 'Wrong container excluded scope: Add a staged entry and check its ALLOCATED_ATTR is unchanged (!= magic)')
  532. topology.standalone.add_s(Entry((STAGED_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  533. 'cn': STAGED_USER1_CN,
  534. 'sn': STAGED_USER1_CN,
  535. ALLOCATED_ATTR: str(20)})))
  536. ent = topology.standalone.getEntry(STAGED_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  537. assert ent.hasAttr(ALLOCATED_ATTR)
  538. assert ent.getValue(ALLOCATED_ATTR) == str(20)
  539. topology.standalone.log.debug('%s.%s=%s' % (STAGED_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  540. topology.standalone.delete_s(STAGED_USER1_DN)
  541. def test_ticket47828_run_30(topology):
  542. """
  543. Wrong container excluded scope: Add an dummy entry and check its ALLOCATED_ATTR is set
  544. """
  545. _header(topology, 'Wrong container excluded scope: Add an dummy entry and check its ALLOCATED_ATTR is set')
  546. topology.standalone.add_s(Entry((DUMMY_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  547. 'cn': DUMMY_USER1_CN,
  548. 'sn': DUMMY_USER1_CN,
  549. ALLOCATED_ATTR: str(-1)})))
  550. ent = topology.standalone.getEntry(DUMMY_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  551. assert ent.hasAttr(ALLOCATED_ATTR)
  552. assert ent.getValue(ALLOCATED_ATTR) != str(-1)
  553. topology.standalone.log.debug('%s.%s=%s' % (DUMMY_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  554. topology.standalone.delete_s(DUMMY_USER1_DN)
  555. def test_ticket47828_run_31(topology):
  556. """
  557. Wrong container excluded scope: Add an dummy entry and check its ALLOCATED_ATTR is unchanged (!= magic)
  558. """
  559. _header(topology, 'Wrong container excluded scope: Add an dummy entry and check its ALLOCATED_ATTR is unchanged (!= magic)')
  560. topology.standalone.add_s(Entry((DUMMY_USER1_DN, {'objectclass': "top person organizationalPerson inetOrgPerson".split(),
  561. 'cn': DUMMY_USER1_CN,
  562. 'sn': DUMMY_USER1_CN,
  563. ALLOCATED_ATTR: str(20)})))
  564. ent = topology.standalone.getEntry(DUMMY_USER1_DN, ldap.SCOPE_BASE, "(objectclass=*)")
  565. assert ent.hasAttr(ALLOCATED_ATTR)
  566. assert ent.getValue(ALLOCATED_ATTR) == str(20)
  567. topology.standalone.log.debug('%s.%s=%s' % (DUMMY_USER1_CN, ALLOCATED_ATTR, ent.getValue(ALLOCATED_ATTR)))
  568. topology.standalone.delete_s(DUMMY_USER1_DN)
  569. def test_ticket47828_final(topology):
  570. topology.standalone.plugins.disable(name=PLUGIN_DNA)
  571. topology.standalone.stop(timeout=10)
  572. def run_isolated():
  573. '''
  574. run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..)
  575. To run isolated without py.test, you need to
  576. - edit this file and comment '@pytest.fixture' line before 'topology' function.
  577. - set the installation prefix
  578. - run this program
  579. '''
  580. global installation_prefix
  581. installation_prefix = None
  582. topo = topology(True)
  583. test_ticket47828_init(topo)
  584. test_ticket47828_run_0(topo)
  585. test_ticket47828_run_1(topo)
  586. test_ticket47828_run_2(topo)
  587. test_ticket47828_run_3(topo)
  588. test_ticket47828_run_4(topo)
  589. test_ticket47828_run_5(topo)
  590. test_ticket47828_run_6(topo)
  591. test_ticket47828_run_7(topo)
  592. test_ticket47828_run_8(topo)
  593. test_ticket47828_run_9(topo)
  594. test_ticket47828_run_10(topo)
  595. test_ticket47828_run_11(topo)
  596. test_ticket47828_run_12(topo)
  597. test_ticket47828_run_13(topo)
  598. test_ticket47828_run_14(topo)
  599. test_ticket47828_run_15(topo)
  600. test_ticket47828_run_16(topo)
  601. test_ticket47828_run_17(topo)
  602. test_ticket47828_run_18(topo)
  603. test_ticket47828_run_19(topo)
  604. test_ticket47828_run_20(topo)
  605. test_ticket47828_run_21(topo)
  606. test_ticket47828_run_22(topo)
  607. test_ticket47828_run_23(topo)
  608. test_ticket47828_run_24(topo)
  609. test_ticket47828_run_25(topo)
  610. test_ticket47828_run_26(topo)
  611. test_ticket47828_run_27(topo)
  612. test_ticket47828_run_28(topo)
  613. test_ticket47828_run_29(topo)
  614. test_ticket47828_run_30(topo)
  615. test_ticket47828_run_31(topo)
  616. test_ticket47828_final(topo)
  617. if __name__ == '__main__':
  618. run_isolated()