ticket47553_test.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. logging.getLogger(__name__).setLevel(logging.DEBUG)
  14. log = logging.getLogger(__name__)
  15. CONTAINER_1_OU = 'test_ou_1'
  16. CONTAINER_2_OU = 'test_ou_2'
  17. CONTAINER_1 = 'ou=%s,dc=example,dc=com' % CONTAINER_1_OU
  18. CONTAINER_2 = 'ou=%s,dc=example,dc=com' % CONTAINER_2_OU
  19. USER_CN = 'test_user'
  20. USER_PWD = 'Secret123'
  21. USER = 'cn=%s,%s' % (USER_CN, CONTAINER_1)
  22. @pytest.fixture(scope="module")
  23. def env_setup(topology_st):
  24. """Adds two containers, one user and two ACI rules"""
  25. try:
  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. except ldap.LDAPError as e:
  46. log.error('Failed to add object to database: %s' % e.message['desc'])
  47. assert False
  48. ACI_TARGET = '(targetattr="*")'
  49. ACI_ALLOW = '(version 3.0; acl "All rights for %s"; allow (all) ' % USER
  50. ACI_SUBJECT = 'userdn="ldap:///%s";)' % USER
  51. ACI_BODY = ACI_TARGET + ACI_ALLOW + ACI_SUBJECT
  52. mod = [(ldap.MOD_ADD, 'aci', ACI_BODY)]
  53. try:
  54. log.info("Add an ACI 'allow (all)' by %s to the %s" % (USER,
  55. CONTAINER_1))
  56. topology_st.standalone.modify_s(CONTAINER_1, mod)
  57. log.info("Add an ACI 'allow (all)' by %s to the %s" % (USER,
  58. CONTAINER_2))
  59. topology_st.standalone.modify_s(CONTAINER_2, mod)
  60. except ldap.LDAPError as e:
  61. log.fatal('Failed to add ACI: error (%s)' % (e.message['desc']))
  62. assert False
  63. def test_ticket47553(topology_st, env_setup):
  64. """Tests, that MODRDN operation is allowed,
  65. if user has ACI right '(all)' under superior entries,
  66. but doesn't have '(modrdn)'
  67. """
  68. log.info("Bind as %s" % USER)
  69. try:
  70. topology_st.standalone.simple_bind_s(USER, USER_PWD)
  71. except ldap.LDAPError as e:
  72. log.error('Bind failed for %s, error %s' % (USER, e.message['desc']))
  73. assert False
  74. log.info("User MODRDN operation from %s to %s" % (CONTAINER_1,
  75. CONTAINER_2))
  76. try:
  77. topology_st.standalone.rename_s(USER, "cn=%s" % USER_CN,
  78. newsuperior=CONTAINER_2, delold=1)
  79. except ldap.LDAPError as e:
  80. log.error('MODRDN failed for %s, error %s' % (USER, e.message['desc']))
  81. assert False
  82. try:
  83. log.info("Check there is no user in %s" % CONTAINER_1)
  84. entries = topology_st.standalone.search_s(CONTAINER_1,
  85. ldap.SCOPE_ONELEVEL,
  86. 'cn=%s' % USER_CN)
  87. assert not entries
  88. log.info("Check there is our user in %s" % CONTAINER_2)
  89. entries = topology_st.standalone.search_s(CONTAINER_2,
  90. ldap.SCOPE_ONELEVEL,
  91. 'cn=%s' % USER_CN)
  92. assert entries
  93. except ldap.LDAPError as e:
  94. log.fatal('Search failed, error: ' + e.message['desc'])
  95. assert False
  96. if __name__ == '__main__':
  97. # Run isolated
  98. # -s for DEBUG mode
  99. # -v for additional verbose
  100. CURRENT_FILE = os.path.realpath(__file__)
  101. pytest.main("-s -v %s" % CURRENT_FILE)