ticket47828_test.py 36 KB

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