ticket47553_single_aci_test.py 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. '''
  2. Created on Nov 7, 2013
  3. @author: tbordaz
  4. '''
  5. import os
  6. import sys
  7. import time
  8. import ldap
  9. import logging
  10. import pytest
  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 lib389._constants import REPLICAROLE_MASTER
  16. logging.getLogger(__name__).setLevel(logging.DEBUG)
  17. log = logging.getLogger(__name__)
  18. #
  19. # important part. We can deploy Master1 and Master2 on different versions
  20. #
  21. installation1_prefix = None
  22. installation2_prefix = None
  23. TEST_REPL_DN = "cn=test_repl, %s" % SUFFIX
  24. STAGING_CN = "staged user"
  25. PRODUCTION_CN = "accounts"
  26. EXCEPT_CN = "excepts"
  27. STAGING_DN = "cn=%s,%s" % (STAGING_CN, SUFFIX)
  28. PRODUCTION_DN = "cn=%s,%s" % (PRODUCTION_CN, SUFFIX)
  29. PROD_EXCEPT_DN = "cn=%s,%s" % (EXCEPT_CN, PRODUCTION_DN)
  30. STAGING_PATTERN = "cn=%s*,%s" % (STAGING_CN[:2], SUFFIX)
  31. PRODUCTION_PATTERN = "cn=%s*,%s" % (PRODUCTION_CN[:2], SUFFIX)
  32. BAD_STAGING_PATTERN = "cn=bad*,%s" % (SUFFIX)
  33. BAD_PRODUCTION_PATTERN = "cn=bad*,%s" % (SUFFIX)
  34. BIND_CN = "bind_entry"
  35. BIND_DN = "cn=%s,%s" % (BIND_CN, SUFFIX)
  36. BIND_PW = "password"
  37. NEW_ACCOUNT = "new_account"
  38. MAX_ACCOUNTS = 20
  39. CONFIG_MODDN_ACI_ATTR = "nsslapd-moddn-aci"
  40. class TopologyMaster1Master2(object):
  41. def __init__(self, master1, master2):
  42. master1.open()
  43. self.master1 = master1
  44. master2.open()
  45. self.master2 = master2
  46. @pytest.fixture(scope="module")
  47. def topology(request):
  48. '''
  49. This fixture is used to create a replicated topology for the 'module'.
  50. The replicated topology is MASTER1 <-> Master2.
  51. '''
  52. global installation1_prefix
  53. global installation2_prefix
  54. # allocate master1 on a given deployement
  55. master1 = DirSrv(verbose=False)
  56. if installation1_prefix:
  57. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  58. # Args for the master1 instance
  59. args_instance[SER_HOST] = HOST_MASTER_1
  60. args_instance[SER_PORT] = PORT_MASTER_1
  61. args_instance[SER_SERVERID_PROP] = SERVERID_MASTER_1
  62. args_master = args_instance.copy()
  63. master1.allocate(args_master)
  64. # allocate master1 on a given deployement
  65. master2 = DirSrv(verbose=False)
  66. if installation2_prefix:
  67. args_instance[SER_DEPLOYED_DIR] = installation2_prefix
  68. # Args for the consumer instance
  69. args_instance[SER_HOST] = HOST_MASTER_2
  70. args_instance[SER_PORT] = PORT_MASTER_2
  71. args_instance[SER_SERVERID_PROP] = SERVERID_MASTER_2
  72. args_master = args_instance.copy()
  73. master2.allocate(args_master)
  74. # Get the status of the instance
  75. instance_master1 = master1.exists()
  76. instance_master2 = master2.exists()
  77. # Remove all the instances
  78. if instance_master1:
  79. master1.delete()
  80. if instance_master2:
  81. master2.delete()
  82. # Create the instances
  83. master1.create()
  84. master1.open()
  85. master2.create()
  86. master2.open()
  87. #
  88. # Now prepare the Master-Consumer topology
  89. #
  90. # First Enable replication
  91. master1.replica.enableReplication(suffix=SUFFIX, role=REPLICAROLE_MASTER, replicaId=REPLICAID_MASTER_1)
  92. master2.replica.enableReplication(suffix=SUFFIX, role=REPLICAROLE_MASTER, replicaId=REPLICAID_MASTER_2)
  93. # Initialize the supplier->consumer
  94. properties = {RA_NAME: r'meTo_$host:$port',
  95. RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],
  96. RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],
  97. RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],
  98. RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}
  99. repl_agreement = master1.agreement.create(suffix=SUFFIX, host=master2.host, port=master2.port, properties=properties)
  100. if not repl_agreement:
  101. log.fatal("Fail to create a replica agreement")
  102. sys.exit(1)
  103. log.debug("%s created" % repl_agreement)
  104. properties = {RA_NAME: r'meTo_$host:$port',
  105. RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],
  106. RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],
  107. RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],
  108. RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}
  109. master2.agreement.create(suffix=SUFFIX, host=master1.host, port=master1.port, properties=properties)
  110. master1.agreement.init(SUFFIX, HOST_MASTER_2, PORT_MASTER_2)
  111. master1.waitForReplInit(repl_agreement)
  112. # Check replication is working fine
  113. if master1.testReplication(DEFAULT_SUFFIX, master2):
  114. log.info('Replication is working.')
  115. else:
  116. log.fatal('Replication is not working.')
  117. assert False
  118. # clear the tmp directory
  119. master1.clearTmpDir(__file__)
  120. # Here we have two instances master and consumer
  121. # with replication working.
  122. return TopologyMaster1Master2(master1, master2)
  123. def _bind_manager(topology):
  124. topology.master1.log.info("Bind as %s " % DN_DM)
  125. topology.master1.simple_bind_s(DN_DM, PASSWORD)
  126. def _bind_normal(topology):
  127. # bind as bind_entry
  128. topology.master1.log.info("Bind as %s" % BIND_DN)
  129. topology.master1.simple_bind_s(BIND_DN, BIND_PW)
  130. def _moddn_aci_deny_tree(topology, mod_type=None, target_from=STAGING_DN, target_to=PROD_EXCEPT_DN):
  131. '''
  132. It denies the access moddn_to in cn=except,cn=accounts,SUFFIX
  133. '''
  134. assert mod_type is not None
  135. ACI_TARGET_FROM = ""
  136. ACI_TARGET_TO = ""
  137. if target_from:
  138. ACI_TARGET_FROM = "(target_from = \"ldap:///%s\")" % (target_from)
  139. if target_to:
  140. ACI_TARGET_TO = "(target_to = \"ldap:///%s\")" % (target_to)
  141. ACI_ALLOW = "(version 3.0; acl \"Deny MODDN to prod_except\"; deny (moddn)"
  142. ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
  143. ACI_BODY = ACI_TARGET_TO + ACI_TARGET_FROM + ACI_ALLOW + ACI_SUBJECT
  144. mod = [(mod_type, 'aci', ACI_BODY)]
  145. #topology.master1.modify_s(SUFFIX, mod)
  146. topology.master1.log.info("Add a DENY aci under %s " % PROD_EXCEPT_DN)
  147. topology.master1.modify_s(PROD_EXCEPT_DN, mod)
  148. def _moddn_aci_staging_to_production(topology, mod_type=None, target_from=STAGING_DN, target_to=PRODUCTION_DN):
  149. assert mod_type is not None
  150. ACI_TARGET_FROM = ""
  151. ACI_TARGET_TO = ""
  152. if target_from:
  153. ACI_TARGET_FROM = "(target_from = \"ldap:///%s\")" % (target_from)
  154. if target_to:
  155. ACI_TARGET_TO = "(target_to = \"ldap:///%s\")" % (target_to)
  156. ACI_ALLOW = "(version 3.0; acl \"MODDN from staging to production\"; allow (moddn)"
  157. ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
  158. ACI_BODY = ACI_TARGET_FROM + ACI_TARGET_TO + ACI_ALLOW + ACI_SUBJECT
  159. mod = [(mod_type, 'aci', ACI_BODY)]
  160. topology.master1.modify_s(SUFFIX, mod)
  161. def _moddn_aci_from_production_to_staging(topology, mod_type=None):
  162. assert mod_type is not None
  163. ACI_TARGET = "(target_from = \"ldap:///%s\") (target_to = \"ldap:///%s\")" % (PRODUCTION_DN, STAGING_DN)
  164. ACI_ALLOW = "(version 3.0; acl \"MODDN from production to staging\"; allow (moddn)"
  165. ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
  166. ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
  167. mod = [(mod_type, 'aci', ACI_BODY)]
  168. topology.master1.modify_s(SUFFIX, mod)
  169. def test_ticket47553_init(topology):
  170. """
  171. Creates
  172. - a staging DIT
  173. - a production DIT
  174. - add accounts in staging DIT
  175. - enable ACL logging (commented for performance reason)
  176. """
  177. topology.master1.log.info("\n\n######################### INITIALIZATION ######################\n")
  178. # entry used to bind with
  179. topology.master1.log.info("Add %s" % BIND_DN)
  180. topology.master1.add_s(Entry((BIND_DN, {
  181. 'objectclass': "top person".split(),
  182. 'sn': BIND_CN,
  183. 'cn': BIND_CN,
  184. 'userpassword': BIND_PW})))
  185. # DIT for staging
  186. topology.master1.log.info("Add %s" % STAGING_DN)
  187. topology.master1.add_s(Entry((STAGING_DN, {
  188. 'objectclass': "top organizationalRole".split(),
  189. 'cn': STAGING_CN,
  190. 'description': "staging DIT"})))
  191. # DIT for production
  192. topology.master1.log.info("Add %s" % PRODUCTION_DN)
  193. topology.master1.add_s(Entry((PRODUCTION_DN, {
  194. 'objectclass': "top organizationalRole".split(),
  195. 'cn': PRODUCTION_CN,
  196. 'description': "production DIT"})))
  197. # DIT for production/except
  198. topology.master1.log.info("Add %s" % PROD_EXCEPT_DN)
  199. topology.master1.add_s(Entry((PROD_EXCEPT_DN, {
  200. 'objectclass': "top organizationalRole".split(),
  201. 'cn': EXCEPT_CN,
  202. 'description': "production except DIT"})))
  203. # enable acl error logging
  204. #mod = [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', '128')]
  205. #topology.master1.modify_s(DN_CONFIG, mod)
  206. #topology.master2.modify_s(DN_CONFIG, mod)
  207. # add dummy entries in the staging DIT
  208. for cpt in range(MAX_ACCOUNTS):
  209. name = "%s%d" % (NEW_ACCOUNT, cpt)
  210. topology.master1.add_s(Entry(("cn=%s,%s" % (name, STAGING_DN), {
  211. 'objectclass': "top person".split(),
  212. 'sn': name,
  213. 'cn': name})))
  214. def test_ticket47553_add(topology):
  215. '''
  216. This test case checks that the ADD operation fails (no ADD aci on production)
  217. '''
  218. topology.master1.log.info("\n\n######################### ADD (should fail) ######################\n")
  219. _bind_normal(topology)
  220. #
  221. # First try to add an entry in production => INSUFFICIENT_ACCESS
  222. #
  223. try:
  224. topology.master1.log.info("Try to add %s" % PRODUCTION_DN)
  225. name = "%s%d" % (NEW_ACCOUNT, 0)
  226. topology.master1.add_s(Entry(("cn=%s,%s" % (name, PRODUCTION_DN), {
  227. 'objectclass': "top person".split(),
  228. 'sn': name,
  229. 'cn': name})))
  230. assert 0 # this is an error, we should not be allowed to add an entry in production
  231. except Exception as e:
  232. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  233. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  234. def test_ticket47553_delete(topology):
  235. '''
  236. This test case checks that the DEL operation fails (no 'delete' aci on production)
  237. '''
  238. topology.master1.log.info("\n\n######################### DELETE (should fail) ######################\n")
  239. _bind_normal(topology)
  240. #
  241. # Second try to delete an entry in staging => INSUFFICIENT_ACCESS
  242. #
  243. try:
  244. topology.master1.log.info("Try to delete %s" % STAGING_DN)
  245. name = "%s%d" % (NEW_ACCOUNT, 0)
  246. topology.master1.delete_s("cn=%s,%s" % (name, STAGING_DN))
  247. assert 0 # this is an error, we should not be allowed to add an entry in production
  248. except Exception as e:
  249. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  250. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  251. def test_ticket47553_moddn_staging_prod_0(topology):
  252. '''
  253. This test case MOVE entry NEW_ACCOUNT0 from staging to prod
  254. target_to/target_from: equality filter
  255. '''
  256. topology.master1.log.info("\n\n######################### MOVE staging -> Prod (0) ######################\n")
  257. _bind_normal(topology)
  258. old_rdn = "cn=%s0" % NEW_ACCOUNT
  259. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  260. new_rdn = old_rdn
  261. new_superior = PRODUCTION_DN
  262. #
  263. # Try to rename without the apropriate ACI => INSUFFICIENT_ACCESS
  264. #
  265. try:
  266. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  267. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  268. assert 0
  269. except AssertionError:
  270. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  271. except Exception as e:
  272. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  273. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  274. # successfull MOD with the ACI
  275. topology.master1.log.info("\n\n######################### MOVE to and from equality filter ######################\n")
  276. _bind_manager(topology)
  277. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_ADD, target_from=STAGING_DN, target_to=PRODUCTION_DN)
  278. _bind_normal(topology)
  279. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  280. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  281. # successfull MOD with the both ACI
  282. _bind_manager(topology)
  283. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_DELETE, target_from=STAGING_DN, target_to=PRODUCTION_DN)
  284. _bind_normal(topology)
  285. def test_ticket47553_moddn_staging_prod_1(topology):
  286. '''
  287. This test case MOVE entry NEW_ACCOUNT1 from staging to prod
  288. target_to/target_from: substring/equality filter
  289. '''
  290. topology.master1.log.info("\n\n######################### MOVE staging -> Prod (1) ######################\n")
  291. _bind_normal(topology)
  292. old_rdn = "cn=%s1" % NEW_ACCOUNT
  293. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  294. new_rdn = old_rdn
  295. new_superior = PRODUCTION_DN
  296. #
  297. # Try to rename without the apropriate ACI => INSUFFICIENT_ACCESS
  298. #
  299. try:
  300. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  301. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  302. assert 0
  303. except AssertionError:
  304. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  305. except Exception as e:
  306. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  307. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  308. # successfull MOD with the ACI
  309. topology.master1.log.info("\n\n######################### MOVE to substring/ from equality filter ######################\n")
  310. _bind_manager(topology)
  311. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_ADD, target_from=STAGING_DN, target_to=PRODUCTION_PATTERN)
  312. _bind_normal(topology)
  313. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  314. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  315. # successfull MOD with the both ACI
  316. _bind_manager(topology)
  317. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_DELETE, target_from=STAGING_DN, target_to=PRODUCTION_PATTERN)
  318. _bind_normal(topology)
  319. def test_ticket47553_moddn_staging_prod_2(topology):
  320. '''
  321. This test case fails to MOVE entry NEW_ACCOUNT2 from staging to prod
  322. because of bad pattern
  323. '''
  324. topology.master1.log.info("\n\n######################### MOVE staging -> Prod (2) ######################\n")
  325. _bind_normal(topology)
  326. old_rdn = "cn=%s2" % NEW_ACCOUNT
  327. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  328. new_rdn = old_rdn
  329. new_superior = PRODUCTION_DN
  330. #
  331. # Try to rename without the apropriate ACI => INSUFFICIENT_ACCESS
  332. #
  333. try:
  334. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  335. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  336. assert 0
  337. except AssertionError:
  338. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  339. except Exception as e:
  340. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  341. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  342. # successfull MOD with the ACI
  343. topology.master1.log.info("\n\n######################### MOVE to substring (BAD)/ from equality filter ######################\n")
  344. _bind_manager(topology)
  345. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_ADD, target_from=STAGING_DN, target_to=BAD_PRODUCTION_PATTERN)
  346. _bind_normal(topology)
  347. try:
  348. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  349. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  350. except AssertionError:
  351. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  352. except Exception as e:
  353. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  354. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  355. # successfull MOD with the both ACI
  356. _bind_manager(topology)
  357. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_DELETE, target_from=STAGING_DN, target_to=BAD_PRODUCTION_PATTERN)
  358. _bind_normal(topology)
  359. def test_ticket47553_moddn_staging_prod_3(topology):
  360. '''
  361. This test case MOVE entry NEW_ACCOUNT3 from staging to prod
  362. target_to/target_from: equality/substring filter
  363. '''
  364. topology.master1.log.info("\n\n######################### MOVE staging -> Prod (3) ######################\n")
  365. _bind_normal(topology)
  366. old_rdn = "cn=%s3" % NEW_ACCOUNT
  367. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  368. new_rdn = old_rdn
  369. new_superior = PRODUCTION_DN
  370. #
  371. # Try to rename without the apropriate ACI => INSUFFICIENT_ACCESS
  372. #
  373. try:
  374. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  375. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  376. assert 0
  377. except AssertionError:
  378. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  379. except Exception as e:
  380. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  381. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  382. # successfull MOD with the ACI
  383. topology.master1.log.info("\n\n######################### MOVE to:equality filter / from substring filter ######################\n")
  384. _bind_manager(topology)
  385. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_ADD, target_from=STAGING_PATTERN, target_to=PRODUCTION_DN)
  386. _bind_normal(topology)
  387. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  388. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  389. # successfull MOD with the both ACI
  390. _bind_manager(topology)
  391. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_DELETE, target_from=STAGING_PATTERN, target_to=PRODUCTION_DN)
  392. _bind_normal(topology)
  393. def test_ticket47553_moddn_staging_prod_4(topology):
  394. '''
  395. This test case fails to MOVE entry NEW_ACCOUNT4 from staging to prod
  396. because of bad pattern
  397. '''
  398. topology.master1.log.info("\n\n######################### MOVE staging -> Prod (4) ######################\n")
  399. _bind_normal(topology)
  400. old_rdn = "cn=%s4" % NEW_ACCOUNT
  401. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  402. new_rdn = old_rdn
  403. new_superior = PRODUCTION_DN
  404. #
  405. # Try to rename without the apropriate ACI => INSUFFICIENT_ACCESS
  406. #
  407. try:
  408. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  409. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  410. assert 0
  411. except AssertionError:
  412. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  413. except Exception as e:
  414. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  415. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  416. # successfull MOD with the ACI
  417. topology.master1.log.info("\n\n######################### MOVE to: equality filter/ from: substring (BAD) ######################\n")
  418. _bind_manager(topology)
  419. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_ADD, target_from=BAD_STAGING_PATTERN, target_to=PRODUCTION_DN)
  420. _bind_normal(topology)
  421. try:
  422. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  423. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  424. except AssertionError:
  425. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  426. except Exception as e:
  427. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  428. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  429. # successfull MOD with the both ACI
  430. _bind_manager(topology)
  431. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_DELETE, target_from=BAD_STAGING_PATTERN, target_to=PRODUCTION_DN)
  432. _bind_normal(topology)
  433. def test_ticket47553_moddn_staging_prod_5(topology):
  434. '''
  435. This test case MOVE entry NEW_ACCOUNT5 from staging to prod
  436. target_to/target_from: substring/substring filter
  437. '''
  438. topology.master1.log.info("\n\n######################### MOVE staging -> Prod (5) ######################\n")
  439. _bind_normal(topology)
  440. old_rdn = "cn=%s5" % NEW_ACCOUNT
  441. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  442. new_rdn = old_rdn
  443. new_superior = PRODUCTION_DN
  444. #
  445. # Try to rename without the apropriate ACI => INSUFFICIENT_ACCESS
  446. #
  447. try:
  448. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  449. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  450. assert 0
  451. except AssertionError:
  452. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  453. except Exception as e:
  454. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  455. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  456. # successfull MOD with the ACI
  457. topology.master1.log.info("\n\n######################### MOVE to:substring filter / from: substring filter ######################\n")
  458. _bind_manager(topology)
  459. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_ADD, target_from=STAGING_PATTERN, target_to=PRODUCTION_PATTERN)
  460. _bind_normal(topology)
  461. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  462. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  463. # successfull MOD with the both ACI
  464. _bind_manager(topology)
  465. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_DELETE, target_from=STAGING_PATTERN, target_to=PRODUCTION_PATTERN)
  466. _bind_normal(topology)
  467. def test_ticket47553_moddn_staging_prod_6(topology):
  468. '''
  469. This test case MOVE entry NEW_ACCOUNT6 from staging to prod
  470. target_to/target_from: substring/<enmpty> filter
  471. '''
  472. topology.master1.log.info("\n\n######################### MOVE staging -> Prod (6) ######################\n")
  473. _bind_normal(topology)
  474. old_rdn = "cn=%s6" % NEW_ACCOUNT
  475. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  476. new_rdn = old_rdn
  477. new_superior = PRODUCTION_DN
  478. #
  479. # Try to rename without the apropriate ACI => INSUFFICIENT_ACCESS
  480. #
  481. try:
  482. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  483. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  484. assert 0
  485. except AssertionError:
  486. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  487. except Exception as e:
  488. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  489. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  490. # successfull MOD with the ACI
  491. topology.master1.log.info("\n\n######################### MOVE to:substring filter / from: empty ######################\n")
  492. _bind_manager(topology)
  493. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_ADD, target_from=None, target_to=PRODUCTION_PATTERN)
  494. _bind_normal(topology)
  495. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  496. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  497. # successfull MOD with the both ACI
  498. _bind_manager(topology)
  499. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_DELETE, target_from=None, target_to=PRODUCTION_PATTERN)
  500. _bind_normal(topology)
  501. def test_ticket47553_moddn_staging_prod_7(topology):
  502. '''
  503. This test case MOVE entry NEW_ACCOUNT7 from staging to prod
  504. target_to/target_from: <empty>/substring filter
  505. '''
  506. topology.master1.log.info("\n\n######################### MOVE staging -> Prod (7) ######################\n")
  507. _bind_normal(topology)
  508. old_rdn = "cn=%s7" % NEW_ACCOUNT
  509. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  510. new_rdn = old_rdn
  511. new_superior = PRODUCTION_DN
  512. #
  513. # Try to rename without the apropriate ACI => INSUFFICIENT_ACCESS
  514. #
  515. try:
  516. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  517. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  518. assert 0
  519. except AssertionError:
  520. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  521. except Exception as e:
  522. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  523. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  524. # successfull MOD with the ACI
  525. topology.master1.log.info("\n\n######################### MOVE to: empty/ from: substring filter ######################\n")
  526. _bind_manager(topology)
  527. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_ADD, target_from=STAGING_PATTERN, target_to=None)
  528. _bind_normal(topology)
  529. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  530. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  531. # successfull MOD with the both ACI
  532. _bind_manager(topology)
  533. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_DELETE, target_from=STAGING_PATTERN, target_to=None)
  534. _bind_normal(topology)
  535. def test_ticket47553_moddn_staging_prod_8(topology):
  536. '''
  537. This test case MOVE entry NEW_ACCOUNT8 from staging to prod
  538. target_to/target_from: <empty>/<empty> filter
  539. '''
  540. topology.master1.log.info("\n\n######################### MOVE staging -> Prod (8) ######################\n")
  541. _bind_normal(topology)
  542. old_rdn = "cn=%s8" % NEW_ACCOUNT
  543. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  544. new_rdn = old_rdn
  545. new_superior = PRODUCTION_DN
  546. #
  547. # Try to rename without the apropriate ACI => INSUFFICIENT_ACCESS
  548. #
  549. try:
  550. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  551. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  552. assert 0
  553. except AssertionError:
  554. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  555. except Exception as e:
  556. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  557. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  558. # successfull MOD with the ACI
  559. topology.master1.log.info("\n\n######################### MOVE to: empty/ from: empty ######################\n")
  560. _bind_manager(topology)
  561. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_ADD, target_from=None, target_to=None)
  562. _bind_normal(topology)
  563. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  564. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  565. # successfull MOD with the both ACI
  566. _bind_manager(topology)
  567. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_DELETE, target_from=None, target_to=None)
  568. _bind_normal(topology)
  569. def test_ticket47553_moddn_staging_prod_9(topology):
  570. '''
  571. This test case disable the 'moddn' right so a MODDN requires a 'add' right
  572. to be successfull.
  573. It fails to MOVE entry NEW_ACCOUNT9 from staging to prod.
  574. Add a 'add' right to prod.
  575. Then it succeeds to MOVE NEW_ACCOUNT9 from staging to prod.
  576. Then enable the 'moddn' right so a MODDN requires a 'moddn' right
  577. It fails to MOVE entry NEW_ACCOUNT10 from staging to prod.
  578. Add a 'moddn' right to prod.
  579. Then it succeeds to MOVE NEW_ACCOUNT10 from staging to prod.
  580. '''
  581. topology.master1.log.info("\n\n######################### MOVE staging -> Prod (9) ######################\n")
  582. _bind_normal(topology)
  583. old_rdn = "cn=%s9" % NEW_ACCOUNT
  584. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  585. new_rdn = old_rdn
  586. new_superior = PRODUCTION_DN
  587. #
  588. # Try to rename without the apropriate ACI => INSUFFICIENT_ACCESS
  589. #
  590. try:
  591. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  592. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  593. assert 0
  594. except AssertionError:
  595. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  596. except Exception as e:
  597. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  598. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  599. ############################################
  600. # Now do tests with no support of moddn aci
  601. ############################################
  602. topology.master1.log.info("Disable the moddn right")
  603. _bind_manager(topology)
  604. mod = [(ldap.MOD_REPLACE, CONFIG_MODDN_ACI_ATTR, 'off')]
  605. topology.master1.modify_s(DN_CONFIG, mod)
  606. # Add the moddn aci that will not be evaluated because of the config flag
  607. topology.master1.log.info("\n\n######################### MOVE to and from equality filter ######################\n")
  608. _bind_manager(topology)
  609. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_ADD, target_from=STAGING_DN, target_to=PRODUCTION_DN)
  610. _bind_normal(topology)
  611. # It will fail because it will test the ADD right
  612. try:
  613. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  614. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  615. assert 0
  616. except AssertionError:
  617. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  618. except Exception as e:
  619. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  620. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  621. # remove the moddn aci
  622. _bind_manager(topology)
  623. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_DELETE, target_from=STAGING_DN, target_to=PRODUCTION_DN)
  624. _bind_normal(topology)
  625. #
  626. # add the 'add' right to the production DN
  627. # Then do a successfull moddn
  628. #
  629. ACI_ALLOW = "(version 3.0; acl \"ADD rights to allow moddn\"; allow (add)"
  630. ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
  631. ACI_BODY = ACI_ALLOW + ACI_SUBJECT
  632. _bind_manager(topology)
  633. mod = [(ldap.MOD_ADD, 'aci', ACI_BODY)]
  634. topology.master1.modify_s(PRODUCTION_DN, mod)
  635. _bind_normal(topology)
  636. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  637. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  638. _bind_manager(topology)
  639. mod = [(ldap.MOD_DELETE, 'aci', ACI_BODY)]
  640. topology.master1.modify_s(PRODUCTION_DN, mod)
  641. _bind_normal(topology)
  642. ############################################
  643. # Now do tests with support of moddn aci
  644. ############################################
  645. topology.master1.log.info("Enable the moddn right")
  646. _bind_manager(topology)
  647. mod = [(ldap.MOD_REPLACE, CONFIG_MODDN_ACI_ATTR, 'on')]
  648. topology.master1.modify_s(DN_CONFIG, mod)
  649. topology.master1.log.info("\n\n######################### MOVE staging -> Prod (10) ######################\n")
  650. _bind_normal(topology)
  651. old_rdn = "cn=%s10" % NEW_ACCOUNT
  652. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  653. new_rdn = old_rdn
  654. new_superior = PRODUCTION_DN
  655. #
  656. # Try to rename without the apropriate ACI => INSUFFICIENT_ACCESS
  657. #
  658. try:
  659. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  660. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  661. assert 0
  662. except AssertionError:
  663. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  664. except Exception as e:
  665. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  666. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  667. #
  668. # add the 'add' right to the production DN
  669. # Then do a failing moddn
  670. #
  671. ACI_ALLOW = "(version 3.0; acl \"ADD rights to allow moddn\"; allow (add)"
  672. ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
  673. ACI_BODY = ACI_ALLOW + ACI_SUBJECT
  674. _bind_manager(topology)
  675. mod = [(ldap.MOD_ADD, 'aci', ACI_BODY)]
  676. topology.master1.modify_s(PRODUCTION_DN, mod)
  677. _bind_normal(topology)
  678. try:
  679. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  680. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  681. assert 0
  682. except AssertionError:
  683. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  684. except Exception as e:
  685. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  686. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  687. _bind_manager(topology)
  688. mod = [(ldap.MOD_DELETE, 'aci', ACI_BODY)]
  689. topology.master1.modify_s(PRODUCTION_DN, mod)
  690. _bind_normal(topology)
  691. # Add the moddn aci that will be evaluated because of the config flag
  692. topology.master1.log.info("\n\n######################### MOVE to and from equality filter ######################\n")
  693. _bind_manager(topology)
  694. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_ADD, target_from=STAGING_DN, target_to=PRODUCTION_DN)
  695. _bind_normal(topology)
  696. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  697. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  698. # remove the moddn aci
  699. _bind_manager(topology)
  700. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_DELETE, target_from=STAGING_DN, target_to=PRODUCTION_DN)
  701. _bind_normal(topology)
  702. def test_ticket47553_moddn_prod_staging(topology):
  703. '''
  704. This test checks that we can move ACCOUNT11 from staging to prod
  705. but not move back ACCOUNT11 from prod to staging
  706. '''
  707. topology.master1.log.info("\n\n######################### MOVE staging -> Prod (11) ######################\n")
  708. _bind_normal(topology)
  709. old_rdn = "cn=%s11" % NEW_ACCOUNT
  710. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  711. new_rdn = old_rdn
  712. new_superior = PRODUCTION_DN
  713. #
  714. # Try to rename without the apropriate ACI => INSUFFICIENT_ACCESS
  715. #
  716. try:
  717. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  718. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  719. assert 0
  720. except AssertionError:
  721. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  722. except Exception as e:
  723. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  724. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  725. # successfull MOD with the ACI
  726. topology.master1.log.info("\n\n######################### MOVE to and from equality filter ######################\n")
  727. _bind_manager(topology)
  728. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_ADD, target_from=STAGING_DN, target_to=PRODUCTION_DN)
  729. _bind_normal(topology)
  730. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  731. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  732. # Now check we can not move back the entry to staging
  733. old_rdn = "cn=%s11" % NEW_ACCOUNT
  734. old_dn = "%s,%s" % (old_rdn, PRODUCTION_DN)
  735. new_rdn = old_rdn
  736. new_superior = STAGING_DN
  737. try:
  738. topology.master1.log.info("Try to move back MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  739. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  740. assert 0
  741. except AssertionError:
  742. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  743. except Exception as e:
  744. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  745. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  746. # successfull MOD with the both ACI
  747. _bind_manager(topology)
  748. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_DELETE, target_from=STAGING_DN, target_to=PRODUCTION_DN)
  749. _bind_normal(topology)
  750. def test_ticket47553_check_repl_M2_to_M1(topology):
  751. '''
  752. Checks that replication is still working M2->M1, using ACCOUNT12
  753. '''
  754. topology.master1.log.info("Bind as %s (M2)" % DN_DM)
  755. topology.master2.simple_bind_s(DN_DM, PASSWORD)
  756. rdn = "cn=%s12" % NEW_ACCOUNT
  757. dn = "%s,%s" % (rdn, STAGING_DN)
  758. # First wait for the ACCOUNT19 entry being replicated on M2
  759. loop = 0
  760. while loop <= 10:
  761. try:
  762. ent = topology.master2.getEntry(dn, ldap.SCOPE_BASE, "(objectclass=*)")
  763. break
  764. except ldap.NO_SUCH_OBJECT:
  765. time.sleep(1)
  766. loop += 1
  767. assert loop <= 10
  768. attribute = 'description'
  769. tested_value = 'Hello world'
  770. mod = [(ldap.MOD_ADD, attribute, tested_value)]
  771. topology.master1.log.info("Update (M2) %s (%s)" % (dn, attribute))
  772. topology.master2.modify_s(dn, mod)
  773. loop = 0
  774. while loop <= 10:
  775. ent = topology.master1.getEntry(dn, ldap.SCOPE_BASE, "(objectclass=*)")
  776. assert ent is not None
  777. if ent.hasAttr(attribute) and (ent.getValue(attribute) == tested_value):
  778. break
  779. time.sleep(1)
  780. loop += 1
  781. assert loop < 10
  782. topology.master1.log.info("Update %s (%s) replicated on M1" % (dn, attribute))
  783. def test_ticket47553_moddn_staging_prod_except(topology):
  784. '''
  785. This test case MOVE entry NEW_ACCOUNT13 from staging to prod
  786. but fails to move entry NEW_ACCOUNT14 from staging to prod_except
  787. '''
  788. topology.master1.log.info("\n\n######################### MOVE staging -> Prod (13) ######################\n")
  789. _bind_normal(topology)
  790. old_rdn = "cn=%s13" % NEW_ACCOUNT
  791. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  792. new_rdn = old_rdn
  793. new_superior = PRODUCTION_DN
  794. #
  795. # Try to rename without the apropriate ACI => INSUFFICIENT_ACCESS
  796. #
  797. try:
  798. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  799. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  800. assert 0
  801. except AssertionError:
  802. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  803. except Exception as e:
  804. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  805. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  806. # successfull MOD with the ACI
  807. topology.master1.log.info("\n\n######################### MOVE to and from equality filter ######################\n")
  808. _bind_manager(topology)
  809. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_ADD, target_from=STAGING_DN, target_to=PRODUCTION_DN)
  810. _moddn_aci_deny_tree(topology, mod_type=ldap.MOD_ADD)
  811. _bind_normal(topology)
  812. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  813. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  814. #
  815. # Now try to move an entry under except
  816. #
  817. topology.master1.log.info("\n\n######################### MOVE staging -> Prod/Except (14) ######################\n")
  818. old_rdn = "cn=%s14" % NEW_ACCOUNT
  819. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  820. new_rdn = old_rdn
  821. new_superior = PROD_EXCEPT_DN
  822. try:
  823. topology.master1.log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  824. topology.master1.rename_s(old_dn, new_rdn, newsuperior=new_superior)
  825. assert 0
  826. except AssertionError:
  827. topology.master1.log.info("Exception (not really expected exception but that is fine as it fails to rename)")
  828. except Exception as e:
  829. topology.master1.log.info("Exception (expected): %s" % type(e).__name__)
  830. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  831. # successfull MOD with the both ACI
  832. _bind_manager(topology)
  833. _moddn_aci_staging_to_production(topology, mod_type=ldap.MOD_DELETE, target_from=STAGING_DN, target_to=PRODUCTION_DN)
  834. _moddn_aci_deny_tree(topology, mod_type=ldap.MOD_DELETE)
  835. _bind_normal(topology)
  836. def test_ticket47553_final(topology):
  837. topology.master1.delete()
  838. topology.master2.delete()
  839. log.info('Testcase PASSED')
  840. def run_isolated():
  841. '''
  842. run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..)
  843. To run isolated without py.test, you need to
  844. - edit this file and comment '@pytest.fixture' line before 'topology' function.
  845. - set the installation prefix
  846. - run this program
  847. '''
  848. global installation1_prefix
  849. global installation2_prefix
  850. installation1_prefix = None
  851. installation2_prefix = None
  852. topo = topology(True)
  853. topo.master1.log.info("\n\n######################### Ticket 47553 ######################\n")
  854. test_ticket47553_init(topo)
  855. # Check that without appropriate aci we are not allowed to add/delete
  856. test_ticket47553_add(topo)
  857. test_ticket47553_delete(topo)
  858. # tests the ACI as equality/substring filter
  859. test_ticket47553_moddn_staging_prod_0(topo)
  860. test_ticket47553_moddn_staging_prod_1(topo)
  861. test_ticket47553_moddn_staging_prod_2(topo)
  862. test_ticket47553_moddn_staging_prod_3(topo)
  863. test_ticket47553_moddn_staging_prod_4(topo)
  864. test_ticket47553_moddn_staging_prod_5(topo)
  865. # tests the ACI with undefined 'target_to'/'target_from'
  866. test_ticket47553_moddn_staging_prod_6(topo)
  867. test_ticket47553_moddn_staging_prod_7(topo)
  868. test_ticket47553_moddn_staging_prod_8(topo)
  869. # Check we can control the behavior with nsslapd-moddn-aci
  870. test_ticket47553_moddn_staging_prod_9(topo)
  871. # Check we can move entry 'from' -> 'to' but not 'to' -> 'from'
  872. test_ticket47553_moddn_prod_staging(topo)
  873. # check replication is still working
  874. test_ticket47553_check_repl_M2_to_M1(topo)
  875. # check DENY rule is working
  876. test_ticket47553_moddn_staging_prod_except(topo)
  877. test_ticket47553_final(topo)
  878. if __name__ == '__main__':
  879. run_isolated()