diff --git a/spylib/utils/domain.py b/spylib/utils/domain.py index 0c90ace..109d6b3 100644 --- a/spylib/utils/domain.py +++ b/spylib/utils/domain.py @@ -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') diff --git a/tests/oauth/test_base.py b/tests/oauth/test_base.py index b25f2d0..d7c7338 100644 --- a/tests/oauth/test_base.py +++ b/tests/oauth/test_base.py @@ -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' @@ -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'