Skip to content

Commit b1d5718

Browse files
committed
Validate that TRACKER_WEB url starts with https:// or http:// and ends
with a /.
1 parent b06d3fe commit b1d5718

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

roundup/configuration.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,25 @@ def str2value(self, value):
495495
else:
496496
return value
497497

498+
class WebUrlOption(Option):
499+
"""URL MUST start with http/https scheme and end with '/'"""
500+
501+
def str2value(self, value):
502+
if not value:
503+
raise OptionValueError(self,value,"Value must not be empty.")
504+
505+
error_msg = ''
506+
if not value.startswith(('http://', 'https://')):
507+
error_msg = "Value must start with http:// or https://.\n"
508+
509+
if not value.endswith('/'):
510+
error_msg += "Value must end with /."
511+
512+
if error_msg:
513+
raise OptionValueError(self,value,error_msg)
514+
else:
515+
return value
516+
498517
class NullableOption(Option):
499518

500519
"""Option that is set to None if its string value is one of NULL strings
@@ -714,13 +733,13 @@ def str2value(self, value):
714733
("tracker", (
715734
(Option, "name", "Roundup issue tracker",
716735
"A descriptive name for your roundup instance."),
717-
(Option, "web", NODEFAULT,
736+
(WebUrlOption, "web", NODEFAULT,
718737
"The web address that the tracker is viewable at.\n"
719738
"This will be included in information"
720739
" sent to users of the tracker.\n"
721740
"The URL MUST include the cgi-bin part or anything else\n"
722741
"that is required to get to the home page of the tracker.\n"
723-
"You MUST include a trailing '/' in the URL."),
742+
"URL MUST start with http/https scheme and end with '/'"),
724743
(MailAddressOption, "email", "issue_tracker",
725744
"Email address that mail to roundup should go to.\n"
726745
"If no domain is specified then mail_domain is added."),

test/test_config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,21 @@ def test_validConfigKeyword(self):
5050
"""Run configure tests looking for invalid option name
5151
"""
5252
self.assertEquals(config._get_option("FOO"), "value")
53+
54+
def testTrackerWeb(self):
55+
config = configuration.CoreConfig()
56+
57+
self.assertEqual(None,
58+
config._get_option('TRACKER_WEB').set("http://foo.example/bar/"))
59+
self.assertEqual(None,
60+
config._get_option('TRACKER_WEB').set("https://foo.example/bar/"))
61+
62+
self.assertRaises(configuration.OptionValueError,
63+
config._get_option('TRACKER_WEB').set, "https://foo.example/bar")
64+
65+
self.assertRaises(configuration.OptionValueError,
66+
config._get_option('TRACKER_WEB').set, "htt://foo.example/bar/")
67+
68+
self.assertRaises(configuration.OptionValueError,
69+
config._get_option('TRACKER_WEB').set, "htt://foo.example/bar")
70+

0 commit comments

Comments
 (0)