1
0

ticket48026_test.py 5.6 KB

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