enhanced_aci_modrnd_test.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 lib389.tasks import *
  11. from lib389.utils import *
  12. from lib389.topologies import topology_st
  13. pytestmark = pytest.mark.tier1
  14. logging.getLogger(__name__).setLevel(logging.DEBUG)
  15. log = logging.getLogger(__name__)
  16. CONTAINER_1_OU = 'test_ou_1'
  17. CONTAINER_2_OU = 'test_ou_2'
  18. CONTAINER_1 = f'ou={CONTAINER_1_OU},dc=example,dc=com'
  19. CONTAINER_2 = f'ou={CONTAINER_2_OU},dc=example,dc=com'
  20. USER_CN = 'test_user'
  21. USER_PWD = 'Secret123'
  22. USER = f'cn={USER_CN},{CONTAINER_1}'
  23. @pytest.fixture(scope="module")
  24. def env_setup(topology_st):
  25. """Adds two containers, one user and two ACI rules"""
  26. log.info("Add a container: %s" % CONTAINER_1)
  27. topology_st.standalone.add_s(Entry((CONTAINER_1,
  28. {'objectclass': 'top',
  29. 'objectclass': 'organizationalunit',
  30. 'ou': CONTAINER_1_OU,
  31. })))
  32. log.info("Add a container: %s" % CONTAINER_2)
  33. topology_st.standalone.add_s(Entry((CONTAINER_2,
  34. {'objectclass': 'top',
  35. 'objectclass': 'organizationalunit',
  36. 'ou': CONTAINER_2_OU,
  37. })))
  38. log.info("Add a user: %s" % USER)
  39. topology_st.standalone.add_s(Entry((USER,
  40. {'objectclass': 'top person'.split(),
  41. 'cn': USER_CN,
  42. 'sn': USER_CN,
  43. 'userpassword': USER_PWD
  44. })))
  45. ACI_TARGET = '(targetattr="*")'
  46. ACI_ALLOW = '(version 3.0; acl "All rights for %s"; allow (all) ' % USER
  47. ACI_SUBJECT = 'userdn="ldap:///%s";)' % USER
  48. ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
  49. mod = [(ldap.MOD_ADD, 'aci', ensure_bytes(ACI_BODY))]
  50. log.info("Add an ACI 'allow (all)' by %s to the %s" % (USER,
  51. CONTAINER_1))
  52. topology_st.standalone.modify_s(CONTAINER_1, mod)
  53. log.info("Add an ACI 'allow (all)' by %s to the %s" % (USER,
  54. CONTAINER_2))
  55. topology_st.standalone.modify_s(CONTAINER_2, mod)
  56. @pytest.mark.ds47553
  57. def test_enhanced_aci_modrnd(topology_st, env_setup):
  58. """Tests, that MODRDN operation is allowed,
  59. if user has ACI right '(all)' under superior entries,
  60. but doesn't have '(modrdn)'
  61. :id: 492cf2a9-2efe-4e3b-955e-85eca61d66b9
  62. :setup: Standalone instance
  63. :steps:
  64. 1. Create two containers
  65. 2. Create a user within "ou=test_ou_1,dc=example,dc=com"
  66. 3. Add an aci with a rule "cn=test_user is allowed all" within these containers
  67. 4. Run MODRDN operation on the "cn=test_user" and set "newsuperior" to
  68. the "ou=test_ou_2,dc=example,dc=com"
  69. 5. Check there is no user under container one (ou=test_ou_1,dc=example,dc=com)
  70. 6. Check there is a user under container two (ou=test_ou_2,dc=example,dc=com)
  71. :expectedresults:
  72. 1. Two containers should be created
  73. 2. User should be added successfully
  74. 3. This should pass
  75. 4. This should pass
  76. 5. User should not be found under container ou=test_ou_1,dc=example,dc=com
  77. 6. User should be found under container ou=test_ou_2,dc=example,dc=com
  78. """
  79. log.info("Bind as %s" % USER)
  80. topology_st.standalone.simple_bind_s(USER, USER_PWD)
  81. log.info("User MODRDN operation from %s to %s" % (CONTAINER_1,
  82. CONTAINER_2))
  83. topology_st.standalone.rename_s(USER, "cn=%s" % USER_CN,
  84. newsuperior=CONTAINER_2, delold=1)
  85. log.info("Check there is no user in %s" % CONTAINER_1)
  86. entries = topology_st.standalone.search_s(CONTAINER_1,
  87. ldap.SCOPE_ONELEVEL,
  88. 'cn=%s' % USER_CN)
  89. assert not entries
  90. log.info("Check there is our user in %s" % CONTAINER_2)
  91. entries = topology_st.standalone.search_s(CONTAINER_2,
  92. ldap.SCOPE_ONELEVEL,
  93. 'cn=%s' % USER_CN)
  94. assert entries
  95. if __name__ == '__main__':
  96. # Run isolated
  97. # -s for DEBUG mode
  98. # -v for additional verbose
  99. CURRENT_FILE = os.path.realpath(__file__)
  100. pytest.main("-s -v %s" % CURRENT_FILE)