diff --git a/swh/web/templates/layout.html b/swh/web/templates/layout.html index fe27f07c..47676ddc 100644 --- a/swh/web/templates/layout.html +++ b/swh/web/templates/layout.html @@ -1,269 +1,275 @@ {% comment %} Copyright (C) 2015-2020 The Software Heritage developers See the AUTHORS file at the top-level directory of this distribution License: GNU Affero General Public License version 3, or any later version See top-level LICENSE file for more information {% endcomment %} {% load js_reverse %} {% load static %} {% load render_bundle from webpack_loader %} {% load swh_templatetags %} {% block title %}{% endblock %} {% render_bundle 'vendors' %} {% render_bundle 'webapp' %} {% block header %}{% endblock %} {% if "production" in DJANGO_SETTINGS_MODULE %} {% endif %}
{% if swh_web_staging %}
Staging
{% endif %} {% block content %}{% endblock %}
{% include "includes/global-modals.html" %}
back to top
diff --git a/swh/web/tests/test_templates.py b/swh/web/tests/test_templates.py index 3e2f677d..bd92e5f4 100644 --- a/swh/web/tests/test_templates.py +++ b/swh/web/tests/test_templates.py @@ -1,25 +1,42 @@ # Copyright (C) 2021 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information import random from swh.web.common.utils import reverse -from swh.web.config import STAGING_SERVER_NAMES +from swh.web.config import STAGING_SERVER_NAMES, get_config from swh.web.tests.django_asserts import assert_contains, assert_not_contains from swh.web.tests.utils import check_http_get_response def test_layout_without_staging_ribbon(client): url = reverse("swh-web-homepage") resp = check_http_get_response(client, url, status_code=200) assert_not_contains(resp, "swh-corner-ribbon") def test_layout_with_staging_ribbon(client): url = reverse("swh-web-homepage") resp = check_http_get_response( client, url, status_code=200, server_name=random.choice(STAGING_SERVER_NAMES), ) assert_contains(resp, "swh-corner-ribbon") + + +def test_layout_with_oidc_auth_enabled(client): + url = reverse("swh-web-homepage") + resp = check_http_get_response(client, url, status_code=200) + assert_contains(resp, reverse("oidc-login")) + + +def test_layout_without_oidc_auth_enabled(client, mocker): + config = get_config() + config["keycloak"]["server_url"] = "" + mock_get_config = mocker.patch("swh.web.common.utils.get_config") + mock_get_config.return_value = config + + url = reverse("swh-web-homepage") + resp = check_http_get_response(client, url, status_code=200) + assert_contains(resp, reverse("login"))