ticket48026_test.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. USER1_DN = 'uid=user1,' + DEFAULT_SUFFIX
  17. USER2_DN = 'uid=user2,' + DEFAULT_SUFFIX
  18. class TopologyStandalone(object):
  19. def __init__(self, standalone):
  20. standalone.open()
  21. self.standalone = standalone
  22. @pytest.fixture(scope="module")
  23. def topology(request):
  24. global installation1_prefix
  25. if installation1_prefix:
  26. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  27. # Creating standalone instance ...
  28. standalone = DirSrv(verbose=False)
  29. args_instance[SER_HOST] = HOST_STANDALONE
  30. args_instance[SER_PORT] = PORT_STANDALONE
  31. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  32. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  33. args_standalone = args_instance.copy()
  34. standalone.allocate(args_standalone)
  35. instance_standalone = standalone.exists()
  36. if instance_standalone:
  37. standalone.delete()
  38. standalone.create()
  39. standalone.open()
  40. # Clear out the tmp dir
  41. standalone.clearTmpDir(__file__)
  42. return TopologyStandalone(standalone)
  43. def test_ticket48026(topology):
  44. '''
  45. Test that multiple attribute uniqueness works correctly.
  46. '''
  47. # Configure the plugin
  48. inst = topology.standalone
  49. inst.plugins.enable(name=PLUGIN_ATTR_UNIQUENESS)
  50. try:
  51. # This plugin enable / disable doesn't seem to create the nsslapd-pluginId correctly?
  52. inst.modify_s('cn=' + PLUGIN_ATTR_UNIQUENESS + ',cn=plugins,cn=config',
  53. [(ldap.MOD_REPLACE, 'uniqueness-attribute-name', 'mail'),
  54. (ldap.MOD_ADD, 'uniqueness-attribute-name',
  55. 'mailAlternateAddress'),
  56. ])
  57. except ldap.LDAPError, e:
  58. log.fatal('test_ticket48026: Failed to configure plugin for "mail": error ' + e.message['desc'])
  59. assert False
  60. inst.restart(timeout=30)
  61. # Add an entry
  62. try:
  63. inst.add_s(Entry((USER1_DN, {'objectclass': "top extensibleObject".split(),
  64. 'sn': '1',
  65. 'cn': 'user 1',
  66. 'uid': 'user1',
  67. 'mail': '[email protected]',
  68. 'mailAlternateAddress' : '[email protected]',
  69. 'userpassword': 'password'})))
  70. except ldap.LDAPError, e:
  71. log.fatal('test_ticket48026: Failed to add test user' + USER1_DN + ': error ' + e.message['desc'])
  72. assert False
  73. try:
  74. inst.add_s(Entry((USER2_DN, {'objectclass': "top extensibleObject".split(),
  75. 'sn': '2',
  76. 'cn': 'user 2',
  77. 'uid': 'user2',
  78. 'mail': '[email protected]',
  79. 'userpassword': 'password'})))
  80. except ldap.CONSTRAINT_VIOLATION:
  81. pass
  82. else:
  83. log.error('test_ticket48026: Adding of 1st entry(mail v mail) incorrectly succeeded')
  84. assert False
  85. try:
  86. inst.add_s(Entry((USER2_DN, {'objectclass': "top extensibleObject".split(),
  87. 'sn': '2',
  88. 'cn': 'user 2',
  89. 'uid': 'user2',
  90. 'mailAlternateAddress': '[email protected]',
  91. 'userpassword': 'password'})))
  92. except ldap.CONSTRAINT_VIOLATION:
  93. pass
  94. else:
  95. log.error('test_ticket48026: Adding of 2nd entry(mailAlternateAddress v mailAlternateAddress) incorrectly succeeded')
  96. assert False
  97. try:
  98. inst.add_s(Entry((USER2_DN, {'objectclass': "top extensibleObject".split(),
  99. 'sn': '2',
  100. 'cn': 'user 2',
  101. 'uid': 'user2',
  102. 'mail': '[email protected]',
  103. 'userpassword': 'password'})))
  104. except ldap.CONSTRAINT_VIOLATION:
  105. pass
  106. else:
  107. log.error('test_ticket48026: Adding of 3rd entry(mail v mailAlternateAddress) incorrectly succeeded')
  108. assert False
  109. try:
  110. inst.add_s(Entry((USER2_DN, {'objectclass': "top extensibleObject".split(),
  111. 'sn': '2',
  112. 'cn': 'user 2',
  113. 'uid': 'user2',
  114. 'mailAlternateAddress': '[email protected]',
  115. 'userpassword': 'password'})))
  116. except ldap.CONSTRAINT_VIOLATION:
  117. pass
  118. else:
  119. log.error('test_ticket48026: Adding of 4th entry(mailAlternateAddress v mail) incorrectly succeeded')
  120. assert False
  121. log.info('Test complete')
  122. def test_ticket48026_final(topology):
  123. topology.standalone.delete()
  124. log.info('Testcase PASSED')
  125. def run_isolated():
  126. global installation1_prefix
  127. installation1_prefix = None
  128. topo = topology(True)
  129. test_ticket48026(topo)
  130. test_ticket48026_final(topo)
  131. if __name__ == '__main__':
  132. run_isolated()