ticket47921_test.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. # Clear out the tmp dir
  47. standalone.clearTmpDir(__file__)
  48. return TopologyStandalone(standalone)
  49. def test_ticket47921(topology):
  50. '''
  51. Test that indirect cos reflects the current value of the indirect entry
  52. '''
  53. INDIRECT_COS_DN = 'cn=cos definition,' + DEFAULT_SUFFIX
  54. MANAGER_DN = 'uid=my manager,ou=people,' + DEFAULT_SUFFIX
  55. USER_DN = 'uid=user,ou=people,' + DEFAULT_SUFFIX
  56. # Add COS definition
  57. try:
  58. topology.standalone.add_s(Entry((INDIRECT_COS_DN,
  59. {'objectclass': 'top cosSuperDefinition cosIndirectDefinition ldapSubEntry'.split(),
  60. 'cosIndirectSpecifier': 'manager',
  61. 'cosAttribute': 'roomnumber'
  62. })))
  63. except ldap.LDAPError as e:
  64. log.fatal('Failed to add cos defintion, error: ' + e.message['desc'])
  65. assert False
  66. # Add manager entry
  67. try:
  68. topology.standalone.add_s(Entry((MANAGER_DN,
  69. {'objectclass': 'top extensibleObject'.split(),
  70. 'uid': 'my manager',
  71. 'roomnumber': '1'
  72. })))
  73. except ldap.LDAPError as e:
  74. log.fatal('Failed to add manager entry, error: ' + e.message['desc'])
  75. assert False
  76. # Add user entry
  77. try:
  78. topology.standalone.add_s(Entry((USER_DN,
  79. {'objectclass': 'top person organizationalPerson inetorgperson'.split(),
  80. 'sn': 'last',
  81. 'cn': 'full',
  82. 'givenname': 'mark',
  83. 'uid': 'user',
  84. 'manager': MANAGER_DN
  85. })))
  86. except ldap.LDAPError as e:
  87. log.fatal('Failed to add manager entry, error: ' + e.message['desc'])
  88. assert False
  89. # Test COS is working
  90. try:
  91. entry = topology.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE,
  92. "uid=user",
  93. ['roomnumber'])
  94. if entry:
  95. if entry[0].getValue('roomnumber') != '1':
  96. log.fatal('COS is not working.')
  97. assert False
  98. else:
  99. log.fatal('Failed to find user entry')
  100. assert False
  101. except ldap.LDAPError as e:
  102. log.error('Failed to search for user entry: ' + e.message['desc'])
  103. assert False
  104. # Modify manager entry
  105. try:
  106. topology.standalone.modify_s(MANAGER_DN, [(ldap.MOD_REPLACE, 'roomnumber', '2')])
  107. except ldap.LDAPError as e:
  108. log.error('Failed to modify manager entry: ' + e.message['desc'])
  109. assert False
  110. # Confirm COS is returning the new value
  111. try:
  112. entry = topology.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE,
  113. "uid=user",
  114. ['roomnumber'])
  115. if entry:
  116. if entry[0].getValue('roomnumber') != '2':
  117. log.fatal('COS is not working after manager update.')
  118. assert False
  119. else:
  120. log.fatal('Failed to find user entry')
  121. assert False
  122. except ldap.LDAPError as e:
  123. log.error('Failed to search for user entry: ' + e.message['desc'])
  124. assert False
  125. log.info('Test complete')
  126. def test_ticket47921_final(topology):
  127. topology.standalone.delete()
  128. log.info('Testcase PASSED')
  129. def run_isolated():
  130. global installation1_prefix
  131. installation1_prefix = None
  132. topo = topology(True)
  133. test_ticket47921(topo)
  134. test_ticket47921_final(topo)
  135. if __name__ == '__main__':
  136. run_isolated()