Skip to content

Commit

Permalink
fix(api): validate that url must be a valid url with http or https (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
vvatelot authored Dec 8, 2023
1 parent 54fb84a commit 9141d1c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions components/ecoindex/models/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class WebPage(BaseModel):
@classmethod
def url_as_http_url(cls, v: str) -> str:
url_object = AnyHttpUrl(url=v)
assert url_object.scheme in {"http", "https"}, "scheme must be http or https"

return url_object.unicode_string()

Expand Down
3 changes: 3 additions & 0 deletions test/components/ecoindex/compute/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def test_model_webpage_invalid_url() -> None:
"[type=url_parsing, input_value='toto', input_type=str]\n"
) in str(error.value)

with raises(ValidationError):
WebPage(url="about:config")


def test_model_webpage_wrong_size() -> None:
with raises(ValidationError) as error:
Expand Down

0 comments on commit 9141d1c

Please sign in to comment.