acl_test.py 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2016 Red Hat, Inc.
  3. # All rights reserved.
  4. #
  5. # License: GPL (version 3 or any later version).
  6. # See LICENSE for details.
  7. # --- END COPYRIGHT BLOCK ---
  8. #
  9. import pytest
  10. from ldap.controls.simple import GetEffectiveRightsControl
  11. from lib389.tasks import *
  12. from lib389.utils import *
  13. from lib389.schema import Schema
  14. from lib389.idm.domain import Domain
  15. from lib389.idm.user import UserAccount, UserAccounts, TEST_USER_PROPERTIES
  16. from lib389.idm.organizationalrole import OrganizationalRole, OrganizationalRoles
  17. from lib389.topologies import topology_m2
  18. from lib389._constants import SUFFIX, DN_SCHEMA, DN_DM, DEFAULT_SUFFIX, PASSWORD
  19. pytestmark = pytest.mark.tier1
  20. logging.getLogger(__name__).setLevel(logging.DEBUG)
  21. log = logging.getLogger(__name__)
  22. TEST_REPL_DN = "cn=test_repl, %s" % SUFFIX
  23. STAGING_CN = "staged user"
  24. PRODUCTION_CN = "accounts"
  25. EXCEPT_CN = "excepts"
  26. STAGING_DN = "cn=%s,%s" % (STAGING_CN, SUFFIX)
  27. PRODUCTION_DN = "cn=%s,%s" % (PRODUCTION_CN, SUFFIX)
  28. PROD_EXCEPT_DN = "cn=%s,%s" % (EXCEPT_CN, PRODUCTION_DN)
  29. STAGING_PATTERN = "cn=%s*,%s" % (STAGING_CN[:2], SUFFIX)
  30. PRODUCTION_PATTERN = "cn=%s*,%s" % (PRODUCTION_CN[:2], SUFFIX)
  31. BAD_STAGING_PATTERN = "cn=bad*,%s" % (SUFFIX)
  32. BAD_PRODUCTION_PATTERN = "cn=bad*,%s" % (SUFFIX)
  33. BIND_RDN = "bind_entry"
  34. BIND_DN = "uid=%s,%s" % (BIND_RDN, SUFFIX)
  35. BIND_PW = "password"
  36. NEW_ACCOUNT = "new_account"
  37. MAX_ACCOUNTS = 20
  38. CONFIG_MODDN_ACI_ATTR = "nsslapd-moddn-aci"
  39. SRC_ENTRY_CN = "tuser"
  40. EXT_RDN = "01"
  41. DST_ENTRY_CN = SRC_ENTRY_CN + EXT_RDN
  42. SRC_ENTRY_DN = "cn=%s,%s" % (SRC_ENTRY_CN, SUFFIX)
  43. DST_ENTRY_DN = "cn=%s,%s" % (DST_ENTRY_CN, SUFFIX)
  44. def add_attr(topology_m2, attr_name):
  45. """Adds attribute to the schema"""
  46. ATTR_VALUE = """(NAME '%s' \
  47. DESC 'Attribute filteri-Multi-Valued' \
  48. SYNTAX 1.3.6.1.4.1.1466.115.121.1.27)""" % attr_name
  49. schema = Schema(topology_m2.ms["master1"])
  50. schema.add('attributeTypes', ATTR_VALUE)
  51. @pytest.fixture(params=["lang-ja", "binary", "phonetic"])
  52. def aci_with_attr_subtype(request, topology_m2):
  53. """Adds and deletes an ACI in the DEFAULT_SUFFIX"""
  54. TARGET_ATTR = 'protectedOperation'
  55. USER_ATTR = 'allowedToPerform'
  56. SUBTYPE = request.param
  57. suffix = Domain(topology_m2.ms["master1"], DEFAULT_SUFFIX)
  58. log.info("========Executing test with '%s' subtype========" % SUBTYPE)
  59. log.info(" Add a target attribute")
  60. add_attr(topology_m2, TARGET_ATTR)
  61. log.info(" Add a user attribute")
  62. add_attr(topology_m2, USER_ATTR)
  63. ACI_TARGET = '(targetattr=%s;%s)' % (TARGET_ATTR, SUBTYPE)
  64. ACI_ALLOW = '(version 3.0; acl "test aci for subtypes"; allow (read) '
  65. ACI_SUBJECT = 'userattr = "%s;%s#GROUPDN";)' % (USER_ATTR, SUBTYPE)
  66. ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
  67. log.info("Add an ACI with attribute subtype")
  68. suffix.add('aci', ACI_BODY)
  69. def fin():
  70. log.info("Finally, delete an ACI with the '%s' subtype" %
  71. SUBTYPE)
  72. suffix.remove('aci', ACI_BODY)
  73. request.addfinalizer(fin)
  74. return ACI_BODY
  75. def test_aci_attr_subtype_targetattr(topology_m2, aci_with_attr_subtype):
  76. """Checks, that ACIs allow attribute subtypes in the targetattr keyword
  77. :id: a99ccda0-5d0b-4d41-99cc-c5e207b3b687
  78. :setup: MMR with two masters,
  79. Define two attributes in the schema - targetattr and userattr,
  80. Add an ACI with attribute subtypes - "lang-ja", "binary", "phonetic"
  81. one by one
  82. :steps:
  83. 1. Search for the added attribute during setup
  84. one by one for each subtypes "lang-ja", "binary", "phonetic"
  85. :expectedresults:
  86. 1. Attributes should be found successfully
  87. one by one for each subtypes "lang-ja", "binary", "phonetic"
  88. """
  89. log.info("Search for the added attribute")
  90. try:
  91. entries = topology_m2.ms["master1"].search_s(DEFAULT_SUFFIX,
  92. ldap.SCOPE_BASE,
  93. '(objectclass=*)', ['aci'])
  94. entry = str(entries[0])
  95. assert aci_with_attr_subtype in entry
  96. log.info("The added attribute was found")
  97. except ldap.LDAPError as e:
  98. log.fatal('Search failed, error: ' + e.message['desc'])
  99. assert False
  100. def _bind_manager(topology_m2):
  101. topology_m2.ms["master1"].log.info("Bind as %s " % DN_DM)
  102. topology_m2.ms["master1"].simple_bind_s(DN_DM, PASSWORD)
  103. def _bind_normal(topology_m2):
  104. # bind as bind_entry
  105. topology_m2.ms["master1"].log.info("Bind as %s" % BIND_DN)
  106. topology_m2.ms["master1"].simple_bind_s(BIND_DN, BIND_PW)
  107. def _moddn_aci_deny_tree(topology_m2, mod_type=None,
  108. target_from=STAGING_DN, target_to=PROD_EXCEPT_DN):
  109. """It denies the access moddn_to in cn=except,cn=accounts,SUFFIX"""
  110. assert mod_type is not None
  111. ACI_TARGET_FROM = ""
  112. ACI_TARGET_TO = ""
  113. if target_from:
  114. ACI_TARGET_FROM = "(target_from = \"ldap:///%s\")" % (target_from)
  115. if target_to:
  116. ACI_TARGET_TO = "(target_to = \"ldap:///%s\")" % (target_to)
  117. ACI_ALLOW = "(version 3.0; acl \"Deny MODDN to prod_except\"; deny (moddn)"
  118. ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
  119. ACI_BODY = ACI_TARGET_TO + ACI_TARGET_FROM + ACI_ALLOW + ACI_SUBJECT
  120. # topology_m2.ms["master1"].modify_s(SUFFIX, mod)
  121. topology_m2.ms["master1"].log.info("Add a DENY aci under %s " % PROD_EXCEPT_DN)
  122. prod_except = OrganizationalRole(topology_m2.ms["master1"], PROD_EXCEPT_DN)
  123. prod_except.set('aci', ACI_BODY, mod_type)
  124. def _write_aci_staging(topology_m2, mod_type=None):
  125. assert mod_type is not None
  126. ACI_TARGET = "(targetattr= \"uid\")(target=\"ldap:///uid=*,%s\")" % STAGING_DN
  127. ACI_ALLOW = "(version 3.0; acl \"write staging entries\"; allow (write)"
  128. ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
  129. ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
  130. suffix = Domain(topology_m2.ms["master1"], SUFFIX)
  131. suffix.set('aci', ACI_BODY, mod_type)
  132. def _write_aci_production(topology_m2, mod_type=None):
  133. assert mod_type is not None
  134. ACI_TARGET = "(targetattr= \"uid\")(target=\"ldap:///uid=*,%s\")" % PRODUCTION_DN
  135. ACI_ALLOW = "(version 3.0; acl \"write production entries\"; allow (write)"
  136. ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
  137. ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
  138. suffix = Domain(topology_m2.ms["master1"], SUFFIX)
  139. suffix.set('aci', ACI_BODY, mod_type)
  140. def _moddn_aci_staging_to_production(topology_m2, mod_type=None,
  141. target_from=STAGING_DN, target_to=PRODUCTION_DN):
  142. assert mod_type is not None
  143. ACI_TARGET_FROM = ""
  144. ACI_TARGET_TO = ""
  145. if target_from:
  146. ACI_TARGET_FROM = "(target_from = \"ldap:///%s\")" % (target_from)
  147. if target_to:
  148. ACI_TARGET_TO = "(target_to = \"ldap:///%s\")" % (target_to)
  149. ACI_ALLOW = "(version 3.0; acl \"MODDN from staging to production\"; allow (moddn)"
  150. ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
  151. ACI_BODY = ACI_TARGET_FROM + ACI_TARGET_TO + ACI_ALLOW + ACI_SUBJECT
  152. suffix = Domain(topology_m2.ms["master1"], SUFFIX)
  153. suffix.set('aci', ACI_BODY, mod_type)
  154. _write_aci_staging(topology_m2, mod_type=mod_type)
  155. def _moddn_aci_from_production_to_staging(topology_m2, mod_type=None):
  156. assert mod_type is not None
  157. ACI_TARGET = "(target_from = \"ldap:///%s\") (target_to = \"ldap:///%s\")" % (
  158. PRODUCTION_DN, STAGING_DN)
  159. ACI_ALLOW = "(version 3.0; acl \"MODDN from production to staging\"; allow (moddn)"
  160. ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
  161. ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
  162. suffix = Domain(topology_m2.ms["master1"], SUFFIX)
  163. suffix.set('aci', ACI_BODY, mod_type)
  164. _write_aci_production(topology_m2, mod_type=mod_type)
  165. @pytest.fixture(scope="module")
  166. def moddn_setup(topology_m2):
  167. """Creates
  168. - a staging DIT
  169. - a production DIT
  170. - add accounts in staging DIT
  171. - enable ACL logging (commented for performance reason)
  172. """
  173. m1 = topology_m2.ms["master1"]
  174. o_roles = OrganizationalRoles(m1, SUFFIX)
  175. m1.log.info("\n\n######## INITIALIZATION ########\n")
  176. # entry used to bind with
  177. m1.log.info("Add {}".format(BIND_DN))
  178. user = UserAccount(m1, BIND_DN)
  179. user_props = TEST_USER_PROPERTIES.copy()
  180. user_props.update({'sn': BIND_RDN,
  181. 'cn': BIND_RDN,
  182. 'uid': BIND_RDN,
  183. 'userpassword': BIND_PW})
  184. user.create(properties=user_props, basedn=SUFFIX)
  185. # DIT for staging
  186. m1.log.info("Add {}".format(STAGING_DN))
  187. o_roles.create(properties={'cn': STAGING_CN, 'description': "staging DIT"})
  188. # DIT for production
  189. m1.log.info("Add {}".format(PRODUCTION_DN))
  190. o_roles.create(properties={'cn': PRODUCTION_CN, 'description': "production DIT"})
  191. # DIT for production/except
  192. m1.log.info("Add {}".format(PROD_EXCEPT_DN))
  193. o_roles_prod = OrganizationalRoles(m1, PRODUCTION_DN)
  194. o_roles_prod.create(properties={'cn': EXCEPT_CN, 'description': "production except DIT"})
  195. # enable acl error logging
  196. # mod = [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', '128')]
  197. # m1.modify_s(DN_CONFIG, mod)
  198. # topology_m2.ms["master2"].modify_s(DN_CONFIG, mod)
  199. # add dummy entries in the staging DIT
  200. staging_users = UserAccounts(m1, SUFFIX, rdn="cn={}".format(STAGING_CN))
  201. user_props = TEST_USER_PROPERTIES.copy()
  202. for cpt in range(MAX_ACCOUNTS):
  203. name = "{}{}".format(NEW_ACCOUNT, cpt)
  204. user_props.update({'sn': name, 'cn': name, 'uid': name})
  205. staging_users.create(properties=user_props)
  206. def test_mode_default_add_deny(topology_m2, moddn_setup):
  207. """Tests that the ADD operation fails (no ADD aci on production)
  208. :id: 301d41d3-b8d8-44c5-8eb9-c2d2816b5a4f
  209. :setup: MMR with two masters,
  210. M1 - staging DIT
  211. M2 - production DIT
  212. add test accounts in staging DIT
  213. :steps:
  214. 1. Add an entry in production
  215. :expectedresults:
  216. 1. It should fail due to INSUFFICIENT_ACCESS
  217. """
  218. topology_m2.ms["master1"].log.info("\n\n######## mode moddn_aci : ADD (should fail) ########\n")
  219. _bind_normal(topology_m2)
  220. #
  221. # First try to add an entry in production => INSUFFICIENT_ACCESS
  222. #
  223. try:
  224. topology_m2.ms["master1"].log.info("Try to add %s" % PRODUCTION_DN)
  225. name = "%s%d" % (NEW_ACCOUNT, 0)
  226. topology_m2.ms["master1"].add_s(Entry(("uid=%s,%s" % (name, PRODUCTION_DN), {
  227. 'objectclass': "top person".split(),
  228. 'sn': name,
  229. 'cn': name,
  230. 'uid': name})))
  231. assert 0 # this is an error, we should not be allowed to add an entry in production
  232. except Exception as e:
  233. topology_m2.ms["master1"].log.info("Exception (expected): %s" % type(e).__name__)
  234. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  235. def test_mode_default_delete_deny(topology_m2, moddn_setup):
  236. """Tests that the DEL operation fails (no 'delete' aci on production)
  237. :id: 5dcb2213-3875-489a-8cb5-ace057120ad6
  238. :setup: MMR with two masters,
  239. M1 - staging DIT
  240. M2 - production DIT
  241. add test accounts in staging DIT
  242. :steps:
  243. 1. Delete an entry in staging
  244. :expectedresults:
  245. 1. It should fail due to INSUFFICIENT_ACCESS
  246. """
  247. topology_m2.ms["master1"].log.info("\n\n######## DELETE (should fail) ########\n")
  248. _bind_normal(topology_m2)
  249. #
  250. # Second try to delete an entry in staging => INSUFFICIENT_ACCESS
  251. #
  252. try:
  253. topology_m2.ms["master1"].log.info("Try to delete %s" % STAGING_DN)
  254. name = "%s%d" % (NEW_ACCOUNT, 0)
  255. topology_m2.ms["master1"].delete_s("uid=%s,%s" % (name, STAGING_DN))
  256. assert 0 # this is an error, we should not be allowed to add an entry in production
  257. except Exception as e:
  258. topology_m2.ms["master1"].log.info("Exception (expected): %s" % type(e).__name__)
  259. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  260. @pytest.mark.parametrize("index,tfrom,tto,failure",
  261. [(0, STAGING_DN, PRODUCTION_DN, False),
  262. (1, STAGING_DN, PRODUCTION_DN, False),
  263. (2, STAGING_DN, BAD_PRODUCTION_PATTERN, True),
  264. (3, STAGING_PATTERN, PRODUCTION_DN, False),
  265. (4, BAD_STAGING_PATTERN, PRODUCTION_DN, True),
  266. (5, STAGING_PATTERN, PRODUCTION_PATTERN, False),
  267. (6, None, PRODUCTION_PATTERN, False),
  268. (7, STAGING_PATTERN, None, False),
  269. (8, None, None, False)])
  270. def test_moddn_staging_prod(topology_m2, moddn_setup,
  271. index, tfrom, tto, failure):
  272. """This test case MOVE entry NEW_ACCOUNT0 from staging to prod
  273. target_to/target_from: equality filter
  274. :id: cbafdd68-64d6-431f-9f22-6fbf9ed23ca0
  275. :setup: MMR with two masters,
  276. M1 - staging DIT
  277. M2 - production DIT
  278. add test accounts in staging DIT
  279. :steps:
  280. 1. Try to modify DN with moddn for each value of
  281. STAGING_DN -> PRODUCTION_DN
  282. 2. Try to modify DN with moddn for each value of
  283. STAGING_DN -> PRODUCTION_DN with appropriate ACI
  284. :expectedresults:
  285. 1. It should fail due to INSUFFICIENT_ACCESS
  286. 2. It should pass due to appropriate ACI
  287. """
  288. topology_m2.ms["master1"].log.info("\n\n######## MOVE staging -> Prod (%s) ########\n" % index)
  289. _bind_normal(topology_m2)
  290. old_rdn = "uid=%s%s" % (NEW_ACCOUNT, index)
  291. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  292. new_rdn = old_rdn
  293. new_superior = PRODUCTION_DN
  294. #
  295. # Try to rename without the appropriate ACI => INSUFFICIENT_ACCESS
  296. #
  297. try:
  298. topology_m2.ms["master1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  299. topology_m2.ms["master1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
  300. assert 0
  301. except AssertionError:
  302. topology_m2.ms["master1"].log.info(
  303. "Exception (not really expected exception but that is fine as it fails to rename)")
  304. except Exception as e:
  305. topology_m2.ms["master1"].log.info("Exception (expected): %s" % type(e).__name__)
  306. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  307. # successful MOD with the ACI
  308. topology_m2.ms["master1"].log.info("\n\n######## MOVE to and from equality filter ########\n")
  309. _bind_manager(topology_m2)
  310. _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_ADD,
  311. target_from=tfrom, target_to=tto)
  312. _bind_normal(topology_m2)
  313. try:
  314. topology_m2.ms["master1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  315. topology_m2.ms["master1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
  316. except Exception as e:
  317. topology_m2.ms["master1"].log.info("Exception (expected): %s" % type(e).__name__)
  318. if failure:
  319. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  320. # successful MOD with the both ACI
  321. _bind_manager(topology_m2)
  322. _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_DELETE,
  323. target_from=tfrom, target_to=tto)
  324. _bind_normal(topology_m2)
  325. def test_moddn_staging_prod_9(topology_m2, moddn_setup):
  326. """
  327. :id: 222dd7e8-7ff1-40b8-ad26-6f8e42fbfcd9
  328. :setup: MMR with two masters,
  329. M1 - staging DIT
  330. M2 - production DIT
  331. add test accounts in staging DIT
  332. :steps:
  333. 1. Try to modify DN with moddn STAGING_DN -> PRODUCTION_DN
  334. 2. Add the moddn aci that will not be evaluated because of the config flag
  335. 3. Try to do modDN
  336. 4. Remove the moddn aci
  337. 5. Add the 'add' right to the production DN
  338. 6. Try to modify DN with moddn with 'add' right
  339. 7. Enable the moddn right
  340. 8. Try to rename without the appropriate ACI
  341. 9. Add the 'add' right to the production DN
  342. 10. Try to rename without the appropriate ACI
  343. 11. Remove the moddn aci
  344. :expectedresults:
  345. 1. It should fail due to INSUFFICIENT_ACCESS
  346. 2. It should pass
  347. 3. It should fail due to INSUFFICIENT_ACCESS
  348. 4. It should pass
  349. 5. It should pass
  350. 6. It should pass
  351. 7. It should pass
  352. 8. It should fail due to INSUFFICIENT_ACCESS
  353. 9. It should pass
  354. 10. It should fail due to INSUFFICIENT_ACCESS
  355. 11. It should pass
  356. """
  357. topology_m2.ms["master1"].log.info("\n\n######## MOVE staging -> Prod (9) ########\n")
  358. _bind_normal(topology_m2)
  359. old_rdn = "uid=%s9" % NEW_ACCOUNT
  360. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  361. new_rdn = old_rdn
  362. new_superior = PRODUCTION_DN
  363. prod = OrganizationalRole(topology_m2.ms["master1"], PRODUCTION_DN)
  364. #
  365. # Try to rename without the appropriate ACI => INSUFFICIENT_ACCESS
  366. #
  367. try:
  368. topology_m2.ms["master1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  369. topology_m2.ms["master1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
  370. assert 0
  371. except AssertionError:
  372. topology_m2.ms["master1"].log.info(
  373. "Exception (not really expected exception but that is fine as it fails to rename)")
  374. except Exception as e:
  375. topology_m2.ms["master1"].log.info("Exception (expected): %s" % type(e).__name__)
  376. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  377. #############
  378. # Now do tests with no support of moddn aci
  379. #############
  380. topology_m2.ms["master1"].log.info("Disable the moddn right")
  381. _bind_manager(topology_m2)
  382. topology_m2.ms["master1"].config.set(CONFIG_MODDN_ACI_ATTR, 'off')
  383. # Add the moddn aci that will not be evaluated because of the config flag
  384. topology_m2.ms["master1"].log.info("\n\n######## MOVE to and from equality filter ########\n")
  385. _bind_manager(topology_m2)
  386. _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_ADD,
  387. target_from=STAGING_DN, target_to=PRODUCTION_DN)
  388. _bind_normal(topology_m2)
  389. # It will fail because it will test the ADD right
  390. try:
  391. topology_m2.ms["master1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  392. topology_m2.ms["master1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
  393. assert 0
  394. except AssertionError:
  395. topology_m2.ms["master1"].log.info(
  396. "Exception (not really expected exception but that is fine as it fails to rename)")
  397. except Exception as e:
  398. topology_m2.ms["master1"].log.info("Exception (expected): %s" % type(e).__name__)
  399. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  400. # remove the moddn aci
  401. _bind_manager(topology_m2)
  402. _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_DELETE,
  403. target_from=STAGING_DN, target_to=PRODUCTION_DN)
  404. _bind_normal(topology_m2)
  405. #
  406. # add the 'add' right to the production DN
  407. # Then do a successful moddn
  408. #
  409. ACI_ALLOW = "(version 3.0; acl \"ADD rights to allow moddn\"; allow (add)"
  410. ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
  411. ACI_BODY = ACI_ALLOW + ACI_SUBJECT
  412. _bind_manager(topology_m2)
  413. prod.add('aci', ACI_BODY)
  414. _write_aci_staging(topology_m2, mod_type=ldap.MOD_ADD)
  415. _bind_normal(topology_m2)
  416. topology_m2.ms["master1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  417. topology_m2.ms["master1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
  418. _bind_manager(topology_m2)
  419. prod.remove('aci', ACI_BODY)
  420. _write_aci_staging(topology_m2, mod_type=ldap.MOD_DELETE)
  421. _bind_normal(topology_m2)
  422. #############
  423. # Now do tests with support of moddn aci
  424. #############
  425. topology_m2.ms["master1"].log.info("Enable the moddn right")
  426. _bind_manager(topology_m2)
  427. topology_m2.ms["master1"].config.set(CONFIG_MODDN_ACI_ATTR, 'on')
  428. topology_m2.ms["master1"].log.info("\n\n######## MOVE staging -> Prod (10) ########\n")
  429. _bind_normal(topology_m2)
  430. old_rdn = "uid=%s10" % NEW_ACCOUNT
  431. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  432. new_rdn = old_rdn
  433. new_superior = PRODUCTION_DN
  434. #
  435. # Try to rename without the appropriate ACI => INSUFFICIENT_ACCESS
  436. #
  437. try:
  438. topology_m2.ms["master1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  439. topology_m2.ms["master1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
  440. assert 0
  441. except AssertionError:
  442. topology_m2.ms["master1"].log.info(
  443. "Exception (not really expected exception but that is fine as it fails to rename)")
  444. except Exception as e:
  445. topology_m2.ms["master1"].log.info("Exception (expected): %s" % type(e).__name__)
  446. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  447. #
  448. # add the 'add' right to the production DN
  449. # Then do a failing moddn
  450. #
  451. ACI_ALLOW = "(version 3.0; acl \"ADD rights to allow moddn\"; allow (add)"
  452. ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
  453. ACI_BODY = ACI_ALLOW + ACI_SUBJECT
  454. _bind_manager(topology_m2)
  455. prod.add('aci', ACI_BODY)
  456. _write_aci_staging(topology_m2, mod_type=ldap.MOD_ADD)
  457. _bind_normal(topology_m2)
  458. try:
  459. topology_m2.ms["master1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  460. topology_m2.ms["master1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
  461. assert 0
  462. except AssertionError:
  463. topology_m2.ms["master1"].log.info(
  464. "Exception (not really expected exception but that is fine as it fails to rename)")
  465. except Exception as e:
  466. topology_m2.ms["master1"].log.info("Exception (expected): %s" % type(e).__name__)
  467. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  468. _bind_manager(topology_m2)
  469. prod.remove('aci', ACI_BODY)
  470. _write_aci_staging(topology_m2, mod_type=ldap.MOD_DELETE)
  471. _bind_normal(topology_m2)
  472. # Add the moddn aci that will be evaluated because of the config flag
  473. topology_m2.ms["master1"].log.info("\n\n######## MOVE to and from equality filter ########\n")
  474. _bind_manager(topology_m2)
  475. _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_ADD,
  476. target_from=STAGING_DN, target_to=PRODUCTION_DN)
  477. _bind_normal(topology_m2)
  478. topology_m2.ms["master1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  479. topology_m2.ms["master1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
  480. # remove the moddn aci
  481. _bind_manager(topology_m2)
  482. _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_DELETE,
  483. target_from=STAGING_DN, target_to=PRODUCTION_DN)
  484. _bind_normal(topology_m2)
  485. def test_moddn_prod_staging(topology_m2, moddn_setup):
  486. """This test checks that we can move ACCOUNT11 from staging to prod
  487. but not move back ACCOUNT11 from prod to staging
  488. :id: 2b061e92-483f-4399-9f56-8d1c1898b043
  489. :setup: MMR with two masters,
  490. M1 - staging DIT
  491. M2 - production DIT
  492. add test accounts in staging DIT
  493. :steps:
  494. 1. Try to rename without the appropriate ACI
  495. 2. Try to MOD with the ACI from stage to production
  496. 3. Try to move back the entry to staging from production
  497. :expectedresults:
  498. 1. It should fail due to INSUFFICIENT_ACCESS
  499. 2. It should pass
  500. 3. It should fail due to INSUFFICIENT_ACCESS
  501. """
  502. topology_m2.ms["master1"].log.info("\n\n######## MOVE staging -> Prod (11) ########\n")
  503. _bind_normal(topology_m2)
  504. old_rdn = "uid=%s11" % NEW_ACCOUNT
  505. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  506. new_rdn = old_rdn
  507. new_superior = PRODUCTION_DN
  508. #
  509. # Try to rename without the appropriate ACI => INSUFFICIENT_ACCESS
  510. #
  511. try:
  512. topology_m2.ms["master1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  513. topology_m2.ms["master1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
  514. assert 0
  515. except AssertionError:
  516. topology_m2.ms["master1"].log.info(
  517. "Exception (not really expected exception but that is fine as it fails to rename)")
  518. except Exception as e:
  519. topology_m2.ms["master1"].log.info("Exception (expected): %s" % type(e).__name__)
  520. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  521. # successful MOD with the ACI
  522. topology_m2.ms["master1"].log.info("\n\n######## MOVE to and from equality filter ########\n")
  523. _bind_manager(topology_m2)
  524. _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_ADD,
  525. target_from=STAGING_DN, target_to=PRODUCTION_DN)
  526. _bind_normal(topology_m2)
  527. topology_m2.ms["master1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  528. topology_m2.ms["master1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
  529. # Now check we can not move back the entry to staging
  530. old_rdn = "uid=%s11" % NEW_ACCOUNT
  531. old_dn = "%s,%s" % (old_rdn, PRODUCTION_DN)
  532. new_rdn = old_rdn
  533. new_superior = STAGING_DN
  534. # add the write right because we want to check the moddn
  535. _bind_manager(topology_m2)
  536. _write_aci_production(topology_m2, mod_type=ldap.MOD_ADD)
  537. _bind_normal(topology_m2)
  538. try:
  539. topology_m2.ms["master1"].log.info("Try to move back MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  540. topology_m2.ms["master1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
  541. assert 0
  542. except AssertionError:
  543. topology_m2.ms["master1"].log.info(
  544. "Exception (not really expected exception but that is fine as it fails to rename)")
  545. except Exception as e:
  546. topology_m2.ms["master1"].log.info("Exception (expected): %s" % type(e).__name__)
  547. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  548. _bind_manager(topology_m2)
  549. _write_aci_production(topology_m2, mod_type=ldap.MOD_DELETE)
  550. _bind_normal(topology_m2)
  551. # successful MOD with the both ACI
  552. _bind_manager(topology_m2)
  553. _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_DELETE,
  554. target_from=STAGING_DN, target_to=PRODUCTION_DN)
  555. _bind_normal(topology_m2)
  556. def test_check_repl_M2_to_M1(topology_m2, moddn_setup):
  557. """Checks that replication is still working M2->M1, using ACCOUNT12
  558. :id: 08ac131d-34b7-443f-aacd-23025bbd7de1
  559. :setup: MMR with two masters,
  560. M1 - staging DIT
  561. M2 - production DIT
  562. add test accounts in staging DIT
  563. :steps:
  564. 1. Add an entry in M2
  565. 2. Search entry on M1
  566. :expectedresults:
  567. 1. It should pass
  568. 2. It should pass
  569. """
  570. topology_m2.ms["master1"].log.info("Bind as %s (M2)" % DN_DM)
  571. topology_m2.ms["master2"].simple_bind_s(DN_DM, PASSWORD)
  572. rdn = "uid=%s12" % NEW_ACCOUNT
  573. dn = "%s,%s" % (rdn, STAGING_DN)
  574. new_account = UserAccount(topology_m2.ms["master2"], dn)
  575. # First wait for the ACCOUNT19 entry being replicated on M2
  576. loop = 0
  577. while loop <= 10:
  578. try:
  579. ent = topology_m2.ms["master2"].getEntry(dn, ldap.SCOPE_BASE, "(objectclass=*)")
  580. break
  581. except ldap.NO_SUCH_OBJECT:
  582. time.sleep(1)
  583. loop += 1
  584. assert loop <= 10
  585. attribute = 'description'
  586. tested_value = b'Hello world'
  587. topology_m2.ms["master1"].log.info("Update (M2) %s (%s)" % (dn, attribute))
  588. new_account.add(attribute, tested_value)
  589. loop = 0
  590. while loop <= 10:
  591. ent = topology_m2.ms["master1"].getEntry(dn, ldap.SCOPE_BASE, "(objectclass=*)")
  592. assert ent is not None
  593. if ent.hasAttr(attribute) and (ent.getValue(attribute) == tested_value):
  594. break
  595. time.sleep(1)
  596. loop += 1
  597. assert loop < 10
  598. topology_m2.ms["master1"].log.info("Update %s (%s) replicated on M1" % (dn, attribute))
  599. def test_moddn_staging_prod_except(topology_m2, moddn_setup):
  600. """This test case MOVE entry NEW_ACCOUNT13 from staging to prod
  601. but fails to move entry NEW_ACCOUNT14 from staging to prod_except
  602. :id: 02d34f4c-8574-428d-b43f-31227426392c
  603. :setup: MMR with two masters,
  604. M1 - staging DIT
  605. M2 - production DIT
  606. add test accounts in staging DIT
  607. :steps:
  608. 1. Try to move entry staging -> Prod
  609. without the appropriate ACI
  610. 2. Do MOD with the appropriate ACI
  611. 3. Try to move an entry under Prod/Except from stage
  612. 4. Try to do MOD with appropriate ACI
  613. :expectedresults:
  614. 1. It should fail due to INSUFFICIENT_ACCESS
  615. 2. It should pass
  616. 3. It should fail due to INSUFFICIENT_ACCESS
  617. 4. It should pass
  618. """
  619. topology_m2.ms["master1"].log.info("\n\n######## MOVE staging -> Prod (13) ########\n")
  620. _bind_normal(topology_m2)
  621. old_rdn = "uid=%s13" % NEW_ACCOUNT
  622. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  623. new_rdn = old_rdn
  624. new_superior = PRODUCTION_DN
  625. #
  626. # Try to rename without the appropriate ACI => INSUFFICIENT_ACCESS
  627. #
  628. try:
  629. topology_m2.ms["master1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  630. topology_m2.ms["master1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
  631. assert 0
  632. except AssertionError:
  633. topology_m2.ms["master1"].log.info(
  634. "Exception (not really expected exception but that is fine as it fails to rename)")
  635. except Exception as e:
  636. topology_m2.ms["master1"].log.info("Exception (expected): %s" % type(e).__name__)
  637. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  638. # successful MOD with the ACI
  639. topology_m2.ms["master1"].log.info("\n\n######## MOVE to and from equality filter ########\n")
  640. _bind_manager(topology_m2)
  641. _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_ADD,
  642. target_from=STAGING_DN, target_to=PRODUCTION_DN)
  643. _moddn_aci_deny_tree(topology_m2, mod_type=ldap.MOD_ADD)
  644. _bind_normal(topology_m2)
  645. topology_m2.ms["master1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  646. topology_m2.ms["master1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
  647. #
  648. # Now try to move an entry under except
  649. #
  650. topology_m2.ms["master1"].log.info("\n\n######## MOVE staging -> Prod/Except (14) ########\n")
  651. old_rdn = "uid=%s14" % NEW_ACCOUNT
  652. old_dn = "%s,%s" % (old_rdn, STAGING_DN)
  653. new_rdn = old_rdn
  654. new_superior = PROD_EXCEPT_DN
  655. try:
  656. topology_m2.ms["master1"].log.info("Try to MODDN %s -> %s,%s" % (old_dn, new_rdn, new_superior))
  657. topology_m2.ms["master1"].rename_s(old_dn, new_rdn, newsuperior=new_superior)
  658. assert 0
  659. except AssertionError:
  660. topology_m2.ms["master1"].log.info(
  661. "Exception (not really expected exception but that is fine as it fails to rename)")
  662. except Exception as e:
  663. topology_m2.ms["master1"].log.info("Exception (expected): %s" % type(e).__name__)
  664. assert isinstance(e, ldap.INSUFFICIENT_ACCESS)
  665. # successful MOD with the both ACI
  666. _bind_manager(topology_m2)
  667. _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_DELETE,
  668. target_from=STAGING_DN, target_to=PRODUCTION_DN)
  669. _moddn_aci_deny_tree(topology_m2, mod_type=ldap.MOD_DELETE)
  670. _bind_normal(topology_m2)
  671. def test_mode_default_ger_no_moddn(topology_m2, moddn_setup):
  672. """mode moddn_aci : Check Get Effective Rights Controls for entries
  673. :id: f4785d73-3b14-49c0-b981-d6ff96fa3496
  674. :setup: MMR with two masters,
  675. M1 - staging DIT
  676. M2 - production DIT
  677. add test accounts in staging DIT
  678. :steps:
  679. 1. Search for GER controls on M1
  680. 2. Check 'n' is not in the entryLevelRights
  681. :expectedresults:
  682. 1. It should pass
  683. 2. It should pass
  684. """
  685. topology_m2.ms["master1"].log.info("\n\n######## mode moddn_aci : GER no moddn ########\n")
  686. request_ctrl = GetEffectiveRightsControl(criticality=True,
  687. authzId=ensure_bytes("dn: " + BIND_DN))
  688. msg_id = topology_m2.ms["master1"].search_ext(PRODUCTION_DN,
  689. ldap.SCOPE_SUBTREE,
  690. "objectclass=*",
  691. serverctrls=[request_ctrl])
  692. rtype, rdata, rmsgid, response_ctrl = topology_m2.ms["master1"].result3(msg_id)
  693. # ger={}
  694. value = ''
  695. for dn, attrs in rdata:
  696. topology_m2.ms["master1"].log.info("dn: %s" % dn)
  697. value = attrs['entryLevelRights'][0]
  698. topology_m2.ms["master1"].log.info("######## entryLevelRights: %r" % value)
  699. assert b'n' not in value
  700. def test_mode_default_ger_with_moddn(topology_m2, moddn_setup):
  701. """This test case adds the moddn aci and check ger contains 'n'
  702. :id: a752a461-432d-483a-89c0-dfb34045a969
  703. :setup: MMR with two masters,
  704. M1 - staging DIT
  705. M2 - production DIT
  706. add test accounts in staging DIT
  707. :steps:
  708. 1. Add moddn ACI on M2
  709. 2. Search for GER controls on M1
  710. 3. Check entryLevelRights value for entries
  711. 4. Check 'n' is in the entryLevelRights
  712. :expectedresults:
  713. 1. It should pass
  714. 2. It should pass
  715. 3. It should pass
  716. 4. It should pass
  717. """
  718. topology_m2.ms["master1"].log.info("\n\n######## mode moddn_aci: GER with moddn ########\n")
  719. # successful MOD with the ACI
  720. _bind_manager(topology_m2)
  721. _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_ADD,
  722. target_from=STAGING_DN, target_to=PRODUCTION_DN)
  723. _bind_normal(topology_m2)
  724. request_ctrl = GetEffectiveRightsControl(criticality=True,
  725. authzId=ensure_bytes("dn: " + BIND_DN))
  726. msg_id = topology_m2.ms["master1"].search_ext(PRODUCTION_DN,
  727. ldap.SCOPE_SUBTREE,
  728. "objectclass=*",
  729. serverctrls=[request_ctrl])
  730. rtype, rdata, rmsgid, response_ctrl = topology_m2.ms["master1"].result3(msg_id)
  731. # ger={}
  732. value = ''
  733. for dn, attrs in rdata:
  734. topology_m2.ms["master1"].log.info("dn: %s" % dn)
  735. value = attrs['entryLevelRights'][0]
  736. topology_m2.ms["master1"].log.info("######## entryLevelRights: %r" % value)
  737. assert b'n' in value
  738. # successful MOD with the both ACI
  739. _bind_manager(topology_m2)
  740. _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_DELETE,
  741. target_from=STAGING_DN, target_to=PRODUCTION_DN)
  742. _bind_normal(topology_m2)
  743. def test_mode_legacy_ger_no_moddn1(topology_m2, moddn_setup):
  744. """This test checks mode legacy : GER no moddn
  745. :id: e783e05b-d0d0-4fd4-9572-258a81b7bd24
  746. :setup: MMR with two masters,
  747. M1 - staging DIT
  748. M2 - production DIT
  749. add test accounts in staging DIT
  750. :steps:
  751. 1. Disable ACI checks - set nsslapd-moddn-aci: off
  752. 2. Search for GER controls on M1
  753. 3. Check entryLevelRights value for entries
  754. 4. Check 'n' is not in the entryLevelRights
  755. :expectedresults:
  756. 1. It should pass
  757. 2. It should pass
  758. 3. It should pass
  759. 4. It should pass
  760. """
  761. topology_m2.ms["master1"].log.info("\n\n######## Disable the moddn aci mod ########\n")
  762. _bind_manager(topology_m2)
  763. topology_m2.ms["master1"].config.set(CONFIG_MODDN_ACI_ATTR, 'off')
  764. topology_m2.ms["master1"].log.info("\n\n######## mode legacy 1: GER no moddn ########\n")
  765. request_ctrl = GetEffectiveRightsControl(criticality=True, authzId=ensure_bytes("dn: " + BIND_DN))
  766. msg_id = topology_m2.ms["master1"].search_ext(PRODUCTION_DN,
  767. ldap.SCOPE_SUBTREE,
  768. "objectclass=*",
  769. serverctrls=[request_ctrl])
  770. rtype, rdata, rmsgid, response_ctrl = topology_m2.ms["master1"].result3(msg_id)
  771. # ger={}
  772. value = ''
  773. for dn, attrs in rdata:
  774. topology_m2.ms["master1"].log.info("dn: %s" % dn)
  775. value = attrs['entryLevelRights'][0]
  776. topology_m2.ms["master1"].log.info("######## entryLevelRights: %r" % value)
  777. assert b'n' not in value
  778. def test_mode_legacy_ger_no_moddn2(topology_m2, moddn_setup):
  779. """This test checks mode legacy : GER no moddn
  780. :id: af87e024-1744-4f1d-a2d3-ea2687e2351d
  781. :setup: MMR with two masters,
  782. M1 - staging DIT
  783. M2 - production DIT
  784. add test accounts in staging DIT
  785. :steps:
  786. 1. Disable ACI checks - set nsslapd-moddn-aci: off
  787. 2. Add moddn ACI on M1
  788. 3. Search for GER controls on M1
  789. 4. Check entryLevelRights value for entries
  790. 5. Check 'n' is not in the entryLevelRights
  791. :expectedresults:
  792. 1. It should pass
  793. 2. It should pass
  794. 3. It should pass
  795. 4. It should be pass
  796. 5. It should pass
  797. """
  798. topology_m2.ms["master1"].log.info("\n\n######## Disable the moddn aci mod ########\n")
  799. _bind_manager(topology_m2)
  800. topology_m2.ms["master1"].config.set(CONFIG_MODDN_ACI_ATTR, 'off')
  801. topology_m2.ms["master1"].log.info("\n\n######## mode legacy 2: GER no moddn ########\n")
  802. # successful MOD with the ACI
  803. _bind_manager(topology_m2)
  804. _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_ADD,
  805. target_from=STAGING_DN, target_to=PRODUCTION_DN)
  806. _bind_normal(topology_m2)
  807. request_ctrl = GetEffectiveRightsControl(criticality=True,
  808. authzId=ensure_bytes("dn: " + BIND_DN))
  809. msg_id = topology_m2.ms["master1"].search_ext(PRODUCTION_DN,
  810. ldap.SCOPE_SUBTREE,
  811. "objectclass=*",
  812. serverctrls=[request_ctrl])
  813. rtype, rdata, rmsgid, response_ctrl = topology_m2.ms["master1"].result3(msg_id)
  814. # ger={}
  815. value = ''
  816. for dn, attrs in rdata:
  817. topology_m2.ms["master1"].log.info("dn: %s" % dn)
  818. value = attrs['entryLevelRights'][0]
  819. topology_m2.ms["master1"].log.info("######## entryLevelRights: %r" % value)
  820. assert b'n' not in value
  821. # successful MOD with the both ACI
  822. _bind_manager(topology_m2)
  823. _moddn_aci_staging_to_production(topology_m2, mod_type=ldap.MOD_DELETE,
  824. target_from=STAGING_DN, target_to=PRODUCTION_DN)
  825. _bind_normal(topology_m2)
  826. def test_mode_legacy_ger_with_moddn(topology_m2, moddn_setup):
  827. """This test checks mode legacy : GER with moddn
  828. :id: 37c1e537-1b5d-4fab-b62a-50cd8c5b3493
  829. :setup: MMR with two masters,
  830. M1 - staging DIT
  831. M2 - production DIT
  832. add test accounts in staging DIT
  833. :steps:
  834. 1. Disable ACI checks - set nsslapd-moddn-aci: off
  835. 2. Add moddn ACI on M1
  836. 3. Search for GER controls on M1
  837. 4. Check entryLevelRights value for entries
  838. 5. Check 'n' is in the entryLevelRights
  839. 6. Try MOD with the both ACI
  840. :expectedresults:
  841. 1. It should pass
  842. 2. It should pass
  843. 3. It should pass
  844. 4. It should pass
  845. 5. It should pass
  846. 6. It should pass
  847. """
  848. suffix = Domain(topology_m2.ms["master1"], SUFFIX)
  849. topology_m2.ms["master1"].log.info("\n\n######## Disable the moddn aci mod ########\n")
  850. _bind_manager(topology_m2)
  851. topology_m2.ms["master1"].config.set(CONFIG_MODDN_ACI_ATTR, 'off')
  852. topology_m2.ms["master1"].log.info("\n\n######## mode legacy : GER with moddn ########\n")
  853. # being allowed to read/write the RDN attribute use to allow the RDN
  854. ACI_TARGET = "(target = \"ldap:///%s\")(targetattr=\"uid\")" % (PRODUCTION_DN)
  855. ACI_ALLOW = "(version 3.0; acl \"MODDN production changing the RDN attribute\"; allow (read,search,write)"
  856. ACI_SUBJECT = " userdn = \"ldap:///%s\";)" % BIND_DN
  857. ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
  858. # successful MOD with the ACI
  859. _bind_manager(topology_m2)
  860. suffix.add('aci', ACI_BODY)
  861. _bind_normal(topology_m2)
  862. request_ctrl = GetEffectiveRightsControl(criticality=True, authzId=ensure_bytes("dn: " + BIND_DN))
  863. msg_id = topology_m2.ms["master1"].search_ext(PRODUCTION_DN,
  864. ldap.SCOPE_SUBTREE,
  865. "objectclass=*",
  866. serverctrls=[request_ctrl])
  867. rtype, rdata, rmsgid, response_ctrl = topology_m2.ms["master1"].result3(msg_id)
  868. # ger={}
  869. value = ''
  870. for dn, attrs in rdata:
  871. topology_m2.ms["master1"].log.info("dn: %s" % dn)
  872. value = attrs['entryLevelRights'][0]
  873. topology_m2.ms["master1"].log.info("######## entryLevelRights: %r" % value)
  874. assert b'n' in value
  875. # successful MOD with the both ACI
  876. _bind_manager(topology_m2)
  877. suffix.remove('aci', ACI_BODY)
  878. # _bind_normal(topology_m2)
  879. @pytest.fixture(scope="module")
  880. def rdn_write_setup(topology_m2):
  881. topology_m2.ms["master1"].log.info("\n\n######## Add entry tuser ########\n")
  882. topology_m2.ms["master1"].add_s(Entry((SRC_ENTRY_DN, {
  883. 'objectclass': "top person".split(),
  884. 'sn': SRC_ENTRY_CN,
  885. 'cn': SRC_ENTRY_CN})))
  886. def test_rdn_write_get_ger(topology_m2, rdn_write_setup):
  887. """This test checks GER rights for anonymous
  888. :id: d5d85f87-b53d-4f50-8fa6-a9e55c75419b
  889. :setup: MMR with two masters,
  890. Add entry tuser
  891. :steps:
  892. 1. Search for GER controls on M1
  893. 2. Check entryLevelRights value for entries
  894. 3. Check 'n' is not in the entryLevelRights
  895. :expectedresults:
  896. 1. It should pass
  897. 2. It should be pass
  898. 3. It should pass
  899. """
  900. ANONYMOUS_DN = ""
  901. topology_m2.ms["master1"].log.info("\n\n######## GER rights for anonymous ########\n")
  902. request_ctrl = GetEffectiveRightsControl(criticality=True,
  903. authzId=ensure_bytes("dn:" + ANONYMOUS_DN))
  904. msg_id = topology_m2.ms["master1"].search_ext(SUFFIX,
  905. ldap.SCOPE_SUBTREE,
  906. "objectclass=*",
  907. serverctrls=[request_ctrl])
  908. rtype, rdata, rmsgid, response_ctrl = topology_m2.ms["master1"].result3(msg_id)
  909. value = ''
  910. for dn, attrs in rdata:
  911. topology_m2.ms["master1"].log.info("dn: %s" % dn)
  912. for value in attrs['entryLevelRights']:
  913. topology_m2.ms["master1"].log.info("######## entryLevelRights: %r" % value)
  914. assert b'n' not in value
  915. def test_rdn_write_modrdn_anonymous(topology_m2, rdn_write_setup):
  916. """Tests anonymous user for modrdn
  917. :id: fc07be23-3341-44ab-a53c-c68c5f9569c7
  918. :setup: MMR with two masters,
  919. Add entry tuser
  920. :steps:
  921. 1. Bind as anonymous user
  922. 2. Try to perform MODRDN operation (SRC_ENTRY_DN -> DST_ENTRY_CN)
  923. 3. Try to search DST_ENTRY_CN
  924. :expectedresults:
  925. 1. It should pass
  926. 2. It should fails with INSUFFICIENT_ACCESS
  927. 3. It should fails with NO_SUCH_OBJECT
  928. """
  929. ANONYMOUS_DN = ""
  930. topology_m2.ms["master1"].close()
  931. topology_m2.ms["master1"].binddn = ANONYMOUS_DN
  932. topology_m2.ms["master1"].open()
  933. msg_id = topology_m2.ms["master1"].search_ext("", ldap.SCOPE_BASE, "objectclass=*")
  934. rtype, rdata, rmsgid, response_ctrl = topology_m2.ms["master1"].result3(msg_id)
  935. for dn, attrs in rdata:
  936. topology_m2.ms["master1"].log.info("dn: %s" % dn)
  937. for attr in attrs:
  938. topology_m2.ms["master1"].log.info("######## %r: %r" % (attr, attrs[attr]))
  939. try:
  940. topology_m2.ms["master1"].rename_s(SRC_ENTRY_DN, "cn=%s" % DST_ENTRY_CN, delold=True)
  941. except Exception as e:
  942. topology_m2.ms["master1"].log.info("Exception (expected): %s" % type(e).__name__)
  943. isinstance(e, ldap.INSUFFICIENT_ACCESS)
  944. try:
  945. topology_m2.ms["master1"].getEntry(DST_ENTRY_DN, ldap.SCOPE_BASE, "objectclass=*")
  946. assert False
  947. except Exception as e:
  948. topology_m2.ms["master1"].log.info("The entry was not renamed (expected)")
  949. isinstance(e, ldap.NO_SUCH_OBJECT)
  950. _bind_manager(topology_m2)
  951. if __name__ == '__main__':
  952. # Run isolated
  953. # -s for DEBUG mode
  954. CURRENT_FILE = os.path.realpath(__file__)
  955. pytest.main("-s %s" % CURRENT_FILE)