Skip to content

Commit 742b24c

Browse files
Merge pull request #399 from OpenKMIP/feat/update-server-config
Update server config handling to parse auth plugin settings
2 parents 44eb5f0 + e215ddb commit 742b24c

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

kmip/services/server/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self):
3737
self.settings['enable_tls_client_auth'] = True
3838
self.settings['tls_cipher_suites'] = []
3939
self.settings['logging_level'] = logging.INFO
40+
self.settings['auth_plugins'] = []
4041

4142
self._expected_settings = [
4243
'hostname',
@@ -121,6 +122,12 @@ def load_settings(self, path):
121122
parser = configparser.SafeConfigParser()
122123
parser.read(path)
123124
self._parse_settings(parser)
125+
self.parse_auth_settings(parser)
126+
127+
def parse_auth_settings(self, parser):
128+
sections = [x for x in parser.sections() if x.startswith("auth:")]
129+
configs = [(x, dict(parser.items(x))) for x in sections]
130+
self.settings['auth_plugins'] = configs
124131

125132
def _parse_settings(self, parser):
126133
if not parser.has_section('server'):

kmip/tests/unit/services/server/test_config.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import logging
1717
import mock
1818

19+
import six
1920
from six.moves import configparser
2021

2122
import 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

Comments
 (0)