Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
npalaska committed May 9, 2023
1 parent c63621a commit c13a82e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 33 deletions.
8 changes: 8 additions & 0 deletions lib/pbench/cli/server/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 9 additions & 13 deletions lib/pbench/server/api/resources/endpoint_configure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from configparser import NoOptionError, NoSectionError
from http import HTTPStatus
import re
from typing import Any, Dict
Expand Down Expand Up @@ -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)
Expand Down
31 changes: 11 additions & 20 deletions lib/pbench/test/unit/server/test_shell_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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",
Expand Down

0 comments on commit c13a82e

Please sign in to comment.