modify_test.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2019 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. import pytest, os, ldap
  9. from lib389._constants import DEFAULT_SUFFIX, PW_DM
  10. from lib389.idm.user import UserAccount
  11. from lib389.idm.account import Anonymous
  12. from lib389.idm.group import Group, UniqueGroup
  13. from lib389.idm.organizationalunit import OrganizationalUnit
  14. from lib389.idm.group import Groups
  15. from lib389.topologies import topology_st as topo
  16. from lib389.idm.domain import Domain
  17. pytestmark = pytest.mark.tier1
  18. CONTAINER_1_DELADD = "ou=Product Development,{}".format(DEFAULT_SUFFIX)
  19. CONTAINER_2_DELADD = "ou=Accounting,{}".format(DEFAULT_SUFFIX)
  20. USER_DELADD = "cn=Jeff Vedder,{}".format(CONTAINER_1_DELADD)
  21. USER_WITH_ACI_DELADD = "cn=Sam Carter,{}".format(CONTAINER_2_DELADD)
  22. KIRSTENVAUGHAN = "cn=Kirsten Vaughan, ou=Human Resources, {}".format(DEFAULT_SUFFIX)
  23. HUMAN_OU_GLOBAL = "ou=Human Resources,{}".format(DEFAULT_SUFFIX)
  24. @pytest.fixture(scope="function")
  25. def cleanup_tree(request, topo):
  26. def fin():
  27. for i in [USER_DELADD, USER_WITH_ACI_DELADD, KIRSTENVAUGHAN, CONTAINER_1_DELADD, CONTAINER_2_DELADD, HUMAN_OU_GLOBAL]:
  28. try:
  29. UserAccount(topo.standalone, i).delete()
  30. except:
  31. pass
  32. request.addfinalizer(fin)
  33. @pytest.fixture(scope="function")
  34. def aci_of_user(request, topo):
  35. # Add anonymous access aci
  36. ACI_TARGET = "(targetattr=\"*\")(target = \"ldap:///%s\")" % (DEFAULT_SUFFIX)
  37. ACI_ALLOW = "(version 3.0; acl \"Anonymous Read access\"; allow (read,search,compare)"
  38. ACI_SUBJECT = "(userdn=\"ldap:///anyone\");)"
  39. ANON_ACI = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
  40. suffix = Domain(topo.standalone, DEFAULT_SUFFIX)
  41. try:
  42. suffix.add('aci', ANON_ACI)
  43. except ldap.TYPE_OR_VALUE_EXISTS:
  44. pass
  45. aci_list = suffix.get_attr_vals('aci')
  46. def finofaci():
  47. domain = Domain(topo.standalone, DEFAULT_SUFFIX)
  48. domain.set('aci', None)
  49. for i in aci_list:
  50. domain.add("aci", i)
  51. request.addfinalizer(finofaci)
  52. def test_allow_write_access_to_targetattr_with_a_single_attribute(
  53. topo, aci_of_user, cleanup_tree):
  54. """Modify Test 1 Allow write access to targetattr with a single attribute
  55. :id: 620d7b82-7abf-11e8-a4db-8c16451d917b
  56. :setup: server
  57. :steps:
  58. 1. Add test entry
  59. 2. Add ACI
  60. 3. User should follow ACI role
  61. :expectedresults:
  62. 1. Entry should be added
  63. 2. Operation should succeed
  64. 3. Operation should succeed
  65. """
  66. ACI_BODY = '(targetattr = "title")(version 3.0; acl "ACI NAME"; allow (write) (userdn = "ldap:///anyone") ;)'
  67. Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
  68. ou = OrganizationalUnit(topo.standalone, "ou=Product Development,{}".format(DEFAULT_SUFFIX))
  69. ou.create(properties={'ou': 'Product Development'})
  70. properties = {
  71. 'uid': 'Jeff Vedder',
  72. 'cn': 'Jeff Vedder',
  73. 'sn': 'user',
  74. 'uidNumber': '1000',
  75. 'gidNumber': '2000',
  76. 'homeDirectory': '/home/' + 'JeffVedder',
  77. 'userPassword': PW_DM
  78. }
  79. user = UserAccount(topo.standalone, "cn=Jeff Vedder,ou=Product Development,{}".format(DEFAULT_SUFFIX))
  80. user.create(properties=properties)
  81. # Allow write access to targetattr with a single attribute
  82. conn = Anonymous(topo.standalone).bind()
  83. ua = UserAccount(conn, USER_DELADD)
  84. ua.add("title", "Architect")
  85. assert ua.get_attr_val('title')
  86. ua.remove("title", "Architect")
  87. def test_allow_write_access_to_targetattr_with_multiple_attibutes(
  88. topo, aci_of_user, cleanup_tree):
  89. """Modify Test 2 Allow write access to targetattr with multiple attibutes
  90. :id: 6b9f05c6-7abf-11e8-9ba1-8c16451d917b
  91. :setup: server
  92. :steps:
  93. 1. Add test entry
  94. 2. Add ACI
  95. 3. User should follow ACI role
  96. :expectedresults:
  97. 1. Entry should be added
  98. 2. Operation should succeed
  99. 3. Operation should succeed
  100. """
  101. ACI_BODY = '(targetattr = "telephonenumber || roomnumber")(version 3.0; acl "ACI NAME"; allow (write) (userdn = "ldap:///anyone") ;)'
  102. Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
  103. ou = OrganizationalUnit(topo.standalone, "ou=Product Development,{}".format(DEFAULT_SUFFIX))
  104. ou.create(properties={'ou': 'Product Development'})
  105. properties = {
  106. 'uid': 'Jeff Vedder',
  107. 'cn': 'Jeff Vedder',
  108. 'sn': 'user',
  109. 'uidNumber': '1000',
  110. 'gidNumber': '2000',
  111. 'homeDirectory': '/home/' + 'JeffVedder',
  112. 'userPassword': PW_DM
  113. }
  114. user = UserAccount(topo.standalone, "cn=Jeff Vedder,ou=Product Development,{}".format(DEFAULT_SUFFIX))
  115. user.create(properties=properties)
  116. # Allow write access to targetattr with multiple attibutes
  117. conn = Anonymous(topo.standalone).bind()
  118. ua = UserAccount(conn, USER_DELADD)
  119. ua.add("telephonenumber", "+1 408 555 1212")
  120. assert ua.get_attr_val('telephonenumber')
  121. ua.add("roomnumber", "101")
  122. assert ua.get_attr_val('roomnumber')
  123. def test_allow_write_access_to_userdn_all(topo, aci_of_user, cleanup_tree):
  124. """Modify Test 3 Allow write access to userdn 'all'
  125. :id: 70c58818-7abf-11e8-afa1-8c16451d917b
  126. :setup: server
  127. :steps:
  128. 1. Add test entry
  129. 2. Add ACI
  130. 3. User should follow ACI role
  131. :expectedresults:
  132. 1. Entry should be added
  133. 2. Operation should succeed
  134. 3. Operation should succeed
  135. """
  136. ACI_BODY = '(targetattr = "*")(version 3.0; acl "ACI NAME"; allow (write) (userdn = "ldap:///all") ;)'
  137. Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
  138. for i in ['Product Development', 'Accounting']:
  139. ou = OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX))
  140. ou.create(properties={'ou': i})
  141. for i in ['Jeff Vedder,ou=Product Development', 'Sam Carter,ou=Accounting']:
  142. properties = {
  143. 'uid': i,
  144. 'cn': i,
  145. 'sn': 'user',
  146. 'uidNumber': '1000',
  147. 'gidNumber': '2000',
  148. 'homeDirectory': '/home/' + i,
  149. 'userPassword': PW_DM
  150. }
  151. user = UserAccount(topo.standalone, "cn={},{}".format(i, DEFAULT_SUFFIX))
  152. user.create(properties=properties)
  153. # Allow write access to userdn 'all'
  154. conn = Anonymous(topo.standalone).bind()
  155. with pytest.raises(ldap.INSUFFICIENT_ACCESS):
  156. UserAccount(conn, USER_DELADD).add("title", "Architect")
  157. conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
  158. UserAccount(conn, USER_DELADD).add("title", "Architect")
  159. assert UserAccount(conn, USER_DELADD).get_attr_val('title')
  160. def test_allow_write_access_to_userdn_with_wildcards_in_dn(
  161. topo, aci_of_user, cleanup_tree):
  162. """Modify Test 4 Allow write access to userdn with wildcards in DN
  163. :id: 766c2312-7abf-11e8-b57d-8c16451d917b
  164. :setup: server
  165. :steps:
  166. 1. Add test entry
  167. 2. Add ACI
  168. 3. User should follow ACI role
  169. :expectedresults:
  170. 1. Entry should be added
  171. 2. Operation should succeed
  172. 3. Operation should succeed
  173. """
  174. ACI_BODY = '(targetattr = "*")(version 3.0; acl "ACI NAME"; allow (write)(userdn = "ldap:///cn=*, ou=Product Development,{}") ;)'.format(DEFAULT_SUFFIX)
  175. Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
  176. ou = OrganizationalUnit(topo.standalone, "ou=Product Development,{}".format(DEFAULT_SUFFIX))
  177. ou.create(properties={'ou': 'Product Development'})
  178. properties = {
  179. 'uid': 'Jeff Vedder',
  180. 'cn': 'Jeff Vedder',
  181. 'sn': 'user',
  182. 'uidNumber': '1000',
  183. 'gidNumber': '2000',
  184. 'homeDirectory': '/home/' + 'JeffVedder',
  185. 'userPassword': PW_DM
  186. }
  187. user = UserAccount(topo.standalone, "cn=Jeff Vedder,ou=Product Development,{}".format(DEFAULT_SUFFIX))
  188. user.create(properties=properties)
  189. conn = UserAccount(topo.standalone, USER_DELADD).bind(PW_DM)
  190. # Allow write access to userdn with wildcards in DN
  191. ua = UserAccount(conn, USER_DELADD)
  192. ua.add("title", "Architect")
  193. assert ua.get_attr_val('title')
  194. def test_allow_write_access_to_userdn_with_multiple_dns(topo, aci_of_user, cleanup_tree):
  195. """Modify Test 5 Allow write access to userdn with multiple DNs
  196. :id: 7aae760a-7abf-11e8-bc3a-8c16451d917b
  197. :setup: server
  198. :steps:
  199. 1. Add test entry
  200. 2. Add ACI
  201. 3. User should follow ACI role
  202. :expectedresults:
  203. 1. Entry should be added
  204. 2. Operation should succeed
  205. 3. Operation should succeed
  206. """
  207. ACI_BODY = '(targetattr = "*")(version 3.0; acl "ACI NAME"; allow (write)(userdn = "ldap:///{} || ldap:///{}") ;)'.format(USER_DELADD, USER_WITH_ACI_DELADD)
  208. Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
  209. for i in ['Product Development', 'Accounting', 'Human Resources']:
  210. ou = OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX))
  211. ou.create(properties={'ou': i})
  212. for i in ['Jeff Vedder,ou=Product Development', 'Sam Carter,ou=Accounting', 'Kirsten Vaughan, ou=Human Resources']:
  213. properties = {
  214. 'uid': i,
  215. 'cn': i,
  216. 'sn': 'user',
  217. 'uidNumber': '1000',
  218. 'gidNumber': '2000',
  219. 'homeDirectory': '/home/' + i,
  220. 'userPassword': PW_DM
  221. }
  222. user = UserAccount(topo.standalone, "cn={},{}".format(i, DEFAULT_SUFFIX))
  223. user.create(properties=properties)
  224. conn = UserAccount(topo.standalone, USER_DELADD).bind(PW_DM)
  225. # Allow write access to userdn with multiple DNs
  226. ua = UserAccount(conn, KIRSTENVAUGHAN)
  227. ua.add("title", "Architect")
  228. conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
  229. # Allow write access to userdn with multiple DNs
  230. ua = UserAccount(conn, USER_DELADD)
  231. ua.add("title", "Architect")
  232. assert ua.get_attr_val('title')
  233. def test_allow_write_access_to_target_with_wildcards(topo, aci_of_user, cleanup_tree):
  234. """Modify Test 6 Allow write access to target with wildcards
  235. :id: 825fe884-7abf-11e8-8541-8c16451d917b
  236. :setup: server
  237. :steps:
  238. 1. Add test entry
  239. 2. Add ACI
  240. 3. User should follow ACI role
  241. :expectedresults:
  242. 1. Entry should be added
  243. 2. Operation should succeed
  244. 3. Operation should succeed
  245. """
  246. ACI_BODY = '(target = ldap:///{})(targetattr = "*")(version 3.0; acl "ACI NAME"; allow (write) (userdn = "ldap:///anyone") ;)'.format(DEFAULT_SUFFIX)
  247. Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
  248. for i in ['Product Development', 'Accounting', 'Human Resources']:
  249. ou = OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX))
  250. ou.create(properties={'ou': i})
  251. for i in ['Jeff Vedder,ou=Product Development', 'Sam Carter,ou=Accounting', 'Kirsten Vaughan, ou=Human Resources']:
  252. properties = {
  253. 'uid': i,
  254. 'cn': i,
  255. 'sn': 'user',
  256. 'uidNumber': '1000',
  257. 'gidNumber': '2000',
  258. 'homeDirectory': '/home/' + i,
  259. 'userPassword': PW_DM
  260. }
  261. user = UserAccount(topo.standalone, "cn={},{}".format(i, DEFAULT_SUFFIX))
  262. user.create(properties=properties)
  263. conn = UserAccount(topo.standalone, USER_DELADD).bind(PW_DM)
  264. # Allow write access to target with wildcards
  265. ua = UserAccount(conn, KIRSTENVAUGHAN)
  266. ua.add("title", "Architect")
  267. assert ua.get_attr_val('title')
  268. conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
  269. # Allow write access to target with wildcards
  270. ua = UserAccount(conn, USER_DELADD)
  271. ua.add("title", "Architect")
  272. assert ua.get_attr_val('title')
  273. def test_allow_write_access_to_userdnattr(topo, aci_of_user, cleanup_tree, request):
  274. """Modify Test 7 Allow write access to userdnattr
  275. :id: 86b418f6-7abf-11e8-ae28-8c16451d917b
  276. :setup: server
  277. :steps:
  278. 1. Add test entry
  279. 2. Add ACI
  280. 3. User should follow ACI role
  281. :expectedresults:
  282. 1. Entry should be added
  283. 2. Operation should succeed
  284. 3. Operation should succeed
  285. """
  286. ACI_BODY = '(target = ldap:///{})(targetattr="*")(version 3.0; acl "{}";allow (write) (userdn = "ldap:///anyone"); )'.format(DEFAULT_SUFFIX, request.node.name)
  287. Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
  288. for i in ['Product Development', 'Accounting']:
  289. ou = OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX))
  290. ou.create(properties={'ou': i})
  291. for i in ['Jeff Vedder,ou=Product Development', 'Sam Carter,ou=Accounting']:
  292. properties = {
  293. 'uid': i,
  294. 'cn': i,
  295. 'sn': 'user',
  296. 'uidNumber': '1000',
  297. 'gidNumber': '2000',
  298. 'homeDirectory': '/home/' + i,
  299. 'userPassword': PW_DM
  300. }
  301. user = UserAccount(topo.standalone, "cn={},{}".format(i, DEFAULT_SUFFIX))
  302. user.create(properties=properties)
  303. UserAccount(topo.standalone, USER_WITH_ACI_DELADD).add('manager', USER_WITH_ACI_DELADD)
  304. conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
  305. # Allow write access to userdnattr
  306. ua = UserAccount(conn, USER_DELADD)
  307. ua.add('uid', 'scoobie')
  308. assert ua.get_attr_val('uid')
  309. ua.add('uid', 'jvedder')
  310. assert ua.get_attr_val('uid')
  311. def test_allow_selfwrite_access_to_anyone(topo, aci_of_user, cleanup_tree):
  312. """Modify Test 8 Allow selfwrite access to anyone
  313. :id: 8b3becf0-7abf-11e8-ac34-8c16451d917b
  314. :setup: server
  315. :steps:
  316. 1. Add test entry
  317. 2. Add ACI
  318. 3. User should follow ACI role
  319. :expectedresults:
  320. 1. Entry should be added
  321. 2. Operation should succeed
  322. 3. Operation should succeed
  323. """
  324. groups = Groups(topo.standalone, DEFAULT_SUFFIX)
  325. group = groups.create(properties={"cn": "group1",
  326. "description": "testgroup"})
  327. ACI_BODY = '(target = ldap:///cn=group1,ou=Groups,{})(targetattr = "member")(version 3.0; acl "ACI NAME"; allow (selfwrite) (userdn = "ldap:///anyone") ;)'.format(DEFAULT_SUFFIX)
  328. Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
  329. ou = OrganizationalUnit(topo.standalone, "ou=Product Development,{}".format(DEFAULT_SUFFIX))
  330. ou.create(properties={'ou': 'Product Development'})
  331. properties = {
  332. 'uid': 'Jeff Vedder',
  333. 'cn': 'Jeff Vedder',
  334. 'sn': 'user',
  335. 'uidNumber': '1000',
  336. 'gidNumber': '2000',
  337. 'homeDirectory': '/home/' + 'JeffVedder',
  338. 'userPassword': PW_DM
  339. }
  340. user = UserAccount(topo.standalone, "cn=Jeff Vedder,ou=Product Development,{}".format(DEFAULT_SUFFIX))
  341. user.create(properties=properties)
  342. conn = UserAccount(topo.standalone, USER_DELADD).bind(PW_DM)
  343. # Allow selfwrite access to anyone
  344. groups = Groups(conn, DEFAULT_SUFFIX)
  345. groups.list()[1].add_member(USER_DELADD)
  346. def test_uniquemember_should_also_be_the_owner(topo, aci_of_user):
  347. """Modify Test 10 groupdnattr = \"ldap:///$BASEDN?owner\" if owner is a group, group's
  348. uniquemember should also be the owner
  349. :id: 9456b2d4-7abf-11e8-829d-8c16451d917b
  350. :setup: server
  351. :steps:
  352. 1. Add test entry
  353. 2. Add ACI
  354. 3. User should follow ACI role
  355. :expectedresults:
  356. 1. Entry should be added
  357. 2. Operation should succeed
  358. 3. Operation should succeed
  359. """
  360. for i in ['ACLGroupTest']:
  361. ou = OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX))
  362. ou.create(properties={'ou': i})
  363. ou = OrganizationalUnit(topo.standalone, "ou=ACLDevelopment,{}".format(DEFAULT_SUFFIX))
  364. ou.create(properties={'ou': 'ACLDevelopment'})
  365. ou.set('aci','(targetattr="*")(version 3.0; acl "groupdnattr acl"; '
  366. 'allow (all)groupdnattr = "ldap:///{}?owner";)'.format(DEFAULT_SUFFIX))
  367. grp = UniqueGroup(topo.standalone, "uid=anuj,ou=ACLDevelopment, {}".format(DEFAULT_SUFFIX))
  368. user_props = (
  369. {'sn': 'Borah',
  370. 'cn': 'Anuj',
  371. 'objectclass': ['top', 'person', 'organizationalPerson', 'inetOrgPerson', 'groupofUniquenames'],
  372. 'userpassword': PW_DM,
  373. 'givenname': 'Anuj',
  374. 'ou': ['ACLDevelopment', 'People'],
  375. 'roomnumber': '123',
  376. 'uniquemember': 'cn=mandatory member'
  377. }
  378. )
  379. grp.create(properties=user_props)
  380. grp = UniqueGroup(topo.standalone, "uid=2ishani,ou=ACLDevelopment, {}".format(DEFAULT_SUFFIX))
  381. user_props = (
  382. {'sn': 'Borah',
  383. 'cn': '2ishani',
  384. 'objectclass': ['top', 'person','organizationalPerson', 'inetOrgPerson', 'groupofUniquenames'],
  385. 'userpassword': PW_DM,
  386. 'givenname': '2ishani',
  387. 'ou': ['ACLDevelopment', 'People'],
  388. 'roomnumber': '1234',
  389. 'uniquemember': 'cn=mandatory member', "owner": "cn=group4, ou=ACLGroupTest, {}".format(DEFAULT_SUFFIX)
  390. }
  391. )
  392. grp.create(properties=user_props)
  393. grp = UniqueGroup(topo.standalone, 'cn=group1,ou=ACLGroupTest,'+DEFAULT_SUFFIX)
  394. grp.create(properties={'cn': 'group1',
  395. 'ou': 'groups'})
  396. grp.set('uniquemember', ["cn=group2, ou=ACLGroupTest, {}".format(DEFAULT_SUFFIX),
  397. "cn=group3, ou=ACLGroupTest, {}".format(DEFAULT_SUFFIX)])
  398. grp = UniqueGroup(topo.standalone, 'cn=group3,ou=ACLGroupTest,' + DEFAULT_SUFFIX)
  399. grp.create(properties={'cn': 'group3',
  400. 'ou': 'groups'})
  401. grp.set('uniquemember', ["cn=group4, ou=ACLGroupTest, {}".format(DEFAULT_SUFFIX)])
  402. grp = UniqueGroup(topo.standalone, 'cn=group4,ou=ACLGroupTest,' + DEFAULT_SUFFIX)
  403. grp.create(properties={
  404. 'cn': 'group4',
  405. 'ou': 'groups'})
  406. grp.set('uniquemember', ["uid=anuj, ou=ACLDevelopment, {}".format(DEFAULT_SUFFIX)])
  407. #uniquemember should also be the owner
  408. conn = UserAccount(topo.standalone, "uid=anuj,ou=ACLDevelopment, {}".format(DEFAULT_SUFFIX)).bind(PW_DM)
  409. ua = UserAccount(conn, "uid=2ishani, ou=ACLDevelopment, {}".format(DEFAULT_SUFFIX))
  410. ua.add('roomnumber', '9999')
  411. assert ua.get_attr_val('roomnumber')
  412. for DN in ["cn=group4,ou=ACLGroupTest,{}".format(DEFAULT_SUFFIX),
  413. "cn=group3,ou=ACLGroupTest,{}".format(DEFAULT_SUFFIX),
  414. "cn=group1,ou=ACLGroupTest,{}".format(DEFAULT_SUFFIX),
  415. "uid=2ishani,ou=ACLDevelopment,{}".format(DEFAULT_SUFFIX),
  416. "uid=anuj,ou=ACLDevelopment,{}".format(DEFAULT_SUFFIX), "ou=ACLDevelopment,{}".format(DEFAULT_SUFFIX),
  417. "ou=ACLGroupTest, {}".format(DEFAULT_SUFFIX)]:
  418. UserAccount(topo.standalone, DN).delete()
  419. def test_aci_with_both_allow_and_deny(topo, aci_of_user, cleanup_tree):
  420. """Modify Test 12 aci with both allow and deny
  421. :id: 9dcfe902-7abf-11e8-86dc-8c16451d917b
  422. :setup: server
  423. :steps:
  424. 1. Add test entry
  425. 2. Add ACI
  426. 3. User should follow ACI role
  427. :expectedresults:
  428. 1. Entry should be added
  429. 2. Operation should succeed
  430. 3. Operation should succeed
  431. """
  432. ACI_BODY = '(targetattr = "*")(version 3.0; acl "ACI NAME"; deny (read, search)userdn = "ldap:///{}"; allow (all) userdn = "ldap:///{}" ;)'.format(USER_WITH_ACI_DELADD, USER_DELADD)
  433. Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
  434. for i in ['Product Development', 'Accounting']:
  435. ou = OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX))
  436. ou.create(properties={'ou': i})
  437. for i in ['Jeff Vedder,ou=Product Development', 'Sam Carter,ou=Accounting']:
  438. properties = {
  439. 'uid': i,
  440. 'cn': i,
  441. 'sn': 'user',
  442. 'uidNumber': '1000',
  443. 'gidNumber': '2000',
  444. 'homeDirectory': '/home/' + i,
  445. 'userPassword': PW_DM
  446. }
  447. user = UserAccount(topo.standalone, "cn={},{}".format(i, DEFAULT_SUFFIX))
  448. user.create(properties=properties)
  449. conn = UserAccount(topo.standalone, USER_DELADD).bind(PW_DM)
  450. # aci with both allow and deny, testing allow
  451. assert UserAccount(conn, USER_WITH_ACI_DELADD).get_attr_val('uid')
  452. conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
  453. # aci with both allow and deny, testing deny
  454. with pytest.raises(IndexError):
  455. UserAccount(conn, USER_WITH_ACI_DELADD).get_attr_val('uid')
  456. def test_allow_owner_to_modify_entry(topo, aci_of_user, cleanup_tree, request):
  457. """Modify Test 14 allow userdnattr = owner to modify entry
  458. :id: aa302090-7abf-11e8-811a-8c16451d917b
  459. :setup: server
  460. :steps:
  461. 1. Add test entry
  462. 2. Add ACI
  463. 3. User should follow ACI role
  464. :expectedresults:
  465. 1. Entry should be added
  466. 2. Operation should succeed
  467. 3. Operation should succeed
  468. """
  469. grp = UniqueGroup(topo.standalone, 'cn=intranet,' + DEFAULT_SUFFIX)
  470. grp.create(properties={
  471. 'cn': 'intranet',
  472. 'ou': 'groups'})
  473. grp.set('owner', USER_WITH_ACI_DELADD)
  474. ACI_BODY = '(target ="ldap:///cn=intranet, {}") (targetattr ="*")(targetfilter ="(objectclass=groupOfUniqueNames)") (version 3.0;acl "{}";allow(read, write, delete, search, compare, add) (userdnattr = "owner");)'.format(DEFAULT_SUFFIX, request.node.name)
  475. Domain(topo.standalone, DEFAULT_SUFFIX).add("aci", ACI_BODY)
  476. for i in ['Product Development', 'Accounting']:
  477. ou = OrganizationalUnit(topo.standalone, "ou={},{}".format(i, DEFAULT_SUFFIX))
  478. ou.create(properties={'ou': i})
  479. for i in ['Jeff Vedder,ou=Product Development', 'Sam Carter,ou=Accounting']:
  480. properties = {
  481. 'uid': i,
  482. 'cn': i,
  483. 'sn': 'user',
  484. 'uidNumber': '1000',
  485. 'gidNumber': '2000',
  486. 'homeDirectory': '/home/' + i,
  487. 'userPassword': PW_DM
  488. }
  489. user = UserAccount(topo.standalone, "cn={},{}".format(i, DEFAULT_SUFFIX))
  490. user.create(properties=properties)
  491. conn = UserAccount(topo.standalone, USER_WITH_ACI_DELADD).bind(PW_DM)
  492. # allow userdnattr = owner to modify entry
  493. ua = UserAccount(conn, 'cn=intranet,dc=example,dc=com')
  494. ua.set('uniquemember', "cn=Andy Walker, ou=Accounting,dc=example,dc=com")
  495. assert ua.get_attr_val('uniquemember')
  496. if __name__ == "__main__":
  497. CURRENT_FILE = os.path.realpath(__file__)
  498. pytest.main("-s -v %s" % CURRENT_FILE)