Skip to content

Commit

Permalink
sso: Add test for RHSSO OAuth service (PROJQUAY-2056)
Browse files Browse the repository at this point in the history
- Add test for RHSSOOAuthService class
  • Loading branch information
jonathankingfc committed May 11, 2022
1 parent 587cceb commit acddb61
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions oauth/loginmanager.py
Expand Up @@ -28,10 +28,10 @@ def __init__(self, config, client=None):
if custom_service.login_enabled(config):
self.services.append(custom_service)
else:
prefix = key.rstrip("_LOGIN_CONFIG").lower()
prefix = key[: -len("_LOGIN_CONFIG")].lower()
if prefix in PREFIX_BLACKLIST:
raise Exception("Cannot use reserved config name %s" % key)
if prefix == "rhsso":
if prefix == "rhss":
self.services.append(RHSSOOAuthService(config, key, client=client))
else:
self.services.append(OIDCLoginService(config, key, client=client))
Expand Down
4 changes: 3 additions & 1 deletion oauth/services/rhsso.py
Expand Up @@ -32,7 +32,9 @@ def exchange_code_for_login(self, app_config, http_client, code, redirect_suffix
)
logger.debug("Got result from export compliance service: " + result.json())
if result.status_code != 200:
raise OAuthLoginException(str(result.json()["errors"]))
raise OAuthLoginException(str(result.json()))
if result.json()["result"] != "OK":
raise OAuthLoginException(str(result.json()["description"]))
except Exception as e:
raise OAuthLoginException(str(e))

Expand Down
9 changes: 9 additions & 0 deletions oauth/test/test_loginmanager.py
Expand Up @@ -2,6 +2,7 @@
from oauth.services.github import GithubOAuthService
from oauth.services.google import GoogleOAuthService
from oauth.oidc import OIDCLoginService
from oauth.services.rhsso import RHSSOOAuthService


def test_login_manager_github():
Expand Down Expand Up @@ -66,3 +67,11 @@ def test_multiple_oidc():
assert len(loginmanager.services) == 2
assert isinstance(loginmanager.services[0], OIDCLoginService)
assert isinstance(loginmanager.services[1], OIDCLoginService)


def test_rhsso():
config = {"RHSSO_LOGIN_CONFIG": {}}

loginmanager = OAuthLoginManager(config)
assert len(loginmanager.services) == 1
assert isinstance(loginmanager.services[0], RHSSOOAuthService)

0 comments on commit acddb61

Please sign in to comment.