dsidm_config_test.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2020 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 time
  10. import pytest
  11. import logging
  12. import os
  13. from lib389 import DEFAULT_SUFFIX
  14. from lib389.cli_idm.client_config import sssd_conf, ldap_conf, display
  15. from lib389.plugins import MemberOfPlugin
  16. from lib389.topologies import topology_st
  17. from lib389.cli_base import FakeArgs
  18. from lib389.idm.group import Groups
  19. from lib389.idm.user import nsUserAccounts
  20. from lib389.utils import ds_is_older
  21. pytestmark = pytest.mark.tier0
  22. LOG_FILE = '/tmp/dsidm.log'
  23. logging.getLogger(__name__).setLevel(logging.DEBUG)
  24. log = logging.getLogger(__name__)
  25. @pytest.fixture(scope="function")
  26. def set_log_file(request):
  27. fh = logging.FileHandler(LOG_FILE)
  28. fh.setLevel(logging.DEBUG)
  29. log.addHandler(fh)
  30. def fin():
  31. log.info('Delete log file')
  32. os.remove(LOG_FILE)
  33. request.addfinalizer(fin)
  34. def check_value_in_log_and_reset(content_list, content_list2=None, check_value=None):
  35. with open(LOG_FILE, 'r+') as f:
  36. file_content = f.read()
  37. if content_list2 is not None:
  38. log.info('Check if content is present in output')
  39. for item in content_list + content_list2:
  40. assert item.lower() in file_content.lower()
  41. else:
  42. log.info('Check if content is present in output')
  43. for item in content_list:
  44. assert item.lower() in file_content.lower()
  45. if check_value is not None:
  46. log.info('Check if value is present in output')
  47. assert check_value in file_content
  48. log.info('Reset log file for next test')
  49. f.truncate(0)
  50. @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
  51. def test_dsidm_config_sssd(topology_st, set_log_file):
  52. """ Test dsidm creation of sssd.conf content
  53. :id: 77812ba6-b133-40f4-91a7-13309618f24d
  54. :setup: Standalone instance
  55. :steps:
  56. 1. Run dsidm client_config sssd.conf
  57. 2. Enable MemberOfPlugin
  58. 3. Run dsidm client_config sssd.conf with allowed group
  59. :expectedresults:
  60. 1. Success
  61. 2. Success
  62. 3. Success
  63. """
  64. standalone = topology_st.standalone
  65. sssd_content_list = ['Generated by 389 Directory Server - dsidm',
  66. 'id_provider = ldap',
  67. 'auth_provider = ldap',
  68. 'access_provider = ldap',
  69. 'chpass_provider = ldap',
  70. 'ldap_search_base = ' + DEFAULT_SUFFIX,
  71. 'ldap_uri = ' + standalone.ldapuri,
  72. 'ldap_user_member_of = memberof',
  73. 'ignore_group_members = False',
  74. '[sssd]',
  75. 'services = nss, pam, ssh, sudo',
  76. 'config_file_version = 2',
  77. 'domains = ldap',
  78. '[nss]',
  79. 'homedir_substring = /home']
  80. schema = 'ldap_schema = rfc2307'
  81. args = FakeArgs()
  82. args.allowed_group = None
  83. log.info('Create sssd.conf content')
  84. sssd_conf(standalone, DEFAULT_SUFFIX, log, args)
  85. log.info('Check if config creation was successful')
  86. check_value_in_log_and_reset(sssd_content_list, check_value=schema)
  87. log.info('Now we test allowed_group argument')
  88. log.info('Enable MemberOf plugin')
  89. plugin = MemberOfPlugin(standalone)
  90. plugin.enable()
  91. standalone.restart()
  92. log.info('Create test group')
  93. groups = Groups(standalone, DEFAULT_SUFFIX)
  94. test_group = groups.create(properties={"cn": "new_group",
  95. "description": "testgroup"})
  96. log.info('Create sssd.conf content with allowed group')
  97. filter_msg = ['ldap_access_filter = (memberOf={})'.format(test_group.dn), 'ldap_schema = rfc2307bis']
  98. args.allowed_group = test_group.rdn
  99. sssd_conf(standalone, DEFAULT_SUFFIX, log, args)
  100. log.info('Check if config creation was successful')
  101. check_value_in_log_and_reset(sssd_content_list, filter_msg)
  102. @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
  103. def test_dsidm_config_ldap(topology_st, set_log_file):
  104. """ Test dsidm creation of ldap.conf content
  105. :id: 29ffcc91-9104-4c90-bcdf-0f6a4082322c
  106. :setup: Standalone instance
  107. :steps:
  108. 1. Create instance
  109. 2. Run dsidm client_config ldap.conf
  110. :expectedresults:
  111. 1. Success
  112. 2. Success
  113. """
  114. standalone = topology_st.standalone
  115. args = FakeArgs()
  116. ldap_content_list = ['OpenLDAP client configuration',
  117. 'Generated by 389 Directory Server - dsidm',
  118. 'BASE ' + DEFAULT_SUFFIX,
  119. 'URI ' + standalone.ldapuri,
  120. 'DEREF never',
  121. 'TLS_CACERTDIR /etc/openldap/certs']
  122. log.info('Create ldap.conf content')
  123. ldap_conf(standalone, DEFAULT_SUFFIX, log, args)
  124. log.info('Check if config creation was successful')
  125. check_value_in_log_and_reset(ldap_content_list)
  126. @pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented")
  127. def test_dsidm_config_display(topology_st, set_log_file):
  128. """ Test dsidm display option
  129. :id: 6e888ae2-8835-44d5-846b-e971d76aa461
  130. :setup: Standalone instance
  131. :steps:
  132. 1. Run dsidm client_config display
  133. 2. Enable MemberOfPlugin
  134. 3. Run dsidm client_config display with MemberOfPlugin
  135. :expectedresults:
  136. 1. Success
  137. 2. Success
  138. 3. Success
  139. """
  140. standalone = topology_st.standalone
  141. users = nsUserAccounts(standalone, DEFAULT_SUFFIX)
  142. groups = Groups(standalone, DEFAULT_SUFFIX)
  143. display_content_list = ['ldap_uri = ' + standalone.ldapuri,
  144. 'ldap_uri = ldaps:///dc%3Dexample%2Cdc%3Dcom',
  145. 'group_basedn = ' + groups._basedn,
  146. 'basedn = ' + DEFAULT_SUFFIX,
  147. 'user_basedn = ' + users._basedn,
  148. 'user_filter = (&(objectclass=nsPerson)(objectclass=nsAccount)(objectclass=nsOrgPerson)'
  149. '(objectclass=posixAccount))',
  150. 'unique id = nsUniqueId',
  151. 'group member attribute = member',
  152. 'user rdn = uid',
  153. 'user identifier = uid',
  154. 'group_filter = (&(objectclass=groupOfNames))',
  155. 'group rdn = cn']
  156. schema_type = 'rfc2307'
  157. args = FakeArgs()
  158. log.info('Test dsidm display option')
  159. display(standalone, DEFAULT_SUFFIX, log, args)
  160. log.info('Check if display option was successful')
  161. check_value_in_log_and_reset(display_content_list, check_value=schema_type)
  162. log.info('Enable MemberOf plugin')
  163. plugin = MemberOfPlugin(standalone)
  164. plugin.enable()
  165. standalone.restart()
  166. log.info('Test dsidm display option with MemberOf plugin')
  167. display(standalone, DEFAULT_SUFFIX, log, args)
  168. log.info('Check if display option was successful with MemberOf plugin enabled')
  169. schema_type = 'rfc2307bis'
  170. check_value_in_log_and_reset(display_content_list, check_value=schema_type)
  171. if __name__ == '__main__':
  172. # Run isolated
  173. # -s for DEBUG mode
  174. CURRENT_FILE = os.path.realpath(__file__)
  175. pytest.main("-s %s" % CURRENT_FILE)