Skip to content

Commit

Permalink
curl_tests: Simplify curl() by only passing one argument, the full url
Browse files Browse the repository at this point in the history
  • Loading branch information
Salamandar committed Nov 4, 2024
1 parent f65e262 commit a31421a
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/curl_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,17 @@


def curl(
base_url,
path,
full_url,
method="GET",
use_cookies=None,
save_cookies=None,
post=None,
referer=None,
):
domain = base_url.replace("https://", "").replace("http://", "").split("/")[0]
domain = full_url.replace("https://", "").replace("http://", "").split("/")[0]

c = pycurl.Curl() # curl
c.setopt(c.URL, f"{base_url}{path}") # https://domain.tld/foo/bar
c.setopt(c.URL, full_url) # https://domain.tld/foo/bar
c.setopt(c.FOLLOWLOCATION, True) # --location
c.setopt(c.SSL_VERIFYPEER, False) # --insecure
c.setopt(
Expand Down Expand Up @@ -122,8 +121,7 @@ def test(

if DIST == "bullseye":
code, content, log_url = curl(
f"https://{DOMAIN}/yunohost/sso",
"/",
f"https://{DOMAIN}/yunohost/sso/",
save_cookies=cookies,
post={"user": USER, "password": PASSWORD},
referer=f"https://{DOMAIN}/yunohost/sso/",
Expand All @@ -133,8 +131,7 @@ def test(
), f"Failed to log in: got code {code} or cookie file was empty?"
else:
code, content, _ = curl(
f"https://{domain}/yunohost/portalapi",
"/login",
f"https://{domain}/yunohost/portalapi/login",
save_cookies=cookies,
post={"credentials": f"{USER}:{PASSWORD}"},
)
Expand All @@ -149,7 +146,7 @@ def test(
while code is None or code in {502, 503, 504}:
time.sleep(retried * 5)
code, content, effective_url = curl(
base_url, path, post=post, use_cookies=cookies
base_url + path, post=post, use_cookies=cookies
)
retried += 1
if retried > 3:
Expand Down Expand Up @@ -234,7 +231,7 @@ def test(
if not asset.startswith("/"):
asset = "/" + asset
asset_code, _, effective_asset_url = curl(
f"https://{domain}", asset, use_cookies=cookies
f"https://{domain}{asset}", use_cookies=cookies
)
if asset_code != 200:
errors.append(
Expand Down

0 comments on commit a31421a

Please sign in to comment.