ticket47921_test.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2015 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 os
  10. import sys
  11. import time
  12. import ldap
  13. import logging
  14. import pytest
  15. from lib389 import DirSrv, Entry, tools, tasks
  16. from lib389.tools import DirSrvTools
  17. from lib389._constants import *
  18. from lib389.properties import *
  19. from lib389.tasks import *
  20. from lib389.utils import *
  21. logging.getLogger(__name__).setLevel(logging.DEBUG)
  22. log = logging.getLogger(__name__)
  23. installation1_prefix = None
  24. class TopologyStandalone(object):
  25. def __init__(self, standalone):
  26. standalone.open()
  27. self.standalone = standalone
  28. @pytest.fixture(scope="module")
  29. def topology(request):
  30. global installation1_prefix
  31. if installation1_prefix:
  32. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  33. # Creating standalone instance ...
  34. standalone = DirSrv(verbose=False)
  35. args_instance[SER_HOST] = HOST_STANDALONE
  36. args_instance[SER_PORT] = PORT_STANDALONE
  37. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  38. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  39. args_standalone = args_instance.copy()
  40. standalone.allocate(args_standalone)
  41. instance_standalone = standalone.exists()
  42. if instance_standalone:
  43. standalone.delete()
  44. standalone.create()
  45. standalone.open()
  46. def fin():
  47. standalone.delete()
  48. request.addfinalizer(fin)
  49. return TopologyStandalone(standalone)
  50. def test_ticket47921(topology):
  51. '''
  52. Test that indirect cos reflects the current value of the indirect entry
  53. '''
  54. INDIRECT_COS_DN = 'cn=cos definition,' + DEFAULT_SUFFIX
  55. MANAGER_DN = 'uid=my manager,ou=people,' + DEFAULT_SUFFIX
  56. USER_DN = 'uid=user,ou=people,' + DEFAULT_SUFFIX
  57. # Add COS definition
  58. try:
  59. topology.standalone.add_s(Entry((INDIRECT_COS_DN,
  60. {'objectclass': 'top cosSuperDefinition cosIndirectDefinition ldapSubEntry'.split(),
  61. 'cosIndirectSpecifier': 'manager',
  62. 'cosAttribute': 'roomnumber'
  63. })))
  64. except ldap.LDAPError as e:
  65. log.fatal('Failed to add cos defintion, error: ' + e.message['desc'])
  66. assert False
  67. # Add manager entry
  68. try:
  69. topology.standalone.add_s(Entry((MANAGER_DN,
  70. {'objectclass': 'top extensibleObject'.split(),
  71. 'uid': 'my manager',
  72. 'roomnumber': '1'
  73. })))
  74. except ldap.LDAPError as e:
  75. log.fatal('Failed to add manager entry, error: ' + e.message['desc'])
  76. assert False
  77. # Add user entry
  78. try:
  79. topology.standalone.add_s(Entry((USER_DN,
  80. {'objectclass': 'top person organizationalPerson inetorgperson'.split(),
  81. 'sn': 'last',
  82. 'cn': 'full',
  83. 'givenname': 'mark',
  84. 'uid': 'user',
  85. 'manager': MANAGER_DN
  86. })))
  87. except ldap.LDAPError as e:
  88. log.fatal('Failed to add manager entry, error: ' + e.message['desc'])
  89. assert False
  90. # Test COS is working
  91. try:
  92. entry = topology.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE,
  93. "uid=user",
  94. ['roomnumber'])
  95. if entry:
  96. if entry[0].getValue('roomnumber') != '1':
  97. log.fatal('COS is not working.')
  98. assert False
  99. else:
  100. log.fatal('Failed to find user entry')
  101. assert False
  102. except ldap.LDAPError as e:
  103. log.error('Failed to search for user entry: ' + e.message['desc'])
  104. assert False
  105. # Modify manager entry
  106. try:
  107. topology.standalone.modify_s(MANAGER_DN, [(ldap.MOD_REPLACE, 'roomnumber', '2')])
  108. except ldap.LDAPError as e:
  109. log.error('Failed to modify manager entry: ' + e.message['desc'])
  110. assert False
  111. # Confirm COS is returning the new value
  112. try:
  113. entry = topology.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE,
  114. "uid=user",
  115. ['roomnumber'])
  116. if entry:
  117. if entry[0].getValue('roomnumber') != '2':
  118. log.fatal('COS is not working after manager update.')
  119. assert False
  120. else:
  121. log.fatal('Failed to find user entry')
  122. assert False
  123. except ldap.LDAPError as e:
  124. log.error('Failed to search for user entry: ' + e.message['desc'])
  125. assert False
  126. log.info('Test complete')
  127. if __name__ == '__main__':
  128. # Run isolated
  129. # -s for DEBUG mode
  130. CURRENT_FILE = os.path.realpath(__file__)
  131. pytest.main("-s %s" % CURRENT_FILE)