ticket47829_test.py 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  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. #
  117. # Here we have standalone instance up and running
  118. # Either coming from a backup recovery
  119. # or from a fresh (re)init
  120. # Time to return the topology
  121. return TopologyStandalone(standalone)
  122. def _header(topology, label):
  123. topology.standalone.log.info("\n\n###############################################")
  124. topology.standalone.log.info("#######")
  125. topology.standalone.log.info("####### %s" % label)
  126. topology.standalone.log.info("#######")
  127. topology.standalone.log.info("###############################################")
  128. def _add_user(topology, type='active'):
  129. if type == 'active':
  130. topology.standalone.add_s(Entry((ACTIVE_USER_DN, {
  131. 'objectclass': "top person inetuser".split(),
  132. 'sn': ACTIVE_USER_CN,
  133. 'cn': ACTIVE_USER_CN})))
  134. elif type == 'stage':
  135. topology.standalone.add_s(Entry((STAGE_USER_DN, {
  136. 'objectclass': "top person inetuser".split(),
  137. 'sn': STAGE_USER_CN,
  138. 'cn': STAGE_USER_CN})))
  139. else:
  140. topology.standalone.add_s(Entry((OUT_USER_DN, {
  141. 'objectclass': "top person inetuser".split(),
  142. 'sn': OUT_USER_CN,
  143. 'cn': OUT_USER_CN})))
  144. def _find_memberof(topology, user_dn=None, group_dn=None, find_result=True):
  145. assert(topology)
  146. assert(user_dn)
  147. assert(group_dn)
  148. ent = topology.standalone.getEntry(user_dn, ldap.SCOPE_BASE, "(objectclass=*)", ['memberof'])
  149. found = False
  150. if ent.hasAttr('memberof'):
  151. for val in ent.getValues('memberof'):
  152. topology.standalone.log.info("!!!!!!! %s: memberof->%s" % (user_dn, val))
  153. if val == group_dn:
  154. found = True
  155. break
  156. if find_result:
  157. assert(found)
  158. else:
  159. assert(not found)
  160. def _find_member(topology, user_dn=None, group_dn=None, find_result=True):
  161. assert(topology)
  162. assert(user_dn)
  163. assert(group_dn)
  164. ent = topology.standalone.getEntry(group_dn, ldap.SCOPE_BASE, "(objectclass=*)", ['member'])
  165. found = False
  166. if ent.hasAttr('member'):
  167. for val in ent.getValues('member'):
  168. topology.standalone.log.info("!!!!!!! %s: member ->%s" % (group_dn, val))
  169. if val == user_dn:
  170. found = True
  171. break
  172. if find_result:
  173. assert(found)
  174. else:
  175. assert(not found)
  176. def _modrdn_entry(topology=None, entry_dn=None, new_rdn=None, del_old=0, new_superior=None):
  177. assert topology != None
  178. assert entry_dn != None
  179. assert new_rdn != None
  180. topology.standalone.log.info("\n\n######################### MODRDN %s ######################\n" % new_rdn)
  181. try:
  182. if new_superior:
  183. topology.standalone.rename_s(entry_dn, new_rdn, newsuperior=new_superior, delold=del_old)
  184. else:
  185. topology.standalone.rename_s(entry_dn, new_rdn, delold=del_old)
  186. except ldap.NO_SUCH_ATTRIBUTE:
  187. topology.standalone.log.info("accepted failure due to 47833: modrdn reports error.. but succeeds")
  188. attempt = 0
  189. if new_superior:
  190. dn = "%s,%s" % (new_rdn, new_superior)
  191. base = new_superior
  192. else:
  193. base = ','.join(entry_dn.split(",")[1:])
  194. dn = "%s, %s" % (new_rdn, base)
  195. filter = entry_dn.split(',')[0]
  196. while attempt < 10:
  197. try:
  198. ent = topology.standalone.getEntry(dn, ldap.SCOPE_BASE, filter)
  199. break
  200. except ldap.NO_SUCH_OBJECT:
  201. topology.standalone.log.info("Accept failure due to 47833: unable to find (base) a modrdn entry")
  202. attempt += 1
  203. time.sleep(1)
  204. if attempt == 10:
  205. ent = topology.standalone.getEntry(base, ldap.SCOPE_SUBTREE, filter)
  206. ent = topology.standalone.getEntry(dn, ldap.SCOPE_BASE, filter)
  207. def _check_memberof(topology=None, action=None, user_dn=None, group_dn=None, find_result=None):
  208. assert(topology)
  209. assert(user_dn)
  210. assert(group_dn)
  211. if action == ldap.MOD_ADD:
  212. txt = 'add'
  213. elif action == ldap.MOD_DELETE:
  214. txt = 'delete'
  215. else:
  216. txt = 'replace'
  217. topology.standalone.log.info('\n%s entry %s' % (txt, user_dn))
  218. topology.standalone.log.info('to group %s' % group_dn)
  219. topology.standalone.modify_s(group_dn, [(action, 'member', user_dn)])
  220. time.sleep(1)
  221. _find_memberof(topology, user_dn=user_dn, group_dn=group_dn, find_result=find_result)
  222. def test_ticket47829_init(topology):
  223. topology.standalone.add_s(Entry((SCOPE_IN_DN, {
  224. 'objectclass': "top nscontainer".split(),
  225. 'cn': SCOPE_IN_DN})))
  226. topology.standalone.add_s(Entry((SCOPE_OUT_DN, {
  227. 'objectclass': "top nscontainer".split(),
  228. 'cn': SCOPE_OUT_DN})))
  229. topology.standalone.add_s(Entry((PROVISIONING_DN, {
  230. 'objectclass': "top nscontainer".split(),
  231. 'cn': PROVISIONING_CN})))
  232. topology.standalone.add_s(Entry((ACTIVE_DN, {
  233. 'objectclass': "top nscontainer".split(),
  234. 'cn': ACTIVE_CN})))
  235. topology.standalone.add_s(Entry((STAGE_DN, {
  236. 'objectclass': "top nscontainer".split(),
  237. 'cn': STAGE_DN})))
  238. topology.standalone.add_s(Entry((DELETE_DN, {
  239. 'objectclass': "top nscontainer".split(),
  240. 'cn': DELETE_CN})))
  241. # add groups
  242. topology.standalone.add_s(Entry((ACTIVE_GROUP_DN, {
  243. 'objectclass': "top groupOfNames inetuser".split(),
  244. 'cn': ACTIVE_GROUP_CN})))
  245. topology.standalone.add_s(Entry((STAGE_GROUP_DN, {
  246. 'objectclass': "top groupOfNames inetuser".split(),
  247. 'cn': STAGE_GROUP_CN})))
  248. topology.standalone.add_s(Entry((OUT_GROUP_DN, {
  249. 'objectclass': "top groupOfNames inetuser".split(),
  250. 'cn': OUT_GROUP_CN})))
  251. topology.standalone.add_s(Entry((INDIRECT_ACTIVE_GROUP_DN, {
  252. 'objectclass': "top groupOfNames".split(),
  253. 'cn': INDIRECT_ACTIVE_GROUP_CN})))
  254. # add users
  255. _add_user(topology, 'active')
  256. _add_user(topology, 'stage')
  257. _add_user(topology, 'out')
  258. # enable memberof of with scope IN except provisioning
  259. topology.standalone.plugins.enable(name=PLUGIN_MEMBER_OF)
  260. dn = "cn=%s,%s" % (PLUGIN_MEMBER_OF, DN_PLUGIN)
  261. topology.standalone.modify_s(dn, [(ldap.MOD_REPLACE, 'memberOfEntryScope', SCOPE_IN_DN)])
  262. topology.standalone.modify_s(dn, [(ldap.MOD_REPLACE, 'memberOfEntryScopeExcludeSubtree', PROVISIONING_DN)])
  263. # enable RI with scope IN except provisioning
  264. topology.standalone.plugins.enable(name=PLUGIN_REFER_INTEGRITY)
  265. dn = "cn=%s,%s" % (PLUGIN_REFER_INTEGRITY, DN_PLUGIN)
  266. topology.standalone.modify_s(dn, [(ldap.MOD_REPLACE, 'nsslapd-pluginentryscope', SCOPE_IN_DN)])
  267. topology.standalone.modify_s(dn, [(ldap.MOD_REPLACE, 'nsslapd-plugincontainerscope', SCOPE_IN_DN)])
  268. topology.standalone.modify_s(dn, [(ldap.MOD_REPLACE, 'nsslapd-pluginExcludeEntryScope', PROVISIONING_DN)])
  269. topology.standalone.restart(timeout=10)
  270. def test_ticket47829_mod_active_user_1(topology):
  271. _header(topology, 'MOD: add an active user to an active group')
  272. # add active user to active group
  273. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  274. _find_member (topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  275. # remove active user to active group
  276. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  277. def test_ticket47829_mod_active_user_2(topology):
  278. _header(topology, 'MOD: add an Active user to a Stage group')
  279. # add active user to stage group
  280. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  281. _find_member (topology, user_dn=ACTIVE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=True)
  282. # remove active user to stage group
  283. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=ACTIVE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  284. def test_ticket47829_mod_active_user_3(topology):
  285. _header(topology, 'MOD: add an Active user to a out of scope group')
  286. # add active user to out of scope group
  287. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  288. _find_member (topology, user_dn=ACTIVE_USER_DN, group_dn=OUT_GROUP_DN, find_result=True)
  289. # remove active user to out of scope group
  290. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=ACTIVE_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  291. def test_ticket47829_mod_stage_user_1(topology):
  292. _header(topology, 'MOD: add an Stage user to a Active group')
  293. # add stage user to active group
  294. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  295. _find_member (topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  296. # remove stage user to active group
  297. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  298. def test_ticket47829_mod_stage_user_2(topology):
  299. _header(topology, 'MOD: add an Stage user to a Stage group')
  300. # add stage user to stage group
  301. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=STAGE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  302. _find_member (topology, user_dn=STAGE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=True)
  303. # remove stage user to stage group
  304. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=STAGE_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  305. def test_ticket47829_mod_stage_user_3(topology):
  306. _header(topology, 'MOD: add an Stage user to a out of scope group')
  307. # add stage user to an out of scope group
  308. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=STAGE_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  309. _find_member (topology, user_dn=STAGE_USER_DN, group_dn=OUT_GROUP_DN, find_result=True)
  310. # remove stage user to out of scope group
  311. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=STAGE_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  312. def test_ticket47829_mod_out_user_1(topology):
  313. _header(topology, 'MOD: add an out of scope user to an active group')
  314. # add out of scope user to active group
  315. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=OUT_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  316. _find_member (topology, user_dn=OUT_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  317. # remove out of scope user to active group
  318. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=OUT_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  319. def test_ticket47829_mod_out_user_2(topology):
  320. _header(topology, 'MOD: add an out of scope user to a Stage group')
  321. # add out of scope user to stage group
  322. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=OUT_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  323. _find_member (topology, user_dn=OUT_USER_DN, group_dn=STAGE_GROUP_DN, find_result=True)
  324. # remove out of scope user to stage group
  325. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=OUT_USER_DN, group_dn=STAGE_GROUP_DN, find_result=False)
  326. def test_ticket47829_mod_out_user_3(topology):
  327. _header(topology, 'MOD: add an out of scope user to an out of scope group')
  328. # add out of scope user to stage group
  329. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=OUT_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  330. _find_member (topology, user_dn=OUT_USER_DN, group_dn=OUT_GROUP_DN, find_result=True)
  331. # remove out of scope user to stage group
  332. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=OUT_USER_DN, group_dn=OUT_GROUP_DN, find_result=False)
  333. def test_ticket47829_mod_active_user_modrdn_active_user_1(topology):
  334. _header(topology, 'add an Active user to a Active group. Then move Active user to Active')
  335. # add Active user to active group
  336. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  337. _find_member (topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  338. # move the Active entry to active, expect 'member' and 'memberof'
  339. _modrdn_entry(topology, entry_dn=ACTIVE_USER_DN, new_rdn="cn=x%s" % ACTIVE_USER_CN, new_superior=ACTIVE_DN)
  340. _find_memberof(topology, user_dn="cn=x%s,%s" %(ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  341. _find_member(topology, user_dn="cn=x%s,%s" %(ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  342. # move the Active entry to active, expect 'member' and no 'memberof'
  343. _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)
  344. _find_memberof(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  345. _find_member(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  346. # remove active user to active group
  347. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  348. def test_ticket47829_mod_active_user_modrdn_stage_user_1(topology):
  349. _header(topology, 'add an Active user to a Active group. Then move Active user to Stage')
  350. # add Active user to active group
  351. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  352. _find_member (topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  353. # move the Active entry to stage, expect no 'member' and 'memberof'
  354. _modrdn_entry(topology, entry_dn=ACTIVE_USER_DN, new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=STAGE_DN)
  355. _find_memberof(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, STAGE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  356. _find_member(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, STAGE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  357. # move the Active entry to Stage, expect 'member' and no 'memberof'
  358. _modrdn_entry(topology, entry_dn="cn=%s,%s" %(ACTIVE_USER_CN, STAGE_DN), new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=ACTIVE_DN)
  359. _find_memberof(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  360. _find_member(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  361. def test_ticket47829_mod_active_user_modrdn_out_user_1(topology):
  362. _header(topology, 'add an Active user to a Active group. Then move Active user to out of scope')
  363. # add Active user to active group
  364. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  365. _find_member (topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  366. # move the Active entry to out of scope, expect no 'member' and no 'memberof'
  367. _modrdn_entry(topology, entry_dn=ACTIVE_USER_DN, new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=OUT_GROUP_DN)
  368. _find_memberof(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, OUT_GROUP_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  369. _find_member(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, OUT_GROUP_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  370. # move the Active entry to out of scope, expect no 'member' and no 'memberof'
  371. _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)
  372. _find_memberof(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  373. _find_member(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  374. def test_ticket47829_mod_modrdn_1(topology):
  375. _header(topology, 'add an Stage user to a Active group. Then move Stage user to Active')
  376. # add Stage user to active group
  377. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  378. _find_member (topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  379. # move the Stage entry to active, expect 'member' and 'memberof'
  380. _modrdn_entry(topology, entry_dn=STAGE_USER_DN, new_rdn="cn=%s" % STAGE_USER_CN, new_superior=ACTIVE_DN)
  381. _find_memberof(topology, user_dn="cn=%s,%s" %(STAGE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  382. _find_member(topology, user_dn="cn=%s,%s" %(STAGE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=True)
  383. # move the Active entry to Stage, expect no 'member' and no 'memberof'
  384. _modrdn_entry(topology, entry_dn="cn=%s,%s" %(STAGE_USER_CN, ACTIVE_DN), new_rdn="cn=%s" % STAGE_USER_CN, new_superior=STAGE_DN)
  385. _find_memberof(topology, user_dn="cn=%s,%s" %(STAGE_USER_CN, STAGE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  386. _find_member(topology, user_dn="cn=%s,%s" %(STAGE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  387. def test_ticket47829_mod_stage_user_modrdn_active_user_1(topology):
  388. _header(topology, 'add an Stage user to a Active group. Then move Stage user to Active')
  389. stage_user_dn = STAGE_USER_DN
  390. stage_user_rdn = "cn=%s" % STAGE_USER_CN
  391. active_user_dn = "cn=%s,%s" % (STAGE_USER_CN, ACTIVE_DN)
  392. # add Stage user to active group
  393. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  394. _find_member (topology, user_dn=stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  395. # move the Stage entry to Actve, expect 'member' and 'memberof'
  396. _modrdn_entry (topology, entry_dn=stage_user_dn, new_rdn=stage_user_rdn, new_superior=ACTIVE_DN)
  397. _find_memberof(topology, user_dn=active_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  398. _find_member (topology, user_dn=active_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  399. # move the Active entry to Stage, expect no 'member' and no 'memberof'
  400. _modrdn_entry (topology, entry_dn=active_user_dn, new_rdn=stage_user_rdn, new_superior=STAGE_DN)
  401. _find_memberof(topology, user_dn=stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  402. _find_member (topology, user_dn=stage_user_dn , group_dn=ACTIVE_GROUP_DN, find_result=False)
  403. def test_ticket47829_mod_stage_user_modrdn_stage_user_1(topology):
  404. _header(topology, 'add an Stage user to a Active group. Then move Stage user to Stage')
  405. _header(topology, 'Return because it requires a fix for 47833')
  406. return
  407. old_stage_user_dn = STAGE_USER_DN
  408. old_stage_user_rdn = "cn=%s" % STAGE_USER_CN
  409. new_stage_user_rdn = "cn=x%s" % STAGE_USER_CN
  410. new_stage_user_dn = "%s,%s" % (new_stage_user_rdn, STAGE_DN)
  411. # add Stage user to active group
  412. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=old_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  413. _find_member (topology, user_dn=old_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  414. # move the Stage entry to Stage, expect no 'member' and 'memberof'
  415. _modrdn_entry (topology, entry_dn=old_stage_user_dn, new_rdn=new_stage_user_rdn, new_superior=STAGE_DN)
  416. _find_memberof(topology, user_dn=new_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  417. _find_member (topology, user_dn=new_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  418. # move the Stage entry to Stage, expect no 'member' and no 'memberof'
  419. _modrdn_entry (topology, entry_dn=new_stage_user_dn, new_rdn=old_stage_user_rdn, new_superior=STAGE_DN)
  420. _find_memberof(topology, user_dn=old_stage_user_dn, group_dn=ACTIVE_GROUP_DN, find_result=False)
  421. _find_member (topology, user_dn=old_stage_user_dn , group_dn=ACTIVE_GROUP_DN, find_result=False)
  422. def test_ticket47829_indirect_active_group_1(topology):
  423. _header(topology, 'add an Active group (G1) to an active group (G0). Then add active user to G1')
  424. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_ADD, 'member', ACTIVE_GROUP_DN)])
  425. # add an active user to G1. Checks that user is memberof G1
  426. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  427. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=True)
  428. # remove G1 from G0
  429. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_DELETE, 'member', ACTIVE_GROUP_DN)])
  430. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  431. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  432. # remove active user from G1
  433. _check_memberof(topology, action=ldap.MOD_DELETE, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  434. def test_ticket47829_indirect_active_group_2(topology):
  435. _header(topology, 'add an Active group (G1) to an active group (G0). Then add active user to G1. Then move active user to stage')
  436. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_ADD, 'member', ACTIVE_GROUP_DN)])
  437. # add an active user to G1. Checks that user is memberof G1
  438. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  439. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=True)
  440. # remove G1 from G0
  441. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_DELETE, 'member', ACTIVE_GROUP_DN)])
  442. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  443. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  444. # move active user to stage
  445. _modrdn_entry(topology, entry_dn=ACTIVE_USER_DN, new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=STAGE_DN)
  446. # stage user is no long member of active group and indirect active group
  447. _find_memberof(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, STAGE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  448. _find_memberof(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, STAGE_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  449. # active group and indirect active group do no longer have stage user as member
  450. _find_member(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, STAGE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  451. _find_member(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, STAGE_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  452. # return back the entry to active. It remains not member
  453. _modrdn_entry(topology, entry_dn="cn=%s,%s" %(ACTIVE_USER_CN, STAGE_DN), new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=ACTIVE_DN)
  454. _find_member(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  455. _find_member(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, ACTIVE_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  456. def test_ticket47829_indirect_active_group_3(topology):
  457. _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')
  458. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_ADD, 'member', ACTIVE_GROUP_DN)])
  459. # add an active user to G1. Checks that user is memberof G1
  460. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  461. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=True)
  462. # remove G1 from G0
  463. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_DELETE, 'member', ACTIVE_GROUP_DN)])
  464. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  465. _find_memberof(topology, user_dn=ACTIVE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  466. # move active user to out of the scope
  467. _modrdn_entry(topology, entry_dn=ACTIVE_USER_DN, new_rdn="cn=%s" % ACTIVE_USER_CN, new_superior=SCOPE_OUT_DN)
  468. # stage user is no long member of active group and indirect active group
  469. _find_memberof(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, SCOPE_OUT_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  470. _find_memberof(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, SCOPE_OUT_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  471. # active group and indirect active group do no longer have stage user as member
  472. _find_member(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, SCOPE_OUT_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  473. _find_member(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, SCOPE_OUT_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  474. # return back the entry to active. It remains not member
  475. _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)
  476. _find_member(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, ACTIVE_DN), group_dn=ACTIVE_GROUP_DN, find_result=False)
  477. _find_member(topology, user_dn="cn=%s,%s" %(ACTIVE_USER_CN, ACTIVE_DN), group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  478. def test_ticket47829_indirect_active_group_4(topology):
  479. _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')
  480. topology.standalone.modify_s(INDIRECT_ACTIVE_GROUP_DN, [(ldap.MOD_ADD, 'member', ACTIVE_GROUP_DN)])
  481. # add stage user to active group
  482. _check_memberof(topology, action=ldap.MOD_ADD, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  483. _find_member (topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=True)
  484. _find_member (topology, user_dn=STAGE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  485. _find_memberof(topology, user_dn=STAGE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  486. _find_memberof(topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  487. # move stage user to active
  488. _modrdn_entry(topology, entry_dn=STAGE_USER_DN, new_rdn="cn=%s" % STAGE_USER_CN, new_superior=ACTIVE_DN)
  489. renamed_stage_dn = "cn=%s,%s" %(STAGE_USER_CN, ACTIVE_DN)
  490. _find_member (topology, user_dn=renamed_stage_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  491. _find_member (topology, user_dn=renamed_stage_dn, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  492. _find_memberof(topology, user_dn=renamed_stage_dn, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=True)
  493. _find_memberof(topology, user_dn=renamed_stage_dn, group_dn=ACTIVE_GROUP_DN, find_result=True)
  494. # move back active to stage
  495. _modrdn_entry(topology, entry_dn=renamed_stage_dn, new_rdn="cn=%s" % STAGE_USER_CN, new_superior=STAGE_DN)
  496. _find_member (topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  497. _find_member (topology, user_dn=STAGE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  498. _find_memberof(topology, user_dn=STAGE_USER_DN, group_dn=INDIRECT_ACTIVE_GROUP_DN, find_result=False)
  499. _find_memberof(topology, user_dn=STAGE_USER_DN, group_dn=ACTIVE_GROUP_DN, find_result=False)
  500. def test_ticket47829_final(topology):
  501. topology.standalone.stop(timeout=10)
  502. def run_isolated():
  503. '''
  504. run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..)
  505. To run isolated without py.test, you need to
  506. - edit this file and comment '@pytest.fixture' line before 'topology' function.
  507. - set the installation prefix
  508. - run this program
  509. '''
  510. global installation_prefix
  511. installation_prefix = None
  512. topo = topology(True)
  513. test_ticket47829_init(topo)
  514. test_ticket47829_mod_active_user_1(topo)
  515. test_ticket47829_mod_active_user_2(topo)
  516. test_ticket47829_mod_active_user_3(topo)
  517. test_ticket47829_mod_stage_user_1(topo)
  518. test_ticket47829_mod_stage_user_2(topo)
  519. test_ticket47829_mod_stage_user_3(topo)
  520. test_ticket47829_mod_out_user_1(topo)
  521. test_ticket47829_mod_out_user_2(topo)
  522. test_ticket47829_mod_out_user_3(topo)
  523. test_ticket47829_mod_active_user_modrdn_active_user_1(topo)
  524. test_ticket47829_mod_active_user_modrdn_stage_user_1(topo)
  525. test_ticket47829_mod_active_user_modrdn_out_user_1(topo)
  526. test_ticket47829_mod_stage_user_modrdn_active_user_1(topo)
  527. test_ticket47829_mod_stage_user_modrdn_stage_user_1(topo)
  528. test_ticket47829_indirect_active_group_1(topo)
  529. test_ticket47829_indirect_active_group_2(topo)
  530. test_ticket47829_indirect_active_group_3(topo)
  531. test_ticket47829_indirect_active_group_4(topo)
  532. test_ticket47829_final(topo)
  533. if __name__ == '__main__':
  534. run_isolated()