ticket47829_test.py 30 KB

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