ticket47829_test.py 32 KB

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