mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
tests: fix permission tests
This commit is contained in:
parent
3765349436
commit
9809de65f8
2 changed files with 15 additions and 7 deletions
|
@ -1946,7 +1946,7 @@ def _set_app_settings(app, settings):
|
||||||
|
|
||||||
def _parse_app_version(v):
|
def _parse_app_version(v):
|
||||||
|
|
||||||
if v == "?":
|
if v in ["?", "-"]:
|
||||||
return (0, 0)
|
return (0, 0)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -355,7 +355,7 @@ def check_permission_for_apps():
|
||||||
|
|
||||||
def can_access_webpage(webpath, logged_as=None):
|
def can_access_webpage(webpath, logged_as=None):
|
||||||
webpath = webpath.rstrip("/")
|
webpath = webpath.rstrip("/")
|
||||||
sso_url = "https://" + maindomain + "/yunohost/portalapi/login"
|
login_endpoint = "https://" + maindomain + "/yunohost/portalapi/login"
|
||||||
|
|
||||||
# Anonymous access
|
# Anonymous access
|
||||||
if not logged_as:
|
if not logged_as:
|
||||||
|
@ -363,20 +363,28 @@ def can_access_webpage(webpath, logged_as=None):
|
||||||
# Login as a user using dummy password
|
# Login as a user using dummy password
|
||||||
else:
|
else:
|
||||||
with requests.Session() as session:
|
with requests.Session() as session:
|
||||||
session.post(
|
r = session.post(
|
||||||
sso_url,
|
login_endpoint,
|
||||||
data={"credentials": f"{logged_as}:{dummy_password}"},
|
data={"credentials": f"{logged_as}:{dummy_password}"},
|
||||||
headers={
|
headers={
|
||||||
"Referer": sso_url,
|
"X-Requested-With": "",
|
||||||
"Content-Type": "application/x-www-form-urlencoded",
|
|
||||||
},
|
},
|
||||||
verify=False,
|
verify=False,
|
||||||
)
|
)
|
||||||
# We should have some cookies related to authentication now
|
# We should have some cookies related to authentication now
|
||||||
assert session.cookies, session
|
assert session.cookies
|
||||||
r = session.get(webpath, verify=False)
|
r = session.get(webpath, verify=False)
|
||||||
|
|
||||||
# If we can't access it, we got redirected to the SSO
|
# If we can't access it, we got redirected to the SSO
|
||||||
|
# with `r=<base64_callback_url>` for anonymous access because they're encouraged to log-in,
|
||||||
|
# and `msg=access_denied` if we are logged but not allowed for this url
|
||||||
|
# with `r=
|
||||||
|
sso_url = "https://yolo.test/yunohost/sso/"
|
||||||
|
if not logged_as:
|
||||||
|
sso_url += "?r="
|
||||||
|
else:
|
||||||
|
sso_url += "?msg=access_denied"
|
||||||
|
|
||||||
return not r.url.startswith(sso_url)
|
return not r.url.startswith(sso_url)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue