Debian Codegraph @

dirsrvtests/tests/suites/sasl/allowed_mechs_test.py

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