Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): validate that url must be a valid url with http or https #19

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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