Requesting the root page “/” as anonymous will redirect to login /yunohost/sso/?next=/
So the user is authenticated via SSO and can access the root page.
Before this Pull request it was a intermediate page rendered by django.
I tested the new changes manually on my YunoHost installation and it works fine.
I would like to test that anonymous users will be redirect to SSO portal for login. But this can’t be tested, because this doesn’t work:
# Access the root page not logged in results in redirect to portal to login
home.path = "/"
home.logged_on_sso = false
home.expect_effective_url = "https://__DOMAIN__/yunohost/sso/?next=/"
# Access the Django Admin not logged in results in redirect to portal to login
admin.path = "/admin/"
admin.logged_on_sso = false
admin.expect_effective_url = "https://__DOMAIN__/yunohost/sso/?next=/admin/"
expect_effective_url can’t have placeholders, isn’t it?
It’s also not possible to just test the expect_return_code, because empty expect_effective_url will also not work.
if expect_effective_url is None and "/yunohost/sso" in effective_url:
errors.append(
f"The request was redirected to yunohost's portal ({effective_url})"
)
if expect_effective_url and expect_effective_url != effective_url:
errors.append(
f"Ended up on URL '{effective_url}', but was expecting '{expect_effective_url}'"
)
Replacement of __DOMAIN__ is helpfull but it’s sadly not possible to test the “need login” redirections via tests.toml if the App can be installed at root domain and in a directory.
But the “return to app” values like /yunohost/sso/?r=aHR0cHM6Ly90ZXN0c2VydmVyL2FwcF9wYXRoL2xvZ2luLXJlcXVpcmVkLw%3D%3D depends on install location. So they can’t hardcoded into tests.toml
What about a complete different solution for these kind of tests?
In tests.toml it’s only needed to define the URL of the App, that will redirect to SSO login.
The “package_check / curl_tests” will do the complete login flow with correct redirects and it only pass the test if we are redirected back to the app. In this case tests like “expect_title” and “expect_content” are then also possible.