ticket47920_test.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 logging
  10. import ldap
  11. import pytest
  12. from ldap.controls.readentry import PostReadControl
  13. from lib389 import Entry
  14. from lib389._constants import *
  15. from lib389.topologies import topology_st
  16. SCOPE_IN_CN = 'in'
  17. SCOPE_OUT_CN = 'out'
  18. SCOPE_IN_DN = 'cn=%s,%s' % (SCOPE_IN_CN, SUFFIX)
  19. SCOPE_OUT_DN = 'cn=%s,%s' % (SCOPE_OUT_CN, SUFFIX)
  20. PROVISIONING_CN = "provisioning"
  21. PROVISIONING_DN = "cn=%s,%s" % (PROVISIONING_CN, SCOPE_IN_DN)
  22. ACTIVE_CN = "accounts"
  23. STAGE_CN = "staged users"
  24. DELETE_CN = "deleted users"
  25. ACTIVE_DN = "cn=%s,%s" % (ACTIVE_CN, SCOPE_IN_DN)
  26. STAGE_DN = "cn=%s,%s" % (STAGE_CN, PROVISIONING_DN)
  27. DELETE_DN = "cn=%s,%s" % (DELETE_CN, PROVISIONING_DN)
  28. STAGE_USER_CN = "stage guy"
  29. STAGE_USER_DN = "cn=%s,%s" % (STAGE_USER_CN, STAGE_DN)
  30. ACTIVE_USER_CN = "active guy"
  31. ACTIVE_USER_DN = "cn=%s,%s" % (ACTIVE_USER_CN, ACTIVE_DN)
  32. OUT_USER_CN = "out guy"
  33. OUT_USER_DN = "cn=%s,%s" % (OUT_USER_CN, SCOPE_OUT_DN)
  34. STAGE_GROUP_CN = "stage group"
  35. STAGE_GROUP_DN = "cn=%s,%s" % (STAGE_GROUP_CN, STAGE_DN)
  36. ACTIVE_GROUP_CN = "active group"
  37. ACTIVE_GROUP_DN = "cn=%s,%s" % (ACTIVE_GROUP_CN, ACTIVE_DN)
  38. OUT_GROUP_CN = "out group"
  39. OUT_GROUP_DN = "cn=%s,%s" % (OUT_GROUP_CN, SCOPE_OUT_DN)
  40. INDIRECT_ACTIVE_GROUP_CN = "indirect active group"
  41. INDIRECT_ACTIVE_GROUP_DN = "cn=%s,%s" % (INDIRECT_ACTIVE_GROUP_CN, ACTIVE_DN)
  42. INITIAL_DESC = "inital description"
  43. FINAL_DESC = "final description"
  44. log = logging.getLogger(__name__)
  45. def _header(topology_st, label):
  46. topology_st.standalone.log.info("\n\n###############################################")
  47. topology_st.standalone.log.info("#######")
  48. topology_st.standalone.log.info("####### %s" % label)
  49. topology_st.standalone.log.info("#######")
  50. topology_st.standalone.log.info("###############################################")
  51. def _add_user(topology_st, type='active'):
  52. if type == 'active':
  53. topology_st.standalone.add_s(Entry((ACTIVE_USER_DN, {
  54. 'objectclass': "top person inetuser".split(),
  55. 'sn': ACTIVE_USER_CN,
  56. 'cn': ACTIVE_USER_CN,
  57. 'description': INITIAL_DESC})))
  58. elif type == 'stage':
  59. topology_st.standalone.add_s(Entry((STAGE_USER_DN, {
  60. 'objectclass': "top person inetuser".split(),
  61. 'sn': STAGE_USER_CN,
  62. 'cn': STAGE_USER_CN})))
  63. else:
  64. topology_st.standalone.add_s(Entry((OUT_USER_DN, {
  65. 'objectclass': "top person inetuser".split(),
  66. 'sn': OUT_USER_CN,
  67. 'cn': OUT_USER_CN})))
  68. def test_ticket47920_init(topology_st):
  69. topology_st.standalone.add_s(Entry((SCOPE_IN_DN, {
  70. 'objectclass': "top nscontainer".split(),
  71. 'cn': SCOPE_IN_DN})))
  72. topology_st.standalone.add_s(Entry((ACTIVE_DN, {
  73. 'objectclass': "top nscontainer".split(),
  74. 'cn': ACTIVE_CN})))
  75. # add users
  76. _add_user(topology_st, 'active')
  77. def test_ticket47920_mod_readentry_ctrl(topology_st):
  78. _header(topology_st, 'MOD: with a readentry control')
  79. topology_st.standalone.log.info("Check the initial value of the entry")
  80. ent = topology_st.standalone.getEntry(ACTIVE_USER_DN, ldap.SCOPE_BASE, "(objectclass=*)", ['description'])
  81. assert ent.hasAttr('description')
  82. assert ent.getValue('description') == INITIAL_DESC
  83. pr = PostReadControl(criticality=True, attrList=['cn', 'description'])
  84. _, _, _, resp_ctrls = topology_st.standalone.modify_ext_s(ACTIVE_USER_DN,
  85. [(ldap.MOD_REPLACE, 'description', [FINAL_DESC])],
  86. serverctrls=[pr])
  87. assert resp_ctrls[0].dn == ACTIVE_USER_DN
  88. assert 'description' in resp_ctrls[0].entry
  89. assert 'cn' in resp_ctrls[0].entry
  90. print(resp_ctrls[0].entry['description'])
  91. ent = topology_st.standalone.getEntry(ACTIVE_USER_DN, ldap.SCOPE_BASE, "(objectclass=*)", ['description'])
  92. assert ent.hasAttr('description')
  93. assert ent.getValue('description') == FINAL_DESC
  94. if __name__ == '__main__':
  95. # Run isolated
  96. # -s for DEBUG mode
  97. CURRENT_FILE = os.path.realpath(__file__)
  98. pytest.main("-s %s" % CURRENT_FILE)