mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(util): catch homepage validation exceptions
We were allowing erroneous URLs through, raising exceptions, from e.g. `http://[localhost:8444/blah`. This patch catches any ValueErrors raised during the parse process and returns False, indicating that the validation failed. This patch also adds testing specifically for `util.valid_homepage`. We didn't have specific testing for this before; this will allow us to catch regressions in this area. Closes #250 Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
1ee8d177b4
commit
60ae676075
2 changed files with 13 additions and 1 deletions
|
@ -63,7 +63,10 @@ def valid_email(email):
|
|||
|
||||
|
||||
def valid_homepage(homepage):
|
||||
parts = urlparse(homepage)
|
||||
try:
|
||||
parts = urlparse(homepage)
|
||||
except ValueError:
|
||||
return False
|
||||
return parts.scheme in ("http", "https") and bool(parts.netloc)
|
||||
|
||||
|
||||
|
|
|
@ -85,3 +85,12 @@ async def test_error_or_result():
|
|||
|
||||
response = await util.error_or_result(good_route, Request())
|
||||
assert response.status_code == HTTPStatus.OK
|
||||
|
||||
|
||||
def test_valid_homepage():
|
||||
assert util.valid_homepage("http://google.com")
|
||||
assert util.valid_homepage("https://google.com")
|
||||
assert not util.valid_homepage("http://[google.com/broken-ipv6")
|
||||
assert not util.valid_homepage("https://[google.com/broken-ipv6")
|
||||
|
||||
assert not util.valid_homepage("gopher://gopher.hprc.utoronto.ca/")
|
||||
|
|
Loading…
Add table
Reference in a new issue