1616import logging
1717import mock
1818
19+ import six
1920from six .moves import configparser
2021
2122import testtools
@@ -123,6 +124,7 @@ def test_load_settings(self):
123124 c = config .KmipServerConfig ()
124125 c ._logger = mock .MagicMock ()
125126 c ._parse_settings = mock .MagicMock ()
127+ c .parse_auth_settings = mock .MagicMock ()
126128
127129 # Test that the right calls are made when correctly processing the
128130 # configuration file.
@@ -138,6 +140,7 @@ def test_load_settings(self):
138140 )
139141 parser_mock .assert_called_with ("/test/path/server.conf" )
140142 self .assertTrue (c ._parse_settings .called )
143+ self .assertTrue (c .parse_auth_settings .called )
141144
142145 # Test that a ConfigurationError is generated when the path is invalid.
143146 c ._logger .reset_mock ()
@@ -151,6 +154,66 @@ def test_load_settings(self):
151154 * args
152155 )
153156
157+ def test_parse_auth_settings (self ):
158+ """
159+ Test that server authentication plugin settings are parsed correctly.
160+ """
161+ parser = configparser .SafeConfigParser ()
162+ parser .add_section ('server' )
163+ parser .add_section ('auth:slugs' )
164+ parser .set ('auth:slugs' , 'enabled' , 'True' )
165+ parser .set ('auth:slugs' , 'url' , 'http://127.0.0.1:8080/slugs/' )
166+ parser .add_section ('auth:ldap' )
167+ parser .set ('auth:ldap' , 'enabled' , 'False' )
168+ parser .set ('auth:ldap' , 'url' , 'http://127.0.0.1:8080/ldap/' )
169+
170+ c = config .KmipServerConfig ()
171+ c ._logger = mock .MagicMock ()
172+
173+ self .assertEqual ([], c .settings ['auth_plugins' ])
174+
175+ c .parse_auth_settings (parser )
176+ configs = c .settings ['auth_plugins' ]
177+
178+ self .assertIsInstance (configs , list )
179+ self .assertEqual (2 , len (configs ))
180+
181+ for c in configs :
182+ self .assertIsInstance (c , tuple )
183+ self .assertEqual (2 , len (c ))
184+ self .assertIn (c [0 ], ['auth:slugs' , 'auth:ldap' ])
185+ self .assertIsInstance (c [1 ], dict )
186+
187+ if c [0 ] == 'auth:slugs' :
188+ self .assertIn ('enabled' , six .iterkeys (c [1 ]))
189+ self .assertEqual ('True' , c [1 ]['enabled' ])
190+ self .assertIn ('url' , six .iterkeys (c [1 ]))
191+ self .assertEqual ('http://127.0.0.1:8080/slugs/' , c [1 ]['url' ])
192+ elif c [0 ] == 'auth:ldap' :
193+ self .assertIn ('enabled' , six .iterkeys (c [1 ]))
194+ self .assertEqual ('False' , c [1 ]['enabled' ])
195+ self .assertIn ('url' , six .iterkeys (c [1 ]))
196+ self .assertEqual ('http://127.0.0.1:8080/ldap/' , c [1 ]['url' ])
197+
198+ def test_parse_auth_settings_no_config (self ):
199+ """
200+ Test that server authentication plugin settings are parsed correctly,
201+ even when not specified.
202+ """
203+ parser = configparser .SafeConfigParser ()
204+ parser .add_section ('server' )
205+
206+ c = config .KmipServerConfig ()
207+ c ._logger = mock .MagicMock ()
208+
209+ self .assertEqual ([], c .settings ['auth_plugins' ])
210+
211+ c .parse_auth_settings (parser )
212+ configs = c .settings ['auth_plugins' ]
213+
214+ self .assertIsInstance (configs , list )
215+ self .assertEqual (0 , len (configs ))
216+
154217 def test_parse_settings (self ):
155218 """
156219 Test that the right methods are called and the right errors generated
0 commit comments