ticket49249_test.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import time
  2. import ldap
  3. import logging
  4. import pytest
  5. from lib389 import DirSrv, Entry, tools, tasks
  6. from lib389.tools import DirSrvTools
  7. from lib389._constants import *
  8. from lib389.properties import *
  9. from lib389.tasks import *
  10. from lib389.utils import *
  11. from lib389.topologies import topology_st as topo
  12. DEBUGGING = os.getenv("DEBUGGING", default=False)
  13. if DEBUGGING:
  14. logging.getLogger(__name__).setLevel(logging.DEBUG)
  15. else:
  16. logging.getLogger(__name__).setLevel(logging.INFO)
  17. log = logging.getLogger(__name__)
  18. COS_BRANCH = 'ou=cos_scope,' + DEFAULT_SUFFIX
  19. COS_DEF = 'cn=cos_definition,' + COS_BRANCH
  20. COS_TEMPLATE = 'cn=cos_template,' + COS_BRANCH
  21. INVALID_USER_WITH_COS = 'cn=cos_user_no_mail,' + COS_BRANCH
  22. VALID_USER_WITH_COS = 'cn=cos_user_with_mail,' + COS_BRANCH
  23. NO_COS_BRANCH = 'ou=no_cos_scope,' + DEFAULT_SUFFIX
  24. INVALID_USER_WITHOUT_COS = 'cn=no_cos_user_no_mail,' + NO_COS_BRANCH
  25. VALID_USER_WITHOUT_COS = 'cn=no_cos_user_with_mail,' + NO_COS_BRANCH
  26. def test_ticket49249(topo):
  27. """Write your testcase here...
  28. Also, if you need any testcase initialization,
  29. please, write additional fixture for that(include finalizer).
  30. """
  31. # Add the branches
  32. try:
  33. topo.standalone.add_s(Entry((COS_BRANCH, {
  34. 'objectclass': 'top extensibleObject'.split(),
  35. 'ou': 'cos_scope'
  36. })))
  37. except ldap.LDAPError as e:
  38. log.error('Failed to add cos_scope: error ' + e.message['desc'])
  39. assert False
  40. try:
  41. topo.standalone.add_s(Entry((NO_COS_BRANCH, {
  42. 'objectclass': 'top extensibleObject'.split(),
  43. 'ou': 'no_cos_scope'
  44. })))
  45. except ldap.LDAPError as e:
  46. log.error('Failed to add no_cos_scope: error ' + e.message['desc'])
  47. assert False
  48. try:
  49. topo.standalone.add_s(Entry((COS_TEMPLATE, {
  50. 'objectclass': 'top ldapsubentry costemplate extensibleObject'.split(),
  51. 'cn': 'cos_template',
  52. 'cosPriority': '1',
  53. 'cn': 'cn=nsPwTemplateEntry,ou=level1,dc=example,dc=com',
  54. 'mailAlternateAddress': 'hello@world'
  55. })))
  56. except ldap.LDAPError as e:
  57. log.error('Failed to add cos_template: error ' + e.message['desc'])
  58. assert False
  59. try:
  60. topo.standalone.add_s(Entry((COS_DEF, {
  61. 'objectclass': 'top ldapsubentry cosSuperDefinition cosPointerDefinition'.split(),
  62. 'cn': 'cos_definition',
  63. 'costemplatedn': COS_TEMPLATE,
  64. 'cosAttribute': 'mailAlternateAddress default'
  65. })))
  66. except ldap.LDAPError as e:
  67. log.error('Failed to add cos_definition: error ' + e.message['desc'])
  68. assert False
  69. try:
  70. # This entry is not allowed to have mailAlternateAddress
  71. topo.standalone.add_s(Entry((INVALID_USER_WITH_COS, {
  72. 'objectclass': 'top person'.split(),
  73. 'cn': 'cos_user_no_mail',
  74. 'sn': 'cos_user_no_mail'
  75. })))
  76. except ldap.LDAPError as e:
  77. log.error('Failed to add cos_user_no_mail: error ' + e.message['desc'])
  78. assert False
  79. try:
  80. # This entry is allowed to have mailAlternateAddress
  81. topo.standalone.add_s(Entry((VALID_USER_WITH_COS, {
  82. 'objectclass': 'top mailGroup'.split(),
  83. 'cn': 'cos_user_with_mail'
  84. })))
  85. except ldap.LDAPError as e:
  86. log.error('Failed to add cos_user_no_mail: error ' + e.message['desc'])
  87. assert False
  88. try:
  89. # This entry is not allowed to have mailAlternateAddress
  90. topo.standalone.add_s(Entry((INVALID_USER_WITHOUT_COS, {
  91. 'objectclass': 'top person'.split(),
  92. 'cn': 'no_cos_user_no_mail',
  93. 'sn': 'no_cos_user_no_mail'
  94. })))
  95. except ldap.LDAPError as e:
  96. log.error('Failed to add no_cos_user_no_mail: error ' + e.message['desc'])
  97. assert False
  98. try:
  99. # This entry is allowed to have mailAlternateAddress
  100. topo.standalone.add_s(Entry((VALID_USER_WITHOUT_COS, {
  101. 'objectclass': 'top mailGroup'.split(),
  102. 'cn': 'no_cos_user_with_mail'
  103. })))
  104. except ldap.LDAPError as e:
  105. log.error('Failed to add no_cos_user_with_mail: error ' + e.message['desc'])
  106. assert False
  107. try:
  108. entries = topo.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, '(mailAlternateAddress=*)')
  109. assert len(entries) == 1
  110. assert entries[0].hasValue('mailAlternateAddress', 'hello@world')
  111. except ldap.LDAPError as e:
  112. log.fatal('Unable to retrieve cos_user_with_mail (only entry with mailAlternateAddress) : error %s' % (USER1_DN, e.message['desc']))
  113. assert False
  114. assert not topo.standalone.ds_error_log.match(".*cos attribute mailAlternateAddress failed schema.*")
  115. if DEBUGGING:
  116. # Add debugging steps(if any)...
  117. pass
  118. if __name__ == '__main__':
  119. # Run isolated
  120. # -s for DEBUG mode
  121. CURRENT_FILE = os.path.realpath(__file__)
  122. pytest.main("-s %s" % CURRENT_FILE)