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 store domain regex #222

Merged
merged 3 commits into from
Aug 16, 2024
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: 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
18 changes: 15 additions & 3 deletions 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 @@ -90,8 +90,6 @@ async def test_oauth_with_fastapi(mocker):
response = client.get('/shopify/auth')
assert response.status_code == 422
response_json = response.json()
# the url will change according to the pydantic version installed
del response_json['detail'][0]['url']
assert response_json == {
'detail': [
{'input': None, 'loc': ['query', 'shop'], 'msg': 'Field required', 'type': 'missing'}
Expand Down Expand Up @@ -212,3 +210,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'
6 changes: 3 additions & 3 deletions tests/token_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class MockHTTPResponse(BaseModel):
jsondata: Optional[dict] = None
headers: dict = {'X-Shopify-Shop-Api-Call-Limit': '39/40'}

def json(self):
def json(self): # type: ignore[override]
# Mock trying to deserialize something that's not a valid JSON
if self.jsondata is None:
loads('NOT A JSON')
return self.jsondata
loads('Not a JSON')
return self.jsondata # type: ignore[return-value]


class TestInformation(BaseModel):
Expand Down
Loading