ticket47829_test.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2015 Red Hat, Inc.
  3. # All rights reserved.
  4. #
  5. # License: GPL (version 3 or any later version).
  6. # See LICENSE for details.
  7. # --- END COPYRIGHT BLOCK ---
  8. #
  9. import os
  10. import sys
  11. import time
  12. import ldap
  13. import logging
  14. import pytest
  15. from lib389 import DirSrv, Entry, tools
  16. from lib389.tools import DirSrvTools
  17. from lib389._constants import *
  18. from lib389.properties import *
  19. SCOPE_IN_CN = 'in'
  20. SCOPE_OUT_CN = 'out'
  21. SCOPE_IN_DN = 'cn=%s,%s' % (SCOPE_IN_CN, SUFFIX)
  22. SCOPE_OUT_DN = 'cn=%s,%s' % (SCOPE_OUT_CN, SUFFIX)
  23. PROVISIONING_CN = "provisioning"
  24. PROVISIONING_DN = "cn=%s,%s" % (PROVISIONING_CN, SCOPE_IN_DN)
  25. ACTIVE_CN = "accounts"
  26. STAGE_CN = "staged users"
  27. DELETE_CN = "deleted users"
  28. ACTIVE_DN = "cn=%s,%s" % (ACTIVE_CN, SCOPE_IN_DN)
  29. STAGE_DN = "cn=%s,%s" % (STAGE_CN, PROVISIONING_DN)
  30. DELETE_DN = "cn=%s,%s" % (DELETE_CN, PROVISIONING_DN)
  31. STAGE_USER_CN = "stage guy"
  32. STAGE_USER_DN = "cn=%s,%s" % (STAGE_USER_CN, STAGE_DN)
  33. ACTIVE_USER_CN = "active guy"
  34. ACTIVE_USER_DN = "cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN)
  35. OUT_USER_CN = "out guy"
  36. OUT_USER_DN = "cn=%s,%s" % (OUT_USER_CN, SCOPE_OUT_DN)
  37. STAGE_GROUP_CN = "stage group"
  38. STAGE_GROUP_DN = "cn=%s,%s" % (STAGE_GROUP_CN, STAGE_DN)
  39. ACTIVE_GROUP_CN = "active group"
  40. ACTIVE_GROUP_DN = "cn=%s,%s" % (ACTIVE_GROUP_CN, ACTIVE_DN)
  41. OUT_GROUP_CN = "out group"
  42. OUT_GROUP_DN = "cn=%s,%s" % (OUT_GROUP_CN, SCOPE_OUT_DN)
  43. INDIRECT_ACTIVE_GROUP_CN = "indirect active group"
  44. INDIRECT_ACTIVE_GROUP_DN = "cn=%s,%s" % (INDIRECT_ACTIVE_GROUP_CN, ACTIVE_DN)
  45. log = logging.getLogger(__name__)
  46. class TopologyStandalone(object):
  47. def __init__(self, standalone):
  48. standalone.open()
  49. self.standalone = standalone
  50. @pytest.fixture(scope="module")
  51. def topology(request):
  52. '''
  53. This fixture is used to standalone topology for the 'module'.
  54. '''
  55. standalone = DirSrv(verbose=False)
  56. # Args for the standalone instance
  57. args_instance[SER_HOST] = HOST_STANDALONE
  58. args_instance[SER_PORT] = PORT_STANDALONE
  59. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  60. args_standalone = args_instance.copy()
  61. standalone.allocate(args_standalone)
  62. # Get the status of the instance and restart it if it exists
  63. instance_standalone = standalone.exists()
  64. # Remove the instance
  65. if instance_standalone:
  66. standalone.delete()
  67. # Create the instance
  68. standalone.create()
  69. # Used to retrieve configuration information (dbdir, confdir...)
  70. standalone.open()
  71. def fin():
  72. standalone.delete()
  73. request.addfinalizer(fin)
  74. # Here we have standalone instance up and running
  75. return TopologyStandalone(standalone)
  76. def _header(topology, label):
  77. topology.standalone.log.info("\n\n###############################################")
  78. topology.standalone.log.info("#######")
  79. topology.standalone.log.info("####### %s" % label)
  80. topology.standalone.log.info("#######")
  81. topology.standalone.log.info("###############################################")
  82. def _add_user(topology, type='active'):
  83. if type == 'active':
  84. topology.standalone.add_s(Entry((ACTIVE_USER_DN, {
  85. 'objectclass': "top person inetuser".split(),
  86. 'sn': ACTIVE_USER_CN,
  87. 'cn': ACTIVE_USER_CN})))
  88. elif type == 'stage':
  89. topology.standalone.add_s(Entry((STAGE_USER_DN, {
  90. 'objectclass': "top person inetuser".split(),
  91. 'sn': STAGE_USER_CN,
  92. 'cn': STAGE_USER_CN})))
  93. else:
  94. topology.standalone.add_s(Entry((OUT_USER_DN, {
  95. 'objectclass': "top person inetuser".split(),
  96. 'sn': OUT_USER_CN,
  97. 'cn': OUT_USER_CN})))
  98. def _find_memberof(topology, user_dn=None, group_dn=None, find_result=True):
  99. assert(topology)
  100. assert(user_dn)
  101. assert(group_dn)
  102. ent = topology.standalone.getEntry(user_dn, ldap.SCOPE_BASE, "(objectclass=*)", ['memberof'])
  103. found = False
  104. if ent.hasAttr('memberof'):
  105. for val in ent.getValues('memberof'):
  106. topology.standalone.log.info("!!!!!!! %s: memberof->%s" % (user_dn, val))
  107. if val == group_dn:
  108. found = True
  109. break
  110. if find_result:
  111. assert(found)
  112. else:
  113. assert(not found)
  114. def _find_member(topology, user_dn=None, group_dn=None, find_result=True):
  115. assert(topology)
  116. assert(user_dn)
  117. assert(group_dn)
  118. ent = topology.standalone.getEntry(group_dn, ldap.SCOPE_BASE, "(objectclass=*)", ['member'])
  119. found = False
  120. if ent.hasAttr('member'):
  121. for val in ent.getValues('member'):
  122. topology.standalone.log.info("!!!!!!! %s: member ->%s" % (group_dn, val))
  123. if val == user_dn:
  124. found = True
  125. break
  126. if find_result:
  127. assert(found)
  128. else:
  129. assert(not found)
  130. def _modrdn_entry(topology=None, entry_dn=None, new_rdn=None, del_old=0, new_superior=None):
  131. assert topology is not None
  132. assert entry_dn is not None
  133. assert new_rdn is not None
  134. topology.standalone.log.info("\n\n######################### MODRDN %s ######################\n" % new_rdn)
  135. try:
  136. if new_superior:
  137. topology.standalone.rename_s(entry_dn, new_rdn, newsuperior=new_superior, delold=del_old)
  138. else:
  139. topology.standalone.rename_s(entry_dn, new_rdn, delold=del_old)
  140. except ldap.NO_SUCH_ATTRIBUTE:
  141. topology.standalone.log.info("accepted failure due to 47833: modrdn reports error.. but succeeds")
  142. attempt = 0
  143. if new_superior:
  144. dn = "%s,%s" % (new_rdn, new_superior)
  145. base = new_superior
  146. else:
  147. base = ','.join(entry_dn.split(",")[1:])
  148. dn = "%s, %s" % (new_rdn, base)
  149. myfilter = entry_dn.split(',')[0]
  150. while attempt < 10:
  151. try:
  152. ent = topology.standalone.getEntry(dn, ldap.SCOPE_BASE, myfilter)
  153. break
  154. except ldap.NO_SUCH_OBJECT:
  155. topology.standalone.log.info("Accept failure due to 47833: unable to find (base) a modrdn entry")
  156. attempt += 1
  157. time.sleep(1)
  158. if attempt == 10:
  159. ent = topology.standalone.getEntry(base, ldap.SCOPE_SUBTREE, myfilter)
  160. ent = topology.standalone.getEntry(dn, ldap.SCOPE_BASE, myfilter)
  161. def _check_memberof(topology=None, action=None, user_dn=None, group_dn=None, find_result=None):
  162. assert(topology)
  163. assert(user_dn)
  164. assert(group_dn)
  165. if action == ldap.MOD_ADD:
  166. txt = 'add'
  167. elif action == ldap.MOD_DELETE:
  168. txt = 'delete'
  169. else:
  170. txt = 'replace'
  171. topology.standalone.log.info('\n%s entry %s' % (txt, user_dn))
  172. topology.standalone.log.info('to group %s' % group_dn)
  173. topology.standalone.modify_s(group_dn, [(action, 'member', user_dn)])
  174. time.sleep(1)
  175. _find_memberof(topology, user_dn=user_dn, group_dn=group_dn, find_result=find_result)
  176. def test_ticket47829_init(topology):
  177. topology.standalone.add_s(Entry((SCOPE_IN_DN, {
  178. 'objectclass': "top nscontainer".split(),
  179. 'cn': SCOPE_IN_DN})))
  180. topology.standalone.add_s(Entry((SCOPE_OUT_DN, {
  181. 'objectclass': "top nscontainer".split(),
  182. 'cn': SCOPE_OUT_DN})))
  183. topology.standalone.add_s(Entry((PROVISIONING_DN, {
  184. 'objectclass': "top nscontainer".split(),
  185. 'cn': PROVISIONING_CN})))
  186. topology.standalone.add_s(Entry((ACTIVE_DN, {
  187. 'objectclass': "top nscontainer".split(),
  188. 'cn': ACTIVE_CN})))
  189. topology.standalone.add_s(Entry((STAGE_DN, {
  190. 'objectclass': "top nscontainer".split(),
  191. 'cn': STAGE_DN})))
  192. topology.standalone.add_s(Entry((DELETE_DN, {
  193. 'objectclass': "top nscontainer".split(),
  194. 'cn': DELETE_CN})))
  195. # add groups
  196. topology.standalone.add_s(Entry((ACTIVE_GROUP_DN, {
  197. 'objectclass': "top groupOfNames inetuser".split(),
  198. 'cn': ACTIVE_GROUP_CN})))
  199. topology.standalone.add_s(Entry((STAGE_GROUP_DN, {
  200. 'objectclass': "top groupOfNames inetuser".split(),
  201. 'cn': STAGE_GROUP_CN})))
  202. topology.standalone.add_s(Entry((OUT_GROUP_DN, {
  203. 'objectclass': "top groupOfNames inetuser".split(),
  204. 'cn': OUT_GROUP_CN})))
  205. topology.standalone.add_s(Entry((INDIRECT_ACTIVE_GROUP_DN, {
  206. 'objectclass': "top groupOfNames".split(),
  207. 'cn': INDIRECT_ACTIVE_GROUP_CN})))
  208. # add users
  209. _add_user(topology, 'active')
  210. _add_user(topology, 'stage')
  211. _add_user(topology, 'out')
  212. # enable memberof of with scope IN except provisioning
  213. topology.standalone.plugins.enable(name=PLUGIN_MEMBER_OF)
  214. dn = "cn=%s,%s" % (PLUGIN_MEMBER_OF, DN_PLUGIN)
  215. topology.standalone.modify_s(dn, [(ldap.MOD_REPLACE, 'memberOfEntryScope', SCOPE_IN_DN)])
  216. topology.standalone.modify_s(dn, [(ldap.MOD_REPLACE, 'memberOfEntryScopeExcludeSubtree', PROVISIONING_DN)])
  217. # enable RI with scope IN except provisioning
  218. topology.standalone.plugins.enable(name=PLUGIN_REFER_INTEGRITY)
  219. dn = "cn=%s,%s" % (PLUGIN_REFER_INTEGRITY, DN_PLUGIN)
  220. topology.standalone.modify_s(dn, [(ldap.MOD_REPLACE, 'nsslapd-pluginentryscope', SCOPE_IN_DN)])
  221. topology.standalone.modify_s(dn, [(ldap.MOD_REPLACE, 'nsslapd-plugincontainerscope', SCOPE_IN_DN)])
  222. topology.standalone.modify_s(dn, [(ldap.MOD_REPLACE, 'nsslapd-pluginExcludeEntryScope', PROVISIONING_DN)])
  223. topology.standalone.restart(timeout=10)
  224. def test_ticket47829_mod_active_user_1(topology):
  225. _header(topology, 'MOD: add an active user to an active group')
  226. # add active user to active group
  227. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  228. _find_member(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  229. # remove active user to active group
  230. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  231. def test_ticket47829_mod_active_user_2(topology):
  232. _header(topology, 'MOD: add an Active user to a Stage group')
  233. # add active user to stage group
  234. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  235. _find_member(topology, user_dn=ACTIVE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=True)
  236. # remove active user to stage group
  237. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=ACTIVE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  238. def test_ticket47829_mod_active_user_3(topology):
  239. _header(topology, 'MOD: add an Active user to a out of scope group')
  240. # add active user to out of scope group
  241. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  242. _find_member(topology, user_dn=ACTIVE_USER_DN, group_dn=OUT_GROUP_DN, find_result=True)
  243. # remove active user to out of scope group
  244. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=ACTIVE_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  245. def test_ticket47829_mod_stage_user_1(topology):
  246. _header(topology, 'MOD: add an Stage user to a Active group')
  247. # add stage user to active group
  248. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  249. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  250. # remove stage user to active group
  251. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  252. def test_ticket47829_mod_stage_user_2(topology):
  253. _header(topology, 'MOD: add an Stage user to a Stage group')
  254. # add stage user to stage group
  255. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=STAGE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  256. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=True)
  257. # remove stage user to stage group
  258. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=STAGE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  259. def test_ticket47829_mod_stage_user_3(topology):
  260. _header(topology, 'MOD: add an Stage user to a out of scope group')
  261. # add stage user to an out of scope group
  262. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=STAGE_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  263. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=OUT_GROUP_DN, find_result=True)
  264. # remove stage user to out of scope group
  265. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=STAGE_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  266. def test_ticket47829_mod_out_user_1(topology):
  267. _header(topology, 'MOD: add an out of scope user to an active group')
  268. # add out of scope user to active group
  269. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=OUT_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  270. _find_member(topology, user_dn=OUT_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  271. # remove out of scope user to active group
  272. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=OUT_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  273. def test_ticket47829_mod_out_user_2(topology):
  274. _header(topology, 'MOD: add an out of scope user to a Stage group')
  275. # add out of scope user to stage group
  276. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=OUT_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  277. _find_member(topology, user_dn=OUT_USER_DN, group_dn=STAGE_GROUP_DN, find_result=True)
  278. # remove out of scope user to stage group
  279. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=OUT_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  280. def test_ticket47829_mod_out_user_3(topology):
  281. _header(topology, 'MOD: add an out of scope user to an out of scope group')
  282. # add out of scope user to stage group
  283. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=OUT_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  284. _find_member(topology, user_dn=OUT_USER_DN, group_dn=OUT_GROUP_DN, find_result=True)
  285. # remove out of scope user to stage group
  286. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=OUT_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  287. def test_ticket47829_mod_active_user_modrdn_active_user_1(topology):
  288. _header(topology, 'add an Active user to a Active group. Then move Active user to Active')
  289. # add Active user to active group
  290. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  291. _find_member(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  292. # move the Active entry to active, expect 'member' and 'memberof'
  293. _modrdn_entry(topology, entry_dn=ACTIVE_USER_DN, new_rdn="cn=x%s" % ACTIVE_USER_CN, new_superior=ACTIVE_DN)
  294. _find_memberof(topology, user_dn="cn=x%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  295. _find_member(topology, user_dn="cn=x%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  296. # move the Active entry to active, expect 'member' and no 'memberof'
  297. _modrdn_entry(topology, entry_dn="cn=x%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=ACTIVE_DN)
  298. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  299. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  300. # remove active user to active group
  301. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  302. def test_ticket47829_mod_active_user_modrdn_stage_user_1(topology):
  303. _header(topology, 'add an Active user to a Active group. Then move Active user to Stage')
  304. # add Active user to active group
  305. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  306. _find_member(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  307. # move the Active entry to stage, expect no 'member' and 'memberof'
  308. _modrdn_entry(topology, entry_dn=ACTIVE_USER_DN, new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=STAGE_DN)
  309. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  310. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  311. # move the Active entry to Stage, expect 'member' and no 'memberof'
  312. _modrdn_entry(topology, entry_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=ACTIVE_DN)
  313. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  314. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  315. def test_ticket47829_mod_active_user_modrdn_out_user_1(topology):
  316. _header(topology, 'add an Active user to a Active group. Then move Active user to out of scope')
  317. # add Active user to active group
  318. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  319. _find_member(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  320. # move the Active entry to out of scope, expect no 'member' and no 'memberof'
  321. _modrdn_entry(topology, entry_dn=ACTIVE_USER_DN, new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=OUT_GROUP_DN)
  322. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, OUT_GROUP_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  323. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, OUT_GROUP_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  324. # move the Active entry to out of scope, expect no 'member' and no 'memberof'
  325. _modrdn_entry(topology, entry_dn="cn=%s,%s" % (ACTIVE_USER_CN, OUT_GROUP_DN), new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=ACTIVE_DN)
  326. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  327. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  328. def test_ticket47829_mod_modrdn_1(topology):
  329. _header(topology, 'add an Stage user to a Active group. Then move Stage user to Active')
  330. # add Stage user to active group
  331. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  332. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  333. # move the Stage entry to active, expect 'member' and 'memberof'
  334. _modrdn_entry(topology, entry_dn=STAGE_USER_DN, new_rdn="cn=%s" % STAGE_USER_CN, new_superior=ACTIVE_DN)
  335. _find_memberof(topology, user_dn="cn=%s,%s" % (STAGE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  336. _find_member(topology, user_dn="cn=%s,%s" % (STAGE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  337. # move the Active entry to Stage, expect no 'member' and no 'memberof'
  338. _modrdn_entry(topology, entry_dn="cn=%s,%s" % (STAGE_USER_CN, ACTIVE_DN), new_rdn="cn=%s" % STAGE_USER_CN, new_superior=STAGE_DN)
  339. _find_memberof(topology, user_dn="cn=%s,%s" % (STAGE_USER_CN, STAGE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  340. _find_member(topology, user_dn="cn=%s,%s" % (STAGE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  341. def test_ticket47829_mod_stage_user_modrdn_active_user_1(topology):
  342. _header(topology, 'add an Stage user to a Active group. Then move Stage user to Active')
  343. stage_user_dn = STAGE_USER_DN
  344. stage_user_rdn = "cn=%s" % STAGE_USER_CN
  345. active_user_dn = "cn=%s,%s" % (STAGE_USER_CN, ACTIVE_DN)
  346. # add Stage user to active group
  347. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  348. _find_member(topology, user_dn=stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  349. # move the Stage entry to Actve, expect 'member' and 'memberof'
  350. _modrdn_entry(topology, entry_dn=stage_user_dn, new_rdn=stage_user_rdn, new_superior=ACTIVE_DN)
  351. _find_memberof(topology, user_dn=active_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  352. _find_member(topology, user_dn=active_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  353. # move the Active entry to Stage, expect no 'member' and no 'memberof'
  354. _modrdn_entry(topology, entry_dn=active_user_dn, new_rdn=stage_user_rdn, new_superior=STAGE_DN)
  355. _find_memberof(topology, user_dn=stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  356. _find_member(topology, user_dn=stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  357. def test_ticket47829_mod_stage_user_modrdn_stage_user_1(topology):
  358. _header(topology, 'add an Stage user to a Active group. Then move Stage user to Stage')
  359. _header(topology, 'Return because it requires a fix for 47833')
  360. return
  361. old_stage_user_dn = STAGE_USER_DN
  362. old_stage_user_rdn = "cn=%s" % STAGE_USER_CN
  363. new_stage_user_rdn = "cn=x%s" % STAGE_USER_CN
  364. new_stage_user_dn = "%s,%s" % (new_stage_user_rdn, STAGE_DN)
  365. # add Stage user to active group
  366. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=old_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  367. _find_member(topology, user_dn=old_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  368. # move the Stage entry to Stage, expect no 'member' and 'memberof'
  369. _modrdn_entry(topology, entry_dn=old_stage_user_dn, new_rdn=new_stage_user_rdn, new_superior=STAGE_DN)
  370. _find_memberof(topology, user_dn=new_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  371. _find_member(topology, user_dn=new_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  372. # move the Stage entry to Stage, expect no 'member' and no 'memberof'
  373. _modrdn_entry(topology, entry_dn=new_stage_user_dn, new_rdn=old_stage_user_rdn, new_superior=STAGE_DN)
  374. _find_memberof(topology, user_dn=old_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  375. _find_member(topology, user_dn=old_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  376. def test_ticket47829_indirect_active_group_1(topology):
  377. _header(topology, 'add an Active group (G1) to an active group (G0). Then add active user to G1')
  378. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_ADD, 'member', ACTIVE_GROUP_DN)])
  379. # add an active user to G1. Checks that user is memberof G1
  380. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  381. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=True)
  382. # remove G1 from G0
  383. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_DELETE, 'member', ACTIVE_GROUP_DN)])
  384. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  385. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  386. # remove active user from G1
  387. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  388. def test_ticket47829_indirect_active_group_2(topology):
  389. _header(topology, 'add an Active group (G1) to an active group (G0). Then add active user to G1. Then move active user to stage')
  390. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_ADD, 'member', ACTIVE_GROUP_DN)])
  391. # add an active user to G1. Checks that user is memberof G1
  392. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  393. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=True)
  394. # remove G1 from G0
  395. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_DELETE, 'member', ACTIVE_GROUP_DN)])
  396. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  397. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  398. # move active user to stage
  399. _modrdn_entry(topology, entry_dn=ACTIVE_USER_DN, new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=STAGE_DN)
  400. # stage user is no long member of active group and indirect active group
  401. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  402. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  403. # active group and indirect active group do no longer have stage user as member
  404. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  405. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  406. # return back the entry to active. It remains not member
  407. _modrdn_entry(topology, entry_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=ACTIVE_DN)
  408. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  409. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  410. def test_ticket47829_indirect_active_group_3(topology):
  411. _header(topology, 'add an Active group (G1) to an active group (G0). Then add active user to G1. Then move active user to out of the scope')
  412. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_ADD, 'member', ACTIVE_GROUP_DN)])
  413. # add an active user to G1. Checks that user is memberof G1
  414. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  415. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=True)
  416. # remove G1 from G0
  417. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_DELETE, 'member', ACTIVE_GROUP_DN)])
  418. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  419. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  420. # move active user to out of the scope
  421. _modrdn_entry(topology, entry_dn=ACTIVE_USER_DN, new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=SCOPE_OUT_DN)
  422. # stage user is no long member of active group and indirect active group
  423. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, SCOPE_OUT_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  424. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, SCOPE_OUT_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  425. # active group and indirect active group do no longer have stage user as member
  426. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, SCOPE_OUT_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  427. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, SCOPE_OUT_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  428. # return back the entry to active. It remains not member
  429. _modrdn_entry(topology, entry_dn="cn=%s,%s" % (ACTIVE_USER_CN, SCOPE_OUT_DN), new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=ACTIVE_DN)
  430. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  431. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  432. def test_ticket47829_indirect_active_group_4(topology):
  433. _header(topology, 'add an Active group (G1) to an active group (G0). Then add stage user to G1. Then move user to active. Then move it back')
  434. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_ADD, 'member', ACTIVE_GROUP_DN)])
  435. # add stage user to active group
  436. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  437. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  438. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  439. _find_memberof(topology, user_dn=STAGE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  440. _find_memberof(topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  441. # move stage user to active
  442. _modrdn_entry(topology, entry_dn=STAGE_USER_DN, new_rdn="cn=%s" % STAGE_USER_CN, new_superior=ACTIVE_DN)
  443. renamed_stage_dn = "cn=%s,%s" % (STAGE_USER_CN, ACTIVE_DN)
  444. _find_member(topology, user_dn=renamed_stage_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  445. _find_member(topology, user_dn=renamed_stage_dn, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  446. _find_memberof(topology, user_dn=renamed_stage_dn, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=True)
  447. _find_memberof(topology, user_dn=renamed_stage_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  448. # move back active to stage
  449. _modrdn_entry(topology, entry_dn=renamed_stage_dn, new_rdn="cn=%s" % STAGE_USER_CN, new_superior=STAGE_DN)
  450. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  451. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  452. _find_memberof(topology, user_dn=STAGE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  453. _find_memberof(topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  454. if __name__ == '__main__':
  455. # Run isolated
  456. # -s for DEBUG mode
  457. CURRENT_FILE = os.path.realpath(__file__)
  458. pytest.main("-s %s" % CURRENT_FILE)