Fix missed tests and revert conftest change (breaks docker build)

This commit is contained in:
Joseph Schorr 2017-01-30 17:28:25 -05:00
parent cf6033b423
commit f5dbc350f8
5 changed files with 20 additions and 19 deletions

View file

@ -20,3 +20,4 @@ coverage
.cache .cache
.npm-debug.log .npm-debug.log
test/__pycache__ test/__pycache__
__pycache__

View file

@ -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

View file

@ -6,6 +6,7 @@ import urlparse
import jwt import jwt
import pytest import pytest
import requests
from httmock import urlmatch, HTTMock from httmock import urlmatch, HTTMock
from Crypto.PublicKey import RSA from Crypto.PublicKey import RSA
@ -13,6 +14,15 @@ from jwkest.jwk import RSAKey
from oauth.oidc import OIDCLoginService, OAuthLoginException 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]) @pytest.fixture(params=[True, False])
def app_config(http_client, request): def app_config(http_client, request):
return { return {

View file

@ -1,6 +1,6 @@
import unittest import unittest
from util.config.oauth import GithubOAuthConfig from oauth.services.github import GithubOAuthService
class TestGithub(unittest.TestCase): class TestGithub(unittest.TestCase):
def test_basic_enterprise_config(self): 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.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/authorize?', github_trigger.authorize_endpoint())
self.assertEquals('https://github.somedomain.com/login/oauth/access_token', github_trigger.token_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.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/authorize?', github_trigger.authorize_endpoint())
self.assertEquals('https://github.somedomain.com/login/oauth/access_token', github_trigger.token_endpoint()) self.assertEquals('https://github.somedomain.com/login/oauth/access_token', github_trigger.token_endpoint())

View file

@ -22,7 +22,9 @@ from data.users.externaljwt import ExternalJWTAuthN
from data.users.externalldap import LDAPConnection, LDAPUsers from data.users.externalldap import LDAPConnection, LDAPUsers
from data.users.keystone import get_keystone_users from data.users.keystone import get_keystone_users
from storage import get_storage_driver 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.secscan.api import SecurityScannerAPI
from util.registry.torrent import torrent_jwt from util.registry.torrent import torrent_jwt
from util.security.signing import SIGNING_ENGINES from util.security.signing import SIGNING_ENGINES
@ -159,7 +161,7 @@ def _validate_gitlab(config, user_obj, _):
raise ConfigValidationException('Missing Client Secret') raise ConfigValidationException('Missing Client Secret')
client = app.config['HTTPCLIENT'] 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) result = oauth.validate_client_id_and_secret(client, app.config)
if not result: if not result:
raise ConfigValidationException('Invalid client id or client secret') raise ConfigValidationException('Invalid client id or client secret')
@ -193,7 +195,7 @@ def _validate_github_with_key(config_key, config):
'organization') 'organization')
client = app.config['HTTPCLIENT'] client = app.config['HTTPCLIENT']
oauth = GithubOAuthConfig(config, config_key) oauth = GithubOAuthService(config, config_key)
result = oauth.validate_client_id_and_secret(client, app.config) result = oauth.validate_client_id_and_secret(client, app.config)
if not result: if not result:
raise ConfigValidationException('Invalid client id or client secret') raise ConfigValidationException('Invalid client id or client secret')
@ -239,7 +241,7 @@ def _validate_google_login(config, user_obj, _):
raise ConfigValidationException('Missing Client Secret') raise ConfigValidationException('Missing Client Secret')
client = app.config['HTTPCLIENT'] 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) result = oauth.validate_client_id_and_secret(client, app.config)
if not result: if not result:
raise ConfigValidationException('Invalid client id or client secret') raise ConfigValidationException('Invalid client id or client secret')