Skip to content

Commit

Permalink
Merge branch 'main' into demo
Browse files Browse the repository at this point in the history
  • Loading branch information
nrh-cklimas committed Jan 10, 2025
2 parents b43ae6a + 24aff7a commit 482492f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions apps/contributions/stripe_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,16 @@ def parse_slug_from_url(url: str) -> str | None:
"""Parse RP slug, if any, from a given URL."""
extracted = tldextract.extract(url)
parts = filter(None, [extracted.subdomain, extracted.domain])
if (query := f"{'.'.join(parts)}.{extracted.suffix}") not in (
allowed := [*settings.HOST_MAP.keys(), settings.DOMAIN_APEX]
if (
f"{extracted.domain}.{extracted.suffix}" != settings.DOMAIN_APEX
and (query := f"{'.'.join(parts)}.{extracted.suffix}") not in settings.HOST_MAP
):
logger.warning(
"URL %s has a host that is not allowed for import: (%s). Acceptable values are %s",
"URL %s is not allowed for import: (%s). Acceptable values are *.%s and %s for custom domains",
url,
query,
", ".join(allowed),
settings.DOMAIN_APEX,
", ".join(settings.HOST_MAP.keys()),
)
raise InvalidStripeTransactionDataError(f"URL {url} has a host that is not allowed for import")
parsed = urlparse(url)
Expand Down
8 changes: 8 additions & 0 deletions apps/contributions/tests/test_stripe_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ def _build_url(trailing_slash):

return _build_url

@pytest.fixture
def referer_url_with_subdomain_on_domain_apex(self, domain_apex, revenue_program):
def _build_url(trailing_slash):
return f"https://sub.{domain_apex}/{revenue_program.slug}{'/' if trailing_slash else ''}"

return _build_url

@pytest.fixture
def referer_url_with_custom_host(self, custom_host, revenue_program):
def _build_url(trailing_slash):
Expand Down Expand Up @@ -244,6 +251,7 @@ def _settings_rp_in_host_map(self, revenue_program, custom_host, settings):
("referer_url_with_no_slug", "_settings_empty_host_map", lambda rp: None, False),
("referer_url_with_slug_and_other_path", "_settings_empty_host_map", lambda rp: rp.slug, False),
("referer_url_with_slug_and_query_params", "_settings_empty_host_map", lambda rp: rp.slug, False),
("referer_url_with_subdomain_on_domain_apex", "_settings_empty_host_map", lambda rp: rp.slug, False),
],
)
@pytest.mark.parametrize("trailing_slash", [True, False])
Expand Down

0 comments on commit 482492f

Please sign in to comment.