allowed_mechs_test.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2017 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 pytest
  10. import os
  11. from lib389.topologies import topology_st
  12. pytestmark = pytest.mark.tier1
  13. def test_basic_feature(topology_st):
  14. """Test the alloweed sasl mechanism feature
  15. :id: b0453b91-9955-4e8f-9d2f-a6bf440022b1
  16. :setup: Standalone instance
  17. :steps:
  18. 1. Get the default list of mechanisms
  19. 2. Set allowed mechanism PLAIN
  20. 3. Verify the list
  21. 4. Restart the server
  22. 5. Verify that list is still correct
  23. 6. Edit mechanisms to allow just PLAIN and EXTERNAL
  24. 7. Verify the list
  25. 8. Edit mechanisms to allow just PLAIN and GSSAPI
  26. 9. Verify the list
  27. 10. Restart the server
  28. 11. Verify that list is still correct
  29. 12. Edit mechanisms to allow just PLAIN, GSSAPI, and ANONYMOUS
  30. 13. Verify the list
  31. 14. Restart the server
  32. 15. Verify that list is still correct
  33. 16. Edit mechanisms to allow just PLAIN and ANONYMOUS
  34. 17. Verify the list
  35. 18. Restart the server
  36. 19. Verify that list is still correct
  37. 20. Reset the allowed list to nothing,
  38. 21. Verify that the returned mechanisms are the default ones
  39. 22. Restart the server
  40. 23. Verify that list is still correct
  41. :expectedresults:
  42. 1. GSSAPI, PLAIN and EXTERNAL mechanisms should be acquired
  43. 2. Operation should be successful
  44. 3. List should have - PLAIN, EXTERNAL; shouldn't have - GSSAPI
  45. 4. Server should be restarted
  46. 5. List should have - PLAIN, EXTERNAL; shouldn't have - GSSAPI
  47. 6. Operation should be successful
  48. 7. List should have - PLAIN, EXTERNAL; shouldn't have - GSSAPI
  49. 8. Operation should be successful
  50. 9. List should have - PLAIN, EXTERNAL, GSSAPI
  51. 10. Server should be restarted
  52. 11. List should have - PLAIN, EXTERNAL, GSSAPI
  53. 12. Operation should be successful
  54. 13. List should have - PLAIN, EXTERNAL, GSSAPI, ANONYMOUS
  55. 14. Server should be restarted
  56. 15. List should have - PLAIN, EXTERNAL, GSSAPI, ANONYMOUS
  57. 16. Operation should be successful
  58. 17. List should have - PLAIN, EXTERNAL, ANONYMOUS; shouldn't have - GSSAPI
  59. 18. Server should be restarted
  60. 19. List should have - PLAIN, EXTERNAL, ANONYMOUS; shouldn't have - GSSAPI
  61. 20. Operation should be successful
  62. 21. List should have - PLAIN, EXTERNAL, GSSAPI
  63. 22. Server should be restarted
  64. 23. List should have - PLAIN, EXTERNAL, GSSAPI
  65. """
  66. standalone = topology_st.standalone
  67. # Get the supported mechanisms. This should contain PLAIN, GSSAPI, EXTERNAL at least
  68. standalone.log.info("Test we have some of the default mechanisms")
  69. orig_mechs = standalone.rootdse.supported_sasl()
  70. print(orig_mechs)
  71. assert('GSSAPI' in orig_mechs)
  72. assert('PLAIN' in orig_mechs)
  73. assert('EXTERNAL' in orig_mechs)
  74. # Now edit the supported mechanisms. Check them again.
  75. standalone.log.info("Edit mechanisms to allow just PLAIN")
  76. standalone.config.set('nsslapd-allowed-sasl-mechanisms', 'PLAIN')
  77. limit_mechs = standalone.rootdse.supported_sasl()
  78. assert('PLAIN' in limit_mechs)
  79. assert('EXTERNAL' in limit_mechs) # Should always be in the allowed list, even if not set.
  80. assert('GSSAPI' not in limit_mechs) # Should not be there!
  81. # Restart the server a few times and make sure nothing changes
  82. standalone.log.info("Restart server and make sure we still have correct allowed mechs")
  83. standalone.restart()
  84. standalone.restart()
  85. limit_mechs = standalone.rootdse.supported_sasl()
  86. assert('PLAIN' in limit_mechs)
  87. assert('EXTERNAL' in limit_mechs)
  88. assert('GSSAPI' not in limit_mechs)
  89. # Set EXTERNAL, even though its always supported
  90. standalone.log.info("Edit mechanisms to allow just PLAIN and EXTERNAL")
  91. standalone.config.set('nsslapd-allowed-sasl-mechanisms', 'PLAIN, EXTERNAL')
  92. limit_mechs = standalone.rootdse.supported_sasl()
  93. assert('PLAIN' in limit_mechs)
  94. assert('EXTERNAL' in limit_mechs)
  95. assert('GSSAPI' not in limit_mechs)
  96. # Now edit the supported mechanisms. Check them again.
  97. standalone.log.info("Edit mechanisms to allow just PLAIN and GSSAPI")
  98. standalone.config.set('nsslapd-allowed-sasl-mechanisms', 'PLAIN, GSSAPI')
  99. limit_mechs = standalone.rootdse.supported_sasl()
  100. assert('PLAIN' in limit_mechs)
  101. assert('EXTERNAL' in limit_mechs)
  102. assert('GSSAPI' in limit_mechs)
  103. assert(len(limit_mechs) == 3)
  104. # Restart server twice and make sure the allowed list is the same
  105. standalone.restart()
  106. standalone.restart() # For ticket 49379 (test double restart)
  107. limit_mechs = standalone.rootdse.supported_sasl()
  108. assert('PLAIN' in limit_mechs)
  109. assert('EXTERNAL' in limit_mechs)
  110. assert('GSSAPI' in limit_mechs)
  111. assert(len(limit_mechs) == 3)
  112. # Add ANONYMOUS to the supported mechanisms and test again.
  113. standalone.log.info("Edit mechanisms to allow just PLAIN, GSSAPI, and ANONYMOUS")
  114. standalone.config.set('nsslapd-allowed-sasl-mechanisms', 'PLAIN, GSSAPI, ANONYMOUS')
  115. limit_mechs = standalone.rootdse.supported_sasl()
  116. assert('PLAIN' in limit_mechs)
  117. assert('EXTERNAL' in limit_mechs)
  118. assert('GSSAPI' in limit_mechs)
  119. assert('ANONYMOUS' in limit_mechs)
  120. assert(len(limit_mechs) == 4)
  121. # Restart server and make sure the allowed list is the same
  122. standalone.restart()
  123. standalone.restart() # For ticket 49379 (test double restart)
  124. limit_mechs = standalone.rootdse.supported_sasl()
  125. assert('PLAIN' in limit_mechs)
  126. assert('EXTERNAL' in limit_mechs)
  127. assert('GSSAPI' in limit_mechs)
  128. assert('ANONYMOUS' in limit_mechs)
  129. assert(len(limit_mechs) == 4)
  130. # Remove GSSAPI
  131. standalone.log.info("Edit mechanisms to allow just PLAIN and ANONYMOUS")
  132. standalone.config.set('nsslapd-allowed-sasl-mechanisms', 'PLAIN, ANONYMOUS')
  133. limit_mechs = standalone.rootdse.supported_sasl()
  134. assert('PLAIN' in limit_mechs)
  135. assert('EXTERNAL' in limit_mechs)
  136. assert('GSSAPI' not in limit_mechs)
  137. assert('ANONYMOUS' in limit_mechs)
  138. assert(len(limit_mechs) == 3)
  139. # Restart server and make sure the allowed list is the same
  140. standalone.restart()
  141. limit_mechs = standalone.rootdse.supported_sasl()
  142. assert('PLAIN' in limit_mechs)
  143. assert('EXTERNAL' in limit_mechs)
  144. assert('GSSAPI' not in limit_mechs)
  145. assert('ANONYMOUS' in limit_mechs)
  146. assert(len(limit_mechs) == 3)
  147. # Do a config reset
  148. standalone.log.info("Reset allowed mechaisms")
  149. standalone.config.reset('nsslapd-allowed-sasl-mechanisms')
  150. # check the supported list is the same as our first check.
  151. standalone.log.info("Check that we have the original set of mechanisms")
  152. final_mechs = standalone.rootdse.supported_sasl()
  153. assert(set(final_mechs) == set(orig_mechs))
  154. # Check it after a restart
  155. standalone.log.info("Check that we have the original set of mechanisms after a restart")
  156. standalone.restart()
  157. final_mechs = standalone.rootdse.supported_sasl()
  158. assert(set(final_mechs) == set(orig_mechs))
  159. if __name__ == '__main__':
  160. # Run isolated
  161. # -s for DEBUG mode
  162. CURRENT_FILE = os.path.realpath(__file__)
  163. pytest.main("-s %s" % CURRENT_FILE)