ticket47937_test.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2016 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 logging
  10. import time
  11. import ldap
  12. import pytest
  13. from lib389 import Entry
  14. from lib389._constants import *
  15. from lib389.topologies import topology_st
  16. log = logging.getLogger(__name__)
  17. def test_ticket47937(topology_st):
  18. """
  19. Test that DNA plugin only accepts valid attributes for "dnaType"
  20. """
  21. log.info("Creating \"ou=people\"...")
  22. try:
  23. topology_st.standalone.add_s(Entry(('ou=people,' + SUFFIX, {
  24. 'objectclass': 'top organizationalunit'.split(),
  25. 'ou': 'people'
  26. })))
  27. except ldap.ALREADY_EXISTS:
  28. pass
  29. except ldap.LDAPError as e:
  30. log.error('Failed to add ou=people org unit: error ' + e.message['desc'])
  31. assert False
  32. log.info("Creating \"ou=ranges\"...")
  33. try:
  34. topology_st.standalone.add_s(Entry(('ou=ranges,' + SUFFIX, {
  35. 'objectclass': 'top organizationalunit'.split(),
  36. 'ou': 'ranges'
  37. })))
  38. except ldap.LDAPError as e:
  39. log.error('Failed to add ou=ranges org unit: error ' + e.message['desc'])
  40. assert False
  41. log.info("Creating \"cn=entry\"...")
  42. try:
  43. topology_st.standalone.add_s(Entry(('cn=entry,ou=people,' + SUFFIX, {
  44. 'objectclass': 'top groupofuniquenames'.split(),
  45. 'cn': 'entry'
  46. })))
  47. except ldap.LDAPError as e:
  48. log.error('Failed to add test entry: error ' + e.message['desc'])
  49. assert False
  50. log.info("Creating DNA shared config entry...")
  51. try:
  52. topology_st.standalone.add_s(Entry(('dnaHostname=localhost.localdomain+dnaPortNum=389,ou=ranges,%s' % SUFFIX, {
  53. 'objectclass': 'top dnaSharedConfig'.split(),
  54. 'dnaHostname': 'localhost.localdomain',
  55. 'dnaPortNum': '389',
  56. 'dnaSecurePortNum': '636',
  57. 'dnaRemainingValues': '9501'
  58. })))
  59. except ldap.LDAPError as e:
  60. log.error('Failed to add shared config entry: error ' + e.message['desc'])
  61. assert False
  62. log.info("Add dna plugin config entry...")
  63. try:
  64. topology_st.standalone.add_s(
  65. Entry(('cn=dna config,cn=Distributed Numeric Assignment Plugin,cn=plugins,cn=config', {
  66. 'objectclass': 'top dnaPluginConfig'.split(),
  67. 'dnaType': 'description',
  68. 'dnaMaxValue': '10000',
  69. 'dnaMagicRegen': '0',
  70. 'dnaFilter': '(objectclass=top)',
  71. 'dnaScope': 'ou=people,%s' % SUFFIX,
  72. 'dnaNextValue': '500',
  73. 'dnaSharedCfgDN': 'ou=ranges,%s' % SUFFIX
  74. })))
  75. except ldap.LDAPError as e:
  76. log.error('Failed to add DNA config entry: error ' + e.message['desc'])
  77. assert False
  78. log.info("Enable the DNA plugin...")
  79. try:
  80. topology_st.standalone.plugins.enable(name=PLUGIN_DNA)
  81. except e:
  82. log.error("Failed to enable DNA Plugin: error " + e.message['desc'])
  83. assert False
  84. log.info("Restarting the server...")
  85. topology_st.standalone.stop(timeout=120)
  86. time.sleep(1)
  87. topology_st.standalone.start(timeout=120)
  88. time.sleep(3)
  89. log.info("Apply an invalid attribute to the DNA config(dnaType: foo)...")
  90. try:
  91. topology_st.standalone.modify_s('cn=dna config,cn=Distributed Numeric Assignment Plugin,cn=plugins,cn=config',
  92. [(ldap.MOD_REPLACE, 'dnaType', 'foo')])
  93. except ldap.LDAPError as e:
  94. log.info('Operation failed as expected (error: %s)' % e.message['desc'])
  95. else:
  96. log.error('Operation incorectly succeeded! Test Failed!')
  97. assert False
  98. if __name__ == '__main__':
  99. # Run isolated
  100. # -s for DEBUG mode
  101. CURRENT_FILE = os.path.realpath(__file__)
  102. pytest.main("-s %s" % CURRENT_FILE)