ticket47829_test.py 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  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. installation_prefix = None
  47. class TopologyStandalone(object):
  48. def __init__(self, standalone):
  49. standalone.open()
  50. self.standalone = standalone
  51. @pytest.fixture(scope="module")
  52. def topology(request):
  53. '''
  54. This fixture is used to standalone topology for the 'module'.
  55. '''
  56. global installation_prefix
  57. if installation_prefix:
  58. args_instance[SER_DEPLOYED_DIR] = installation_prefix
  59. standalone = DirSrv(verbose=False)
  60. # Args for the standalone instance
  61. args_instance[SER_HOST] = HOST_STANDALONE
  62. args_instance[SER_PORT] = PORT_STANDALONE
  63. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  64. args_standalone = args_instance.copy()
  65. standalone.allocate(args_standalone)
  66. # Get the status of the instance and restart it if it exists
  67. instance_standalone = standalone.exists()
  68. # Remove the instance
  69. if instance_standalone:
  70. standalone.delete()
  71. # Create the instance
  72. standalone.create()
  73. # Used to retrieve configuration information (dbdir, confdir...)
  74. standalone.open()
  75. def fin():
  76. standalone.delete()
  77. request.addfinalizer(fin)
  78. # Here we have standalone instance up and running
  79. return TopologyStandalone(standalone)
  80. def _header(topology, label):
  81. topology.standalone.log.info("\n\n###############################################")
  82. topology.standalone.log.info("#######")
  83. topology.standalone.log.info("####### %s" % label)
  84. topology.standalone.log.info("#######")
  85. topology.standalone.log.info("###############################################")
  86. def _add_user(topology, type='active'):
  87. if type == 'active':
  88. topology.standalone.add_s(Entry((ACTIVE_USER_DN, {
  89. 'objectclass': "top person inetuser".split(),
  90. 'sn': ACTIVE_USER_CN,
  91. 'cn': ACTIVE_USER_CN})))
  92. elif type == 'stage':
  93. topology.standalone.add_s(Entry((STAGE_USER_DN, {
  94. 'objectclass': "top person inetuser".split(),
  95. 'sn': STAGE_USER_CN,
  96. 'cn': STAGE_USER_CN})))
  97. else:
  98. topology.standalone.add_s(Entry((OUT_USER_DN, {
  99. 'objectclass': "top person inetuser".split(),
  100. 'sn': OUT_USER_CN,
  101. 'cn': OUT_USER_CN})))
  102. def _find_memberof(topology, user_dn=None, group_dn=None, find_result=True):
  103. assert(topology)
  104. assert(user_dn)
  105. assert(group_dn)
  106. ent = topology.standalone.getEntry(user_dn, ldap.SCOPE_BASE, "(objectclass=*)", ['memberof'])
  107. found = False
  108. if ent.hasAttr('memberof'):
  109. for val in ent.getValues('memberof'):
  110. topology.standalone.log.info("!!!!!!! %s: memberof->%s" % (user_dn, val))
  111. if val == group_dn:
  112. found = True
  113. break
  114. if find_result:
  115. assert(found)
  116. else:
  117. assert(not found)
  118. def _find_member(topology, user_dn=None, group_dn=None, find_result=True):
  119. assert(topology)
  120. assert(user_dn)
  121. assert(group_dn)
  122. ent = topology.standalone.getEntry(group_dn, ldap.SCOPE_BASE, "(objectclass=*)", ['member'])
  123. found = False
  124. if ent.hasAttr('member'):
  125. for val in ent.getValues('member'):
  126. topology.standalone.log.info("!!!!!!! %s: member ->%s" % (group_dn, val))
  127. if val == user_dn:
  128. found = True
  129. break
  130. if find_result:
  131. assert(found)
  132. else:
  133. assert(not found)
  134. def _modrdn_entry(topology=None, entry_dn=None, new_rdn=None, del_old=0, new_superior=None):
  135. assert topology is not None
  136. assert entry_dn is not None
  137. assert new_rdn is not None
  138. topology.standalone.log.info("\n\n######################### MODRDN %s ######################\n" % new_rdn)
  139. try:
  140. if new_superior:
  141. topology.standalone.rename_s(entry_dn, new_rdn, newsuperior=new_superior, delold=del_old)
  142. else:
  143. topology.standalone.rename_s(entry_dn, new_rdn, delold=del_old)
  144. except ldap.NO_SUCH_ATTRIBUTE:
  145. topology.standalone.log.info("accepted failure due to 47833: modrdn reports error.. but succeeds")
  146. attempt = 0
  147. if new_superior:
  148. dn = "%s,%s" % (new_rdn, new_superior)
  149. base = new_superior
  150. else:
  151. base = ','.join(entry_dn.split(",")[1:])
  152. dn = "%s, %s" % (new_rdn, base)
  153. myfilter = entry_dn.split(',')[0]
  154. while attempt < 10:
  155. try:
  156. ent = topology.standalone.getEntry(dn, ldap.SCOPE_BASE, myfilter)
  157. break
  158. except ldap.NO_SUCH_OBJECT:
  159. topology.standalone.log.info("Accept failure due to 47833: unable to find (base) a modrdn entry")
  160. attempt += 1
  161. time.sleep(1)
  162. if attempt == 10:
  163. ent = topology.standalone.getEntry(base, ldap.SCOPE_SUBTREE, myfilter)
  164. ent = topology.standalone.getEntry(dn, ldap.SCOPE_BASE, myfilter)
  165. def _check_memberof(topology=None, action=None, user_dn=None, group_dn=None, find_result=None):
  166. assert(topology)
  167. assert(user_dn)
  168. assert(group_dn)
  169. if action == ldap.MOD_ADD:
  170. txt = 'add'
  171. elif action == ldap.MOD_DELETE:
  172. txt = 'delete'
  173. else:
  174. txt = 'replace'
  175. topology.standalone.log.info('\n%s entry %s' % (txt, user_dn))
  176. topology.standalone.log.info('to group %s' % group_dn)
  177. topology.standalone.modify_s(group_dn, [(action, 'member', user_dn)])
  178. time.sleep(1)
  179. _find_memberof(topology, user_dn=user_dn, group_dn=group_dn, find_result=find_result)
  180. def test_ticket47829_init(topology):
  181. topology.standalone.add_s(Entry((SCOPE_IN_DN, {
  182. 'objectclass': "top nscontainer".split(),
  183. 'cn': SCOPE_IN_DN})))
  184. topology.standalone.add_s(Entry((SCOPE_OUT_DN, {
  185. 'objectclass': "top nscontainer".split(),
  186. 'cn': SCOPE_OUT_DN})))
  187. topology.standalone.add_s(Entry((PROVISIONING_DN, {
  188. 'objectclass': "top nscontainer".split(),
  189. 'cn': PROVISIONING_CN})))
  190. topology.standalone.add_s(Entry((ACTIVE_DN, {
  191. 'objectclass': "top nscontainer".split(),
  192. 'cn': ACTIVE_CN})))
  193. topology.standalone.add_s(Entry((STAGE_DN, {
  194. 'objectclass': "top nscontainer".split(),
  195. 'cn': STAGE_DN})))
  196. topology.standalone.add_s(Entry((DELETE_DN, {
  197. 'objectclass': "top nscontainer".split(),
  198. 'cn': DELETE_CN})))
  199. # add groups
  200. topology.standalone.add_s(Entry((ACTIVE_GROUP_DN, {
  201. 'objectclass': "top groupOfNames inetuser".split(),
  202. 'cn': ACTIVE_GROUP_CN})))
  203. topology.standalone.add_s(Entry((STAGE_GROUP_DN, {
  204. 'objectclass': "top groupOfNames inetuser".split(),
  205. 'cn': STAGE_GROUP_CN})))
  206. topology.standalone.add_s(Entry((OUT_GROUP_DN, {
  207. 'objectclass': "top groupOfNames inetuser".split(),
  208. 'cn': OUT_GROUP_CN})))
  209. topology.standalone.add_s(Entry((INDIRECT_ACTIVE_GROUP_DN, {
  210. 'objectclass': "top groupOfNames".split(),
  211. 'cn': INDIRECT_ACTIVE_GROUP_CN})))
  212. # add users
  213. _add_user(topology, 'active')
  214. _add_user(topology, 'stage')
  215. _add_user(topology, 'out')
  216. # enable memberof of with scope IN except provisioning
  217. topology.standalone.plugins.enable(name=PLUGIN_MEMBER_OF)
  218. dn = "cn=%s,%s" % (PLUGIN_MEMBER_OF, DN_PLUGIN)
  219. topology.standalone.modify_s(dn, [(ldap.MOD_REPLACE, 'memberOfEntryScope', SCOPE_IN_DN)])
  220. topology.standalone.modify_s(dn, [(ldap.MOD_REPLACE, 'memberOfEntryScopeExcludeSubtree', PROVISIONING_DN)])
  221. # enable RI with scope IN except provisioning
  222. topology.standalone.plugins.enable(name=PLUGIN_REFER_INTEGRITY)
  223. dn = "cn=%s,%s" % (PLUGIN_REFER_INTEGRITY, DN_PLUGIN)
  224. topology.standalone.modify_s(dn, [(ldap.MOD_REPLACE, 'nsslapd-pluginentryscope', SCOPE_IN_DN)])
  225. topology.standalone.modify_s(dn, [(ldap.MOD_REPLACE, 'nsslapd-plugincontainerscope', SCOPE_IN_DN)])
  226. topology.standalone.modify_s(dn, [(ldap.MOD_REPLACE, 'nsslapd-pluginExcludeEntryScope', PROVISIONING_DN)])
  227. topology.standalone.restart(timeout=10)
  228. def test_ticket47829_mod_active_user_1(topology):
  229. _header(topology, 'MOD: add an active user to an active group')
  230. # add active user to active group
  231. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  232. _find_member(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  233. # remove active user to active group
  234. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  235. def test_ticket47829_mod_active_user_2(topology):
  236. _header(topology, 'MOD: add an Active user to a Stage group')
  237. # add active user to stage group
  238. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  239. _find_member(topology, user_dn=ACTIVE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=True)
  240. # remove active user to stage group
  241. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=ACTIVE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  242. def test_ticket47829_mod_active_user_3(topology):
  243. _header(topology, 'MOD: add an Active user to a out of scope group')
  244. # add active user to out of scope group
  245. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  246. _find_member(topology, user_dn=ACTIVE_USER_DN, group_dn=OUT_GROUP_DN, find_result=True)
  247. # remove active user to out of scope group
  248. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=ACTIVE_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  249. def test_ticket47829_mod_stage_user_1(topology):
  250. _header(topology, 'MOD: add an Stage user to a Active group')
  251. # add stage user to active group
  252. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  253. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  254. # remove stage user to active group
  255. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  256. def test_ticket47829_mod_stage_user_2(topology):
  257. _header(topology, 'MOD: add an Stage user to a Stage group')
  258. # add stage user to stage group
  259. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=STAGE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  260. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=True)
  261. # remove stage user to stage group
  262. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=STAGE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  263. def test_ticket47829_mod_stage_user_3(topology):
  264. _header(topology, 'MOD: add an Stage user to a out of scope group')
  265. # add stage user to an out of scope group
  266. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=STAGE_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  267. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=OUT_GROUP_DN, find_result=True)
  268. # remove stage user to out of scope group
  269. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=STAGE_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  270. def test_ticket47829_mod_out_user_1(topology):
  271. _header(topology, 'MOD: add an out of scope user to an active group')
  272. # add out of scope user to active group
  273. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=OUT_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  274. _find_member(topology, user_dn=OUT_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  275. # remove out of scope user to active group
  276. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=OUT_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  277. def test_ticket47829_mod_out_user_2(topology):
  278. _header(topology, 'MOD: add an out of scope user to a Stage group')
  279. # add out of scope user to stage group
  280. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=OUT_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  281. _find_member(topology, user_dn=OUT_USER_DN, group_dn=STAGE_GROUP_DN, find_result=True)
  282. # remove out of scope user to stage group
  283. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=OUT_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  284. def test_ticket47829_mod_out_user_3(topology):
  285. _header(topology, 'MOD: add an out of scope user to an out of scope group')
  286. # add out of scope user to stage group
  287. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=OUT_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  288. _find_member(topology, user_dn=OUT_USER_DN, group_dn=OUT_GROUP_DN, find_result=True)
  289. # remove out of scope user to stage group
  290. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=OUT_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  291. def test_ticket47829_mod_active_user_modrdn_active_user_1(topology):
  292. _header(topology, 'add an Active user to a Active group. Then move Active user to Active')
  293. # add Active user to active group
  294. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  295. _find_member(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  296. # move the Active entry to active, expect 'member' and 'memberof'
  297. _modrdn_entry(topology, entry_dn=ACTIVE_USER_DN, new_rdn="cn=x%s" % ACTIVE_USER_CN, new_superior=ACTIVE_DN)
  298. _find_memberof(topology, user_dn="cn=x%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  299. _find_member(topology, user_dn="cn=x%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  300. # move the Active entry to active, expect 'member' and no 'memberof'
  301. _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)
  302. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  303. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  304. # remove active user to active group
  305. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  306. def test_ticket47829_mod_active_user_modrdn_stage_user_1(topology):
  307. _header(topology, 'add an Active user to a Active group. Then move Active user to Stage')
  308. # add Active user to active group
  309. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  310. _find_member(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  311. # move the Active entry to stage, expect no 'member' and 'memberof'
  312. _modrdn_entry(topology, entry_dn=ACTIVE_USER_DN, new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=STAGE_DN)
  313. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  314. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  315. # move the Active entry to Stage, expect 'member' and no 'memberof'
  316. _modrdn_entry(topology, entry_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=ACTIVE_DN)
  317. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  318. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  319. def test_ticket47829_mod_active_user_modrdn_out_user_1(topology):
  320. _header(topology, 'add an Active user to a Active group. Then move Active user to out of scope')
  321. # add Active user to active group
  322. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  323. _find_member(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  324. # move the Active entry to out of scope, expect no 'member' and no 'memberof'
  325. _modrdn_entry(topology, entry_dn=ACTIVE_USER_DN, new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=OUT_GROUP_DN)
  326. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, OUT_GROUP_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  327. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, OUT_GROUP_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  328. # move the Active entry to out of scope, expect no 'member' and no 'memberof'
  329. _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)
  330. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  331. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  332. def test_ticket47829_mod_modrdn_1(topology):
  333. _header(topology, 'add an Stage user to a Active group. Then move Stage user to Active')
  334. # add Stage user to active group
  335. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  336. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  337. # move the Stage entry to active, expect 'member' and 'memberof'
  338. _modrdn_entry(topology, entry_dn=STAGE_USER_DN, new_rdn="cn=%s" % STAGE_USER_CN, new_superior=ACTIVE_DN)
  339. _find_memberof(topology, user_dn="cn=%s,%s" % (STAGE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  340. _find_member(topology, user_dn="cn=%s,%s" % (STAGE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  341. # move the Active entry to Stage, expect no 'member' and no 'memberof'
  342. _modrdn_entry(topology, entry_dn="cn=%s,%s" % (STAGE_USER_CN, ACTIVE_DN), new_rdn="cn=%s" % STAGE_USER_CN, new_superior=STAGE_DN)
  343. _find_memberof(topology, user_dn="cn=%s,%s" % (STAGE_USER_CN, STAGE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  344. _find_member(topology, user_dn="cn=%s,%s" % (STAGE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  345. def test_ticket47829_mod_stage_user_modrdn_active_user_1(topology):
  346. _header(topology, 'add an Stage user to a Active group. Then move Stage user to Active')
  347. stage_user_dn = STAGE_USER_DN
  348. stage_user_rdn = "cn=%s" % STAGE_USER_CN
  349. active_user_dn = "cn=%s,%s" % (STAGE_USER_CN, ACTIVE_DN)
  350. # add Stage user to active group
  351. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  352. _find_member(topology, 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, entry_dn=stage_user_dn, new_rdn=stage_user_rdn, new_superior=ACTIVE_DN)
  355. _find_memberof(topology, user_dn=active_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  356. _find_member(topology, 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, entry_dn=active_user_dn, new_rdn=stage_user_rdn, new_superior=STAGE_DN)
  359. _find_memberof(topology, user_dn=stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  360. _find_member(topology, 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):
  362. _header(topology, 'add an Stage user to a Active group. Then move Stage user to Stage')
  363. _header(topology, '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, action=ldap.MOD_ADD, user_dn=old_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  371. _find_member(topology, user_dn=old_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  372. # move the Stage entry to Stage, expect no 'member' and 'memberof'
  373. _modrdn_entry(topology, entry_dn=old_stage_user_dn, new_rdn=new_stage_user_rdn, new_superior=STAGE_DN)
  374. _find_memberof(topology, user_dn=new_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  375. _find_member(topology, user_dn=new_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  376. # move the Stage entry to Stage, expect no 'member' and no 'memberof'
  377. _modrdn_entry(topology, entry_dn=new_stage_user_dn, new_rdn=old_stage_user_rdn, new_superior=STAGE_DN)
  378. _find_memberof(topology, user_dn=old_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  379. _find_member(topology, user_dn=old_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  380. def test_ticket47829_indirect_active_group_1(topology):
  381. _header(topology, 'add an Active group (G1) to an active group (G0). Then add active user to G1')
  382. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_ADD, 'member', ACTIVE_GROUP_DN)])
  383. # add an active user to G1. Checks that user is memberof G1
  384. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  385. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=True)
  386. # remove G1 from G0
  387. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_DELETE, 'member', ACTIVE_GROUP_DN)])
  388. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  389. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  390. # remove active user from G1
  391. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  392. def test_ticket47829_indirect_active_group_2(topology):
  393. _header(topology, 'add an Active group (G1) to an active group (G0). Then add active user to G1. Then move active user to stage')
  394. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_ADD, 'member', ACTIVE_GROUP_DN)])
  395. # add an active user to G1. Checks that user is memberof G1
  396. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  397. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=True)
  398. # remove G1 from G0
  399. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_DELETE, 'member', ACTIVE_GROUP_DN)])
  400. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  401. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  402. # move active user to stage
  403. _modrdn_entry(topology, entry_dn=ACTIVE_USER_DN, new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=STAGE_DN)
  404. # stage user is no long member of active group and indirect active group
  405. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  406. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  407. # active group and indirect active group do no longer have stage user as member
  408. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  409. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  410. # return back the entry to active. It remains not member
  411. _modrdn_entry(topology, entry_dn="cn=%s,%s" % (ACTIVE_USER_CN, STAGE_DN), new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=ACTIVE_DN)
  412. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  413. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  414. def test_ticket47829_indirect_active_group_3(topology):
  415. _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')
  416. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_ADD, 'member', ACTIVE_GROUP_DN)])
  417. # add an active user to G1. Checks that user is memberof G1
  418. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  419. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=True)
  420. # remove G1 from G0
  421. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_DELETE, 'member', ACTIVE_GROUP_DN)])
  422. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  423. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  424. # move active user to out of the scope
  425. _modrdn_entry(topology, entry_dn=ACTIVE_USER_DN, new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=SCOPE_OUT_DN)
  426. # stage user is no long member of active group and indirect active group
  427. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, SCOPE_OUT_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  428. _find_memberof(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, SCOPE_OUT_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  429. # active group and indirect active group do no longer have stage user as member
  430. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, SCOPE_OUT_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  431. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, SCOPE_OUT_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  432. # return back the entry to active. It remains not member
  433. _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)
  434. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  435. _find_member(topology, user_dn="cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  436. def test_ticket47829_indirect_active_group_4(topology):
  437. _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')
  438. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_ADD, 'member', ACTIVE_GROUP_DN)])
  439. # add stage user to active group
  440. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  441. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  442. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  443. _find_memberof(topology, user_dn=STAGE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  444. _find_memberof(topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  445. # move stage user to active
  446. _modrdn_entry(topology, entry_dn=STAGE_USER_DN, new_rdn="cn=%s" % STAGE_USER_CN, new_superior=ACTIVE_DN)
  447. renamed_stage_dn = "cn=%s,%s" % (STAGE_USER_CN, ACTIVE_DN)
  448. _find_member(topology, user_dn=renamed_stage_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  449. _find_member(topology, user_dn=renamed_stage_dn, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  450. _find_memberof(topology, user_dn=renamed_stage_dn, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=True)
  451. _find_memberof(topology, user_dn=renamed_stage_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  452. # move back active to stage
  453. _modrdn_entry(topology, entry_dn=renamed_stage_dn, new_rdn="cn=%s" % STAGE_USER_CN, new_superior=STAGE_DN)
  454. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  455. _find_member(topology, user_dn=STAGE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  456. _find_memberof(topology, user_dn=STAGE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  457. _find_memberof(topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  458. def test_ticket47829_final(topology):
  459. log.info('Testcase PASSED')
  460. def run_isolated():
  461. '''
  462. run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..)
  463. To run isolated without py.test, you need to
  464. - edit this file and comment '@pytest.fixture' line before 'topology' function.
  465. - set the installation prefix
  466. - run this program
  467. '''
  468. global installation_prefix
  469. installation_prefix = None
  470. topo = topology(True)
  471. test_ticket47829_init(topo)
  472. test_ticket47829_mod_active_user_1(topo)
  473. test_ticket47829_mod_active_user_2(topo)
  474. test_ticket47829_mod_active_user_3(topo)
  475. test_ticket47829_mod_stage_user_1(topo)
  476. test_ticket47829_mod_stage_user_2(topo)
  477. test_ticket47829_mod_stage_user_3(topo)
  478. test_ticket47829_mod_out_user_1(topo)
  479. test_ticket47829_mod_out_user_2(topo)
  480. test_ticket47829_mod_out_user_3(topo)
  481. test_ticket47829_mod_active_user_modrdn_active_user_1(topo)
  482. test_ticket47829_mod_active_user_modrdn_stage_user_1(topo)
  483. test_ticket47829_mod_active_user_modrdn_out_user_1(topo)
  484. test_ticket47829_mod_stage_user_modrdn_active_user_1(topo)
  485. test_ticket47829_mod_stage_user_modrdn_stage_user_1(topo)
  486. test_ticket47829_indirect_active_group_1(topo)
  487. test_ticket47829_indirect_active_group_2(topo)
  488. test_ticket47829_indirect_active_group_3(topo)
  489. test_ticket47829_indirect_active_group_4(topo)
  490. test_ticket47829_final(topo)
  491. if __name__ == '__main__':
  492. run_isolated()