Skip to content

Commit

Permalink
Fix invalid iconUrl on Safe App creation (#1107)
Browse files Browse the repository at this point in the history
* Generate logo URLs by calling `uuid.uuid4()` instead of relying on the Safe App ID.
  • Loading branch information
hectorgomezv authored Apr 23, 2024
1 parent 70da0ae commit aea1c6b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/safe_apps/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import uuid
from enum import Enum
from typing import IO, Union

Expand All @@ -17,7 +18,7 @@

def safe_app_icon_path(instance: "SafeApp", filename: str) -> str:
_, file_extension = os.path.splitext(filename)
return f"safe_apps/{instance.app_id}/icon{file_extension}"
return f"safe_apps/{uuid.uuid4()}/icon{file_extension}"


def validate_safe_app_icon_size(image: Union[str, IO[bytes]]) -> None:
Expand Down
9 changes: 7 additions & 2 deletions src/safe_apps/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ class IconTestCase(TestCase):
def test_icon_upload_path(self) -> None:
safe_app = SafeAppFactory.create()

self.assertEqual(
safe_app.icon_url.url, f"/media/safe_apps/{safe_app.app_id}/icon.jpg"
path_regex = "|".join(
[
r"\/media\/safe_apps\/",
r"[0-9(a-f|A-F)]{8}-[0-9(a-f|A-F)]{4}-4[0-9(a-f|A-F)]{3}-[89ab][0-9(a-f|A-F)]{3}-[0-9(a-f|A-F)]{12}",
r"\/icon.jpg",
]
)
self.assertRegex(safe_app.icon_url.url, path_regex)

def test_icon_max_size_validation(self) -> None:
safe_app = SafeAppFactory.create(
Expand Down

0 comments on commit aea1c6b

Please sign in to comment.