1
0

ticket47829_test.py 34 KB

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