1
0

ticket47828_test.py 34 KB

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