diff --git a/lib/pbench/cli/server/shell.py b/lib/pbench/cli/server/shell.py index 510e432d26..3de8427984 100644 --- a/lib/pbench/cli/server/shell.py +++ b/lib/pbench/cli/server/shell.py @@ -110,6 +110,14 @@ def run_gunicorn(server_config: PbenchServerConfig, logger: Logger) -> int: except OpenIDClient.NotConfigured as exc: logger.warning("OpenID Connect client not configured, {}", exc) notifier.notify("STOPPING=1") + notifier.notify("STATUS=OPENID broker not configured") + return 1 + except [ + OpenIDClient.ServerConnectionError, + OpenIDClient.ServerConnectionTimedOut, + ] as exc: + logger.warning("OpenID Connect client not reachable, {}", exc) + notifier.notify("STOPPING=1") notifier.notify("STATUS=OPENID broker not responding") return 1 else: diff --git a/lib/pbench/server/api/resources/endpoint_configure.py b/lib/pbench/server/api/resources/endpoint_configure.py index 39d0ec44fb..5238cfc7dd 100644 --- a/lib/pbench/server/api/resources/endpoint_configure.py +++ b/lib/pbench/server/api/resources/endpoint_configure.py @@ -1,4 +1,3 @@ -from configparser import NoOptionError, NoSectionError from http import HTTPStatus import re from typing import Any, Dict @@ -150,18 +149,15 @@ def get(self): "uri": templates, } - try: - client = self.server_config.get("openid", "client") - realm = self.server_config.get("openid", "realm") - server = self.server_config.get("openid", "server_url") - except (NoOptionError, NoSectionError): - pass - else: - endpoints["openid"] = { - "client": client, - "realm": realm, - "server": server, - } + client = self.server_config.get("openid", "client") + realm = self.server_config.get("openid", "realm") + server = self.server_config.get("openid", "server_url") + + endpoints["openid"] = { + "client": client, + "realm": realm, + "server": server, + } try: response = jsonify(endpoints) diff --git a/lib/pbench/test/unit/server/test_shell_cli.py b/lib/pbench/test/unit/server/test_shell_cli.py index 971bb70d72..dd67ccfe8d 100644 --- a/lib/pbench/test/unit/server/test_shell_cli.py +++ b/lib/pbench/test/unit/server/test_shell_cli.py @@ -207,8 +207,17 @@ def init_db(*args, **kwargs) -> int: assert ret_val == 1 @staticmethod + @pytest.mark.parametrize( + "exc", + [ + Exception("oidc exception"), + OpenIDClient.NotConfigured, + OpenIDClient.ServerConnectionTimedOut, + OpenIDClient.ServerConnectionError, + ], + ) def test_main_wait_for_oidc_server_exc( - monkeypatch, make_logger, mock_get_server_config + monkeypatch, make_logger, mock_get_server_config, exc ): def immediate_success(*args, **kwargs): pass @@ -219,7 +228,7 @@ def wait_for_oidc_server( server_config: PbenchServerConfig, logger: logging.Logger ) -> str: called[0] = True - raise Exception("oidc exception") + raise exc monkeypatch.setattr(shell.site, "ENABLE_USER_SITE", False) monkeypatch.setattr(shell, "wait_for_uri", immediate_success) @@ -232,24 +241,6 @@ def wait_for_oidc_server( assert called[0] assert ret_val == 1 - called = [False] - - # Test when specifically OpenIDClient.NotConfigured is raised from - # wait_for_oidc_server - def wait_for_oidc_server( - server_config: PbenchServerConfig, logger: logging.Logger - ) -> str: - called[0] = True - raise OpenIDClient.NotConfigured - - monkeypatch.setattr( - shell.OpenIDClient, "wait_for_oidc_server", wait_for_oidc_server - ) - ret_val = shell.main() - - assert called[0] - assert ret_val == 1 - @staticmethod @pytest.mark.parametrize( "wait_for_uri_exc",