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

Fixed Grist again as it uses non-/ base tag. #187

Merged
merged 4 commits into from
Nov 29, 2024
Merged
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
36 changes: 29 additions & 7 deletions lib/curl_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import tempfile
import pycurl
from bs4 import BeautifulSoup
from urllib.parse import urlencode, urlparse
from urllib.parse import urlencode, urljoin, urlparse
from io import BytesIO

DOMAIN = os.environ["DOMAIN"]
Expand Down Expand Up @@ -103,6 +103,26 @@ def curl(

return (return_code, return_content, effective_url)

def validate_and_normalize(effective_url, base, uri):
parsed_domain = urlparse(effective_url)

# sometimes assets point to //asset/somethig.css
# when parsed 'asset' becomes a domain, strip extra slashes
while uri.startswith("//"):
uri = uri[1:]

# now, first join base on top of effective_url
effective_url = urljoin(effective_url, base)
# then potentially relative URI
effective_url = urljoin(effective_url, uri)

# at this point effective_url should contain absolute path to linked content
parsed = urlparse(effective_url)
if parsed.netloc != parsed_domain.netloc:
# third-party hosting, not good for CI
return False, ""

return True, parsed.geturl()

def test(
base_url,
Expand Down Expand Up @@ -162,6 +182,8 @@ def test(
content = html.find("body")
content = content.get_text().strip() if content else ""
content = re.sub(r"[\t\n\s]{3,}", "\n\n", content)
base_tag = html.find("base")
base = base_tag.get("href", "") if base_tag else ""

errors = []
if expect_effective_url is None and "/yunohost/sso" in effective_url:
Expand Down Expand Up @@ -199,11 +221,11 @@ def test(
]
if stylesheets:
for sheet in stylesheets:
parsed = urlparse(sheet)
if parsed.netloc != "" and parsed.netloc != domain:
(valid, uri) = validate_and_normalize(effective_url, base, sheet)
if not valid:
continue
assets_to_check.append(
parsed._replace(netloc=domain)._replace(scheme="https").geturl()
uri
)
break

Expand All @@ -217,11 +239,11 @@ def test(
]
if js:
for js in js:
parsed = urlparse(js)
if parsed.netloc != "" and parsed.netloc != domain:
(valid, uri) = validate_and_normalize(effective_url, base, js)
if not valid:
continue
assets_to_check.append(
parsed._replace(netloc=domain)._replace(scheme="https").geturl()
uri
)
break

Expand Down