ticket47921_test.py 4.6 KB

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