Skip to content

Commit

Permalink
fix store domain regex
Browse files Browse the repository at this point in the history
  • Loading branch information
lishanl committed Aug 16, 2024
1 parent b8f67ba commit e878d0f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spylib/utils/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def domain_to_storename(domain: str) -> str:

def store_domain(shop: str) -> str:
"""Conversion of a shop's subdomain or complete or incomplete url into a complete url."""
result = search(r'^(https:\/\/)?([a-z1-9\-]+)(\.myshopify\.com[\/]?)?$', shop.lower())
result = search(r'^(https:\/\/)?([^.]+)(\.myshopify\.com[\/]?)?$', shop.lower())
if not result:
raise ValueError(f'{shop} is not a shopify shop')

Expand Down
16 changes: 15 additions & 1 deletion tests/oauth/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from spylib import hmac
from spylib.exceptions import FastAPIImportError
from spylib.utils import JWTBaseModel, now_epoch
from spylib.utils import JWTBaseModel, domain_to_storename, now_epoch, store_domain

SHOPIFY_API_KEY = 'API_KEY'
SHOPIFY_SECRET_KEY = 'SECRET_KEY'
Expand Down Expand Up @@ -212,3 +212,17 @@ def check_oauth_redirect_query(query: str, scope: List[str], query_extra: dict =
assert parsed_query == expected_query

return state


def test_domain_to_storename():
assert domain_to_storename(domain='test.myshopify.com') == 'test'
assert domain_to_storename(domain='test2.myshopify.com') == 'test2'
assert domain_to_storename(domain='test-v2.myshopify.com') == 'test-v2'
assert domain_to_storename(domain='test-2-0.myshopify.com') == 'test-2-0'


def test_store_domain():
assert store_domain(shop='test.myshopify.com') == 'test.myshopify.com'
assert store_domain(shop='test-2.myshopify.com') == 'test-2.myshopify.com'
assert store_domain(shop='test-v2.myshopify.com') == 'test-v2.myshopify.com'
assert store_domain(shop='test-2-0.myshopify.com') == 'test-2-0.myshopify.com'

0 comments on commit e878d0f

Please sign in to comment.