Skip to content

Commit d00ed44

Browse files
committed
specialize URIValidator to validate redirect URIs
1 parent 190b6de commit d00ed44

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

oauth2_provider/tests/test_validators.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88

99
class TestValidators(TestCase):
1010
def test_validate_good_uris(self):
11-
good_urls = 'http://example.com/ http://example.it/?key=val'
11+
good_urls = 'http://example.com/ http://example.it/?key=val http://example'
1212
# Check ValidationError not thrown
1313
validate_uris(good_urls)
1414

1515
def test_validate_bad_uris(self):
16-
bad_urls = 'http://example.com http://example'
17-
self.assertRaises(ValidationError, validate_uris, bad_urls)
16+
bad_url = 'http://example.com/#fragment'
17+
self.assertRaises(ValidationError, validate_uris, bad_url)
18+
bad_url = 'http:/example.com'
19+
self.assertRaises(ValidationError, validate_uris, bad_url)

oauth2_provider/validators.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@ def __call__(self, value):
4040
url = value
4141

4242

43+
class RedirectURIValidator(URIValidator):
44+
def __call__(self, value):
45+
super(RedirectURIValidator, self).__call__(value)
46+
if len(value.split('#')) > 1:
47+
raise ValidationError('Redirect URIs must not contain fragments')
48+
49+
4350
def validate_uris(value):
4451
"""
4552
This validator ensures that `value` contains valid blank-separated urls"
4653
"""
47-
v = URIValidator()
54+
v = RedirectURIValidator()
4855
for uri in value.split():
4956
v(uri)

0 commit comments

Comments
 (0)