diff --git a/.dockerignore b/.dockerignore index 0a5878cef..ce563e77b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -20,3 +20,4 @@ coverage .cache .npm-debug.log test/__pycache__ +__pycache__ diff --git a/conftest.py b/conftest.py deleted file mode 100644 index b2488d926..000000000 --- a/conftest.py +++ /dev/null @@ -1,12 +0,0 @@ -import pytest - -import requests - -@pytest.fixture() -def http_client(): - sess = requests.Session() - adapter = requests.adapters.HTTPAdapter(pool_connections=100, - pool_maxsize=100) - sess.mount('http://', adapter) - sess.mount('https://', adapter) - return sess diff --git a/oauth/test/test_oidc.py b/oauth/test/test_oidc.py index 4f15bfe0d..e8bdd0c0e 100644 --- a/oauth/test/test_oidc.py +++ b/oauth/test/test_oidc.py @@ -6,6 +6,7 @@ import urlparse import jwt import pytest +import requests from httmock import urlmatch, HTTMock from Crypto.PublicKey import RSA @@ -13,6 +14,15 @@ from jwkest.jwk import RSAKey from oauth.oidc import OIDCLoginService, OAuthLoginException +@pytest.fixture() +def http_client(): + sess = requests.Session() + adapter = requests.adapters.HTTPAdapter(pool_connections=100, + pool_maxsize=100) + sess.mount('http://', adapter) + sess.mount('https://', adapter) + return sess + @pytest.fixture(params=[True, False]) def app_config(http_client, request): return { diff --git a/test/test_github.py b/test/test_github.py index 4b2fc5d2c..1296af155 100644 --- a/test/test_github.py +++ b/test/test_github.py @@ -1,6 +1,6 @@ import unittest -from util.config.oauth import GithubOAuthConfig +from oauth.services.github import GithubOAuthService class TestGithub(unittest.TestCase): def test_basic_enterprise_config(self): @@ -12,7 +12,7 @@ class TestGithub(unittest.TestCase): } } - github_trigger = GithubOAuthConfig(config, 'GITHUB_TRIGGER_CONFIG') + github_trigger = GithubOAuthService(config, 'GITHUB_TRIGGER_CONFIG') self.assertTrue(github_trigger.is_enterprise()) self.assertEquals('https://github.somedomain.com/login/oauth/authorize?', github_trigger.authorize_endpoint()) self.assertEquals('https://github.somedomain.com/login/oauth/access_token', github_trigger.token_endpoint()) @@ -33,7 +33,7 @@ class TestGithub(unittest.TestCase): } } - github_trigger = GithubOAuthConfig(config, 'GITHUB_TRIGGER_CONFIG') + github_trigger = GithubOAuthService(config, 'GITHUB_TRIGGER_CONFIG') self.assertTrue(github_trigger.is_enterprise()) self.assertEquals('https://github.somedomain.com/login/oauth/authorize?', github_trigger.authorize_endpoint()) self.assertEquals('https://github.somedomain.com/login/oauth/access_token', github_trigger.token_endpoint()) diff --git a/util/config/validator.py b/util/config/validator.py index 9ff7ea973..3c31ca056 100644 --- a/util/config/validator.py +++ b/util/config/validator.py @@ -22,7 +22,9 @@ from data.users.externaljwt import ExternalJWTAuthN from data.users.externalldap import LDAPConnection, LDAPUsers from data.users.keystone import get_keystone_users from storage import get_storage_driver -from util.config.oauth import GoogleOAuthConfig, GithubOAuthConfig, GitLabOAuthConfig +from oauth.services.github import GithubOAuthService +from oauth.services.google import GoogleOAuthService +from oauth.services.gitlab import GitLabOAuthService from util.secscan.api import SecurityScannerAPI from util.registry.torrent import torrent_jwt from util.security.signing import SIGNING_ENGINES @@ -159,7 +161,7 @@ def _validate_gitlab(config, user_obj, _): raise ConfigValidationException('Missing Client Secret') client = app.config['HTTPCLIENT'] - oauth = GitLabOAuthConfig(config, 'GITLAB_TRIGGER_CONFIG') + oauth = GitLabOAuthService(config, 'GITLAB_TRIGGER_CONFIG') result = oauth.validate_client_id_and_secret(client, app.config) if not result: raise ConfigValidationException('Invalid client id or client secret') @@ -193,7 +195,7 @@ def _validate_github_with_key(config_key, config): 'organization') client = app.config['HTTPCLIENT'] - oauth = GithubOAuthConfig(config, config_key) + oauth = GithubOAuthService(config, config_key) result = oauth.validate_client_id_and_secret(client, app.config) if not result: raise ConfigValidationException('Invalid client id or client secret') @@ -239,7 +241,7 @@ def _validate_google_login(config, user_obj, _): raise ConfigValidationException('Missing Client Secret') client = app.config['HTTPCLIENT'] - oauth = GoogleOAuthConfig(config, 'GOOGLE_LOGIN_CONFIG') + oauth = GoogleOAuthService(config, 'GOOGLE_LOGIN_CONFIG') result = oauth.validate_client_id_and_secret(client, app.config) if not result: raise ConfigValidationException('Invalid client id or client secret')