ticket47828_test.py 32 KB

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