Skip to content

Commit 4572170

Browse files
committed
Show an error for username= without password=. Fixes #728
1 parent b7e4ed8 commit 4572170

File tree

3 files changed

+68
-8
lines changed

3 files changed

+68
-8
lines changed

CHANGES.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Next 3.x Release
2+
----------------
3+
4+
- Parsing the config file will now fail with an error message if an
5+
``inet_http_server`` or ``unix_http_server`` section contains a ``username=``
6+
but no ``password=``. In previous versions, ``supervisord`` would start with
7+
this invalid configuration but the HTTP server would always return a 500
8+
Internal Server Error. Thanks to Chris Ergatides for reporting this issue.
9+
110
3.2.1 (2016-02-06)
211
------------------
312

supervisor/options.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -988,10 +988,12 @@ def _parse_username_and_password(self, parser, section):
988988
get = parser.saneget
989989
username = get(section, 'username', None)
990990
password = get(section, 'password', None)
991-
if username is None and password is not None:
992-
raise ValueError(
993-
'Must specify username if password is specified in [%s]'
994-
% section)
991+
if username is not None or password is not None:
992+
if username is None or password is None:
993+
raise ValueError(
994+
'Section [%s] contains incomplete authentication: '
995+
'If a username or a password is specified, both the '
996+
'username and password must be specified' % section)
995997
return {'username':username, 'password':password}
996998

997999
def server_configs_from_parser(self, parser):

supervisor/tests/test_options.py

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,13 +1123,36 @@ def test_options_afunix_no_file(self):
11231123
self.assertEqual(exc.args[0],
11241124
"section [unix_http_server] has no file value")
11251125

1126+
def test_options_afunix_username_without_password(self):
1127+
instance = self._makeOne()
1128+
text = lstrip("""\
1129+
[supervisord]
1130+
1131+
[unix_http_server]
1132+
file=/tmp/supvtest.sock
1133+
username=usernamehere
1134+
;no password=
1135+
chmod=0755
1136+
""")
1137+
instance.configfile = StringIO(text)
1138+
try:
1139+
instance.read_config(StringIO(text))
1140+
self.fail("nothing raised")
1141+
except ValueError as exc:
1142+
self.assertEqual(exc.args[0],
1143+
'Section [unix_http_server] contains incomplete '
1144+
'authentication: If a username or a password is '
1145+
'specified, both the username and password must '
1146+
'be specified')
1147+
11261148
def test_options_afunix_password_without_username(self):
11271149
instance = self._makeOne()
11281150
text = lstrip("""\
11291151
[supervisord]
11301152
11311153
[unix_http_server]
11321154
file=/tmp/supvtest.sock
1155+
;no username=
11331156
password=passwordhere
11341157
chmod=0755
11351158
""")
@@ -1139,8 +1162,10 @@ def test_options_afunix_password_without_username(self):
11391162
self.fail("nothing raised")
11401163
except ValueError, exc:
11411164
self.assertEqual(exc.args[0],
1142-
"Must specify username if password is specified "
1143-
"in [unix_http_server]")
1165+
'Section [unix_http_server] contains incomplete '
1166+
'authentication: If a username or a password is '
1167+
'specified, both the username and password must '
1168+
'be specified')
11441169

11451170
def test_options_afunix_file_expands_here(self):
11461171
instance = self._makeOne()
@@ -1167,6 +1192,28 @@ def test_options_afunix_file_expands_here(self):
11671192
finally:
11681193
shutil.rmtree(here, ignore_errors=True)
11691194

1195+
def test_options_afinet_username_without_password(self):
1196+
instance = self._makeOne()
1197+
text = lstrip("""\
1198+
[supervisord]
1199+
1200+
[inet_http_server]
1201+
file=/tmp/supvtest.sock
1202+
username=usernamehere
1203+
;no password=
1204+
chmod=0755
1205+
""")
1206+
instance.configfile = StringIO(text)
1207+
try:
1208+
instance.read_config(StringIO(text))
1209+
self.fail("nothing raised")
1210+
except ValueError as exc:
1211+
self.assertEqual(exc.args[0],
1212+
'Section [inet_http_server] contains incomplete '
1213+
'authentication: If a username or a password is '
1214+
'specified, both the username and password must '
1215+
'be specified')
1216+
11701217
def test_options_afinet_password_without_username(self):
11711218
instance = self._makeOne()
11721219
text = lstrip("""\
@@ -1182,8 +1229,10 @@ def test_options_afinet_password_without_username(self):
11821229
self.fail("nothing raised")
11831230
except ValueError, exc:
11841231
self.assertEqual(exc.args[0],
1185-
"Must specify username if password is specified "
1186-
"in [inet_http_server]")
1232+
'Section [inet_http_server] contains incomplete '
1233+
'authentication: If a username or a password is '
1234+
'specified, both the username and password must '
1235+
'be specified')
11871236

11881237
def test_options_afinet_no_port(self):
11891238
instance = self._makeOne()

0 commit comments

Comments
 (0)