ticket47640_test.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. def fin():
  47. standalone.delete()
  48. request.addfinalizer(fin)
  49. return TopologyStandalone(standalone)
  50. def test_ticket47640(topology):
  51. '''
  52. Linked Attrs Plugins - verify that if the plugin fails to update the link entry
  53. that the entire operation is aborted
  54. '''
  55. # Enable Dynamic plugins, and the linked Attrs plugin
  56. try:
  57. topology.standalone.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-dynamic-plugins', 'on')])
  58. except ldap.LDAPError as e:
  59. ldap.fatal('Failed to enable dynamic plugin!' + e.message['desc'])
  60. assert False
  61. try:
  62. topology.standalone.plugins.enable(name=PLUGIN_LINKED_ATTRS)
  63. except ValueError as e:
  64. ldap.fatal('Failed to enable linked attributes plugin!' + e.message['desc'])
  65. assert False
  66. # Add the plugin config entry
  67. try:
  68. topology.standalone.add_s(Entry(('cn=manager link,cn=Linked Attributes,cn=plugins,cn=config', {
  69. 'objectclass': 'top extensibleObject'.split(),
  70. 'cn': 'Manager Link',
  71. 'linkType': 'seeAlso',
  72. 'managedType': 'seeAlso'
  73. })))
  74. except ldap.LDAPError as e:
  75. log.fatal('Failed to add linked attr config entry: error ' + e.message['desc'])
  76. assert False
  77. # Add an entry who has a link to an entry that does not exist
  78. OP_REJECTED = False
  79. try:
  80. topology.standalone.add_s(Entry(('uid=manager,' + DEFAULT_SUFFIX, {
  81. 'objectclass': 'top extensibleObject'.split(),
  82. 'uid': 'manager',
  83. 'seeAlso': 'uid=user,dc=example,dc=com'
  84. })))
  85. except ldap.UNWILLING_TO_PERFORM:
  86. # Success
  87. log.info('Add operation correctly rejected.')
  88. OP_REJECTED = True
  89. except ldap.LDAPError as e:
  90. log.fatal('Add operation incorrectly rejected: error %s - ' +
  91. 'expected "unwilling to perform"' % e.message['desc'])
  92. assert False
  93. if not OP_REJECTED:
  94. log.fatal('Add operation incorrectly allowed')
  95. assert False
  96. log.info('Test complete')
  97. if __name__ == '__main__':
  98. # Run isolated
  99. # -s for DEBUG mode
  100. CURRENT_FILE = os.path.realpath(__file__)
  101. pytest.main("-s %s" % CURRENT_FILE)