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

Enforce proper website_url formatting in manifests #841

Merged
merged 1 commit into from
Apr 19, 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
2 changes: 2 additions & 0 deletions django/thunderstore/repository/package_manifest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.core.validators import URLValidator
from rest_framework import serializers
from rest_framework.exceptions import ValidationError

Expand Down Expand Up @@ -27,6 +28,7 @@ def __init__(self, *args, **kwargs):
website_url = StrictCharField(
max_length=PackageVersion._meta.get_field("website_url").max_length,
allow_blank=True,
validators=[URLValidator(schemes=["http", "https", "mailto", "ipfs"])],
)
description = StrictCharField(
max_length=PackageVersion._meta.get_field("description").max_length,
Expand Down
25 changes: 21 additions & 4 deletions django/thunderstore/repository/tests/test_package_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,32 @@ def test_manifest_v1_serializer_version_number_validation(
@pytest.mark.parametrize(
"url, error",
[
["asdiasdhuasd", ""],
["asdiasdhuasd", "Enter a valid URL."],
["https://google.com/", ""],
["", ""],
["a", ""],
["some not valid website URL", ""],
["a", "Enter a valid URL."],
["some not valid website URL", "Enter a valid URL."],
["http://google.com/", ""],
["https://google.com/", ""],
["mailto://google.com/", ""],
["ipfs://google.com/", ""],
[None, "This field may not be null."],
["a" * PackageVersion._meta.get_field("website_url").max_length, ""],
[
"a" * PackageVersion._meta.get_field("website_url").max_length,
"Enter a valid URL.",
],
[
"a" * PackageVersion._meta.get_field("website_url").max_length + "b",
"Enter a valid URL.",
],
[
"https://example.org/"
+ ("a" * (PackageVersion._meta.get_field("website_url").max_length - 20)),
"",
],
[
"https://example.org/"
+ ("a" * (PackageVersion._meta.get_field("website_url").max_length - 19)),
"Ensure this field has no more than 1024 characters.",
],
],
Expand Down