ticket48893_test.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. DEBUGGING = False
  14. if DEBUGGING:
  15. logging.getLogger(__name__).setLevel(logging.DEBUG)
  16. else:
  17. logging.getLogger(__name__).setLevel(logging.INFO)
  18. log = logging.getLogger(__name__)
  19. class TopologyStandalone(object):
  20. """The DS Topology Class"""
  21. def __init__(self, standalone):
  22. """Init"""
  23. standalone.open()
  24. self.standalone = standalone
  25. @pytest.fixture(scope="module")
  26. def topology(request):
  27. """Create DS Deployment"""
  28. # Creating standalone instance ...
  29. if DEBUGGING:
  30. standalone = DirSrv(verbose=True)
  31. else:
  32. standalone = DirSrv(verbose=False)
  33. args_instance[SER_HOST] = HOST_STANDALONE
  34. args_instance[SER_PORT] = PORT_STANDALONE
  35. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  36. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  37. args_standalone = args_instance.copy()
  38. standalone.allocate(args_standalone)
  39. instance_standalone = standalone.exists()
  40. if instance_standalone:
  41. standalone.delete()
  42. standalone.create()
  43. standalone.open()
  44. def fin():
  45. """If we are debugging just stop the instances, otherwise remove
  46. them
  47. """
  48. if DEBUGGING:
  49. standalone.stop(60)
  50. else:
  51. standalone.delete()
  52. request.addfinalizer(fin)
  53. # Clear out the tmp dir
  54. standalone.clearTmpDir(__file__)
  55. return TopologyStandalone(standalone)
  56. def _attr_present(conn):
  57. results = conn.search_s('cn=config', ldap.SCOPE_SUBTREE, '(objectClass=*)')
  58. if DEBUGGING:
  59. print(results)
  60. if len(results) > 0:
  61. return True
  62. return False
  63. def test_ticket48893(topology):
  64. """
  65. Test that anonymous has NO VIEW to cn=config
  66. """
  67. if DEBUGGING:
  68. # Add debugging steps(if any)...
  69. pass
  70. # Do an anonymous bind
  71. conn = ldap.initialize("ldap://%s:%s" % (HOST_STANDALONE, PORT_STANDALONE))
  72. conn.simple_bind_s()
  73. # Make sure that we cannot see what's in cn=config as anonymous
  74. assert(not _attr_present(conn))
  75. conn.unbind_s()
  76. log.info('Test PASSED')
  77. if __name__ == '__main__':
  78. # Run isolated
  79. # -s for DEBUG mode
  80. CURRENT_FILE = os.path.realpath(__file__)
  81. pytest.main("-s %s" % CURRENT_FILE)