ticket47553_single_aci_test.py 43 KB

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