From 326456cb78eb6b50e6f44f01cb0eaccc7652cf1f Mon Sep 17 00:00:00 2001 From: Pieter Ennes Date: Thu, 20 Sep 2018 23:10:17 +0100 Subject: Fix OIDC tests (#565) * Unmute ignored OIDC tests. * Fix more import errors. * Remove recently invalidated test for id_token_hint. * Fix tested grants. * Fix import on py27. --- oauthlib/openid/connect/core/endpoints/__init__.py | 0 .../connect/core/endpoints/pre_configured.py | 30 ++++++++++++---------- .../openid/connect/core/grant_types/__init__.py | 6 ++--- .../oauth1/rfc5849/endpoints/test_authorization.py | 2 +- tests/openid/connect/core/endpoints/__init__.py | 0 .../connect/core/endpoints/test_claims_handling.py | 7 +++-- .../test_openid_connect_params_handling.py | 8 +++--- tests/openid/connect/core/grant_types/__init__.py | 0 .../core/grant_types/test_authorization_code.py | 10 +++----- .../connect/core/grant_types/test_dispatchers.py | 8 +++--- .../openid/connect/core/grant_types/test_hybrid.py | 3 ++- .../connect/core/grant_types/test_implicit.py | 18 +++---------- .../openid/connect/core/test_request_validator.py | 2 +- tests/openid/connect/core/test_server.py | 2 +- tests/openid/connect/core/test_tokens.py | 2 +- 15 files changed, 42 insertions(+), 56 deletions(-) create mode 100644 oauthlib/openid/connect/core/endpoints/__init__.py create mode 100644 tests/openid/connect/core/endpoints/__init__.py create mode 100644 tests/openid/connect/core/grant_types/__init__.py diff --git a/oauthlib/openid/connect/core/endpoints/__init__.py b/oauthlib/openid/connect/core/endpoints/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/oauthlib/openid/connect/core/endpoints/pre_configured.py b/oauthlib/openid/connect/core/endpoints/pre_configured.py index 3bcd24d..04bd628 100644 --- a/oauthlib/openid/connect/core/endpoints/pre_configured.py +++ b/oauthlib/openid/connect/core/endpoints/pre_configured.py @@ -8,29 +8,31 @@ for providing OpenID Connect servers. """ from __future__ import absolute_import, unicode_literals -from ..grant_types import ( +from oauthlib.oauth2.rfc6749.endpoints import ( + AuthorizationEndpoint, + ResourceEndpoint, + RevocationEndpoint, + TokenEndpoint +) +from oauthlib.oauth2.rfc6749.grant_types import ( AuthorizationCodeGrant as OAuth2AuthorizationCodeGrant, - ClientCredentialsGrant, ImplicitGrant as OAuth2ImplicitGrant, + ClientCredentialsGrant, RefreshTokenGrant, ResourceOwnerPasswordCredentialsGrant ) - -from oauthlib.openid.connect.core.grant_types.authorization_code import AuthorizationCodeGrant -from oauthlib.openid.connect.core.grant_types.dispatchers import ( +from oauthlib.oauth2.rfc6749.tokens import BearerToken +from ..grant_types import ( + AuthorizationCodeGrant, + ImplicitGrant, + HybridGrant, +) +from ..grant_types.dispatchers import ( AuthorizationCodeGrantDispatcher, ImplicitTokenGrantDispatcher, AuthorizationTokenGrantDispatcher ) -from oauthlib.openid.connect.core.grant_types.implicit import ImplicitGrant -from oauthlib.openid.connect.core.grant_types.hybrid import HybridGrant -from oauthlib.openid.connect.core.tokens import JWTToken - -from ..tokens import BearerToken -from .authorization import AuthorizationEndpoint -from .resource import ResourceEndpoint -from .revocation import RevocationEndpoint -from .token import TokenEndpoint +from ..tokens import JWTToken class Server(AuthorizationEndpoint, TokenEndpoint, ResourceEndpoint, diff --git a/oauthlib/openid/connect/core/grant_types/__init__.py b/oauthlib/openid/connect/core/grant_types/__init__.py index 7fc183d..63f30ac 100644 --- a/oauthlib/openid/connect/core/grant_types/__init__.py +++ b/oauthlib/openid/connect/core/grant_types/__init__.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -oauthlib.oauth2.rfc6749.grant_types -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +oauthlib.openid.connect.core.grant_types +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ from __future__ import unicode_literals, absolute_import @@ -10,7 +10,7 @@ from .implicit import ImplicitGrant from .base import GrantTypeBase from .hybrid import HybridGrant from .exceptions import OIDCNoPrompt -from oauthlib.openid.connect.core.grant_types.dispatchers import ( +from .dispatchers import ( AuthorizationCodeGrantDispatcher, ImplicitTokenGrantDispatcher, AuthorizationTokenGrantDispatcher diff --git a/tests/oauth1/rfc5849/endpoints/test_authorization.py b/tests/oauth1/rfc5849/endpoints/test_authorization.py index 022e8e9..e9d3604 100644 --- a/tests/oauth1/rfc5849/endpoints/test_authorization.py +++ b/tests/oauth1/rfc5849/endpoints/test_authorization.py @@ -6,7 +6,7 @@ from oauthlib.oauth1 import RequestValidator from oauthlib.oauth1.rfc5849 import errors from oauthlib.oauth1.rfc5849.endpoints import AuthorizationEndpoint -from ....unittest import TestCase +from tests.unittest import TestCase class AuthorizationEndpointTest(TestCase): diff --git a/tests/openid/connect/core/endpoints/__init__.py b/tests/openid/connect/core/endpoints/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/openid/connect/core/endpoints/test_claims_handling.py b/tests/openid/connect/core/endpoints/test_claims_handling.py index 37a7cdd..d5908a8 100644 --- a/tests/openid/connect/core/endpoints/test_claims_handling.py +++ b/tests/openid/connect/core/endpoints/test_claims_handling.py @@ -11,11 +11,10 @@ from __future__ import absolute_import, unicode_literals import mock from oauthlib.oauth2 import RequestValidator +from oauthlib.openid.connect.core.endpoints.pre_configured import Server -from oauthlib.oauth2.rfc6749.endpoints.pre_configured import Server - -from ....unittest import TestCase -from .test_utils import get_query_credentials +from tests.unittest import TestCase +from tests.oauth2.rfc6749.endpoints.test_utils import get_query_credentials class TestClaimsHandling(TestCase): diff --git a/tests/openid/connect/core/endpoints/test_openid_connect_params_handling.py b/tests/openid/connect/core/endpoints/test_openid_connect_params_handling.py index 89431b6..517239a 100644 --- a/tests/openid/connect/core/endpoints/test_openid_connect_params_handling.py +++ b/tests/openid/connect/core/endpoints/test_openid_connect_params_handling.py @@ -5,10 +5,10 @@ import mock from oauthlib.oauth2 import InvalidRequestError from oauthlib.oauth2.rfc6749.endpoints.authorization import \ AuthorizationEndpoint -from oauthlib.oauth2.rfc6749.grant_types import OpenIDConnectAuthCode from oauthlib.oauth2.rfc6749.tokens import BearerToken +from oauthlib.openid.connect.core.grant_types import AuthorizationCodeGrant -from ....unittest import TestCase +from tests.unittest import TestCase try: from urllib.parse import urlencode @@ -16,14 +16,12 @@ except ImportError: from urllib import urlencode - - class OpenIDConnectEndpointTest(TestCase): def setUp(self): self.mock_validator = mock.MagicMock() self.mock_validator.authenticate_client.side_effect = self.set_client - grant = OpenIDConnectAuthCode(request_validator=self.mock_validator) + grant = AuthorizationCodeGrant(request_validator=self.mock_validator) bearer = BearerToken(self.mock_validator) self.endpoint = AuthorizationEndpoint(grant, bearer, response_types={'code': grant}) diff --git a/tests/openid/connect/core/grant_types/__init__.py b/tests/openid/connect/core/grant_types/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/openid/connect/core/grant_types/test_authorization_code.py b/tests/openid/connect/core/grant_types/test_authorization_code.py index 1bad120..9bbe7fb 100644 --- a/tests/openid/connect/core/grant_types/test_authorization_code.py +++ b/tests/openid/connect/core/grant_types/test_authorization_code.py @@ -11,8 +11,9 @@ from oauthlib.oauth2.rfc6749.tokens import BearerToken from oauthlib.openid.connect.core.grant_types.authorization_code import AuthorizationCodeGrant from oauthlib.openid.connect.core.grant_types.exceptions import OIDCNoPrompt -from ....unittest import TestCase -from ....oauth2.rfc6749.grant_types.test_authorization_code import AuthorizationCodeGrantTest +from tests.unittest import TestCase +from tests.oauth2.rfc6749.grant_types.test_authorization_code import \ + AuthorizationCodeGrantTest def get_id_token_mock(token, token_handler, request): @@ -81,12 +82,7 @@ class OpenIDAuthCodeTest(TestCase): self.auth.validate_authorization_request, self.request) - # prompt == none requires id token hint bearer = BearerToken(self.mock_validator) - h, b, s = self.auth.create_authorization_response(self.request, bearer) - self.assertIn('error=invalid_request', h['Location']) - self.assertEqual(b, None) - self.assertEqual(s, 302) self.request.response_mode = 'query' self.request.id_token_hint = 'me@email.com' diff --git a/tests/openid/connect/core/grant_types/test_dispatchers.py b/tests/openid/connect/core/grant_types/test_dispatchers.py index 84f2688..e7dce45 100644 --- a/tests/openid/connect/core/grant_types/test_dispatchers.py +++ b/tests/openid/connect/core/grant_types/test_dispatchers.py @@ -17,7 +17,7 @@ from oauthlib.oauth2.rfc6749.grant_types import ( ) -from ....unittest import TestCase +from tests.unittest import TestCase class ImplicitTokenGrantDispatcherTest(TestCase): @@ -47,12 +47,12 @@ class ImplicitTokenGrantDispatcherTest(TestCase): def test_create_authorization_response_oauth(self): self.request.scopes = ('hello', 'world') handler = self.dispatcher._handler_for_request(self.request) - self.assertIsInstance(handler, ImplicitGrant) + self.assertIsInstance(handler, OAuth2ImplicitGrant) def test_validate_authorization_request_oauth(self): self.request.scopes = ('hello', 'world') handler = self.dispatcher._handler_for_request(self.request) - self.assertIsInstance(handler, ImplicitGrant) + self.assertIsInstance(handler, OAuth2ImplicitGrant) class DispatcherTest(TestCase): @@ -66,7 +66,7 @@ class DispatcherTest(TestCase): self.request_validator = mock.MagicMock() self.auth_grant = OAuth2AuthorizationCodeGrant(self.request_validator) - self.openid_connect_auth = OAuth2AuthorizationCodeGrant(self.request_validator) + self.openid_connect_auth = AuthorizationCodeGrant(self.request_validator) class AuthTokenGrantDispatcherOpenIdTest(DispatcherTest): diff --git a/tests/openid/connect/core/grant_types/test_hybrid.py b/tests/openid/connect/core/grant_types/test_hybrid.py index 531ae7f..6eb8037 100644 --- a/tests/openid/connect/core/grant_types/test_hybrid.py +++ b/tests/openid/connect/core/grant_types/test_hybrid.py @@ -2,7 +2,8 @@ from __future__ import absolute_import, unicode_literals from oauthlib.openid.connect.core.grant_types.hybrid import HybridGrant -from ....oauth2.rfc6749.grant_types.test_authorization_code import AuthorizationCodeGrantTest +from tests.oauth2.rfc6749.grant_types.test_authorization_code import \ + AuthorizationCodeGrantTest class OpenIDHybridInterferenceTest(AuthorizationCodeGrantTest): diff --git a/tests/openid/connect/core/grant_types/test_implicit.py b/tests/openid/connect/core/grant_types/test_implicit.py index 56247d9..c369bb6 100644 --- a/tests/openid/connect/core/grant_types/test_implicit.py +++ b/tests/openid/connect/core/grant_types/test_implicit.py @@ -4,18 +4,14 @@ from __future__ import absolute_import, unicode_literals import mock from oauthlib.common import Request - from oauthlib.oauth2.rfc6749.tokens import BearerToken - -from oauthlib.openid.connect.core.grant_types.implicit import ImplicitGrant -from oauthlib.openid.connect.core.grant_types.hybrid import HybridGrant from oauthlib.openid.connect.core.grant_types.exceptions import OIDCNoPrompt - -from ....unittest import TestCase +from oauthlib.openid.connect.core.grant_types.hybrid import HybridGrant +from oauthlib.openid.connect.core.grant_types.implicit import ImplicitGrant +from tests.oauth2.rfc6749.grant_types.test_implicit import ImplicitGrantTest +from tests.unittest import TestCase from .test_authorization_code import get_id_token_mock, OpenIDAuthCodeTest -from ....oauth2.rfc6749.grant_types.test_implicit import ImplicitGrantTest - class OpenIDImplicitInterferenceTest(ImplicitGrantTest): """Test that OpenID don't interfere with normal OAuth 2 flows.""" @@ -80,13 +76,7 @@ class OpenIDImplicitTest(TestCase): self.auth.validate_authorization_request, self.request) - # prompt == none requires id token hint bearer = BearerToken(self.mock_validator) - h, b, s = self.auth.create_authorization_response(self.request, bearer) - self.assertIn('error=invalid_request', h['Location']) - self.assertEqual(b, None) - self.assertEqual(s, 302) - self.request.id_token_hint = 'me@email.com' h, b, s = self.auth.create_authorization_response(self.request, bearer) self.assertURLEqual(h['Location'], self.url_fragment, parse_fragment=True) diff --git a/tests/openid/connect/core/test_request_validator.py b/tests/openid/connect/core/test_request_validator.py index 14a7c23..1e71fb1 100644 --- a/tests/openid/connect/core/test_request_validator.py +++ b/tests/openid/connect/core/test_request_validator.py @@ -3,7 +3,7 @@ from __future__ import absolute_import, unicode_literals from oauthlib.openid.connect.core.request_validator import RequestValidator -from ....unittest import TestCase +from tests.unittest import TestCase class RequestValidatorTest(TestCase): diff --git a/tests/openid/connect/core/test_server.py b/tests/openid/connect/core/test_server.py index 83290db..a83f22d 100644 --- a/tests/openid/connect/core/test_server.py +++ b/tests/openid/connect/core/test_server.py @@ -14,7 +14,7 @@ from oauthlib.openid.connect.core.grant_types.authorization_code import Authoriz from oauthlib.openid.connect.core.grant_types.implicit import ImplicitGrant from oauthlib.openid.connect.core.grant_types.hybrid import HybridGrant -from ....unittest import TestCase +from tests.unittest import TestCase class AuthorizationEndpointTest(TestCase): diff --git a/tests/openid/connect/core/test_tokens.py b/tests/openid/connect/core/test_tokens.py index 12c75f1..1fcfb51 100644 --- a/tests/openid/connect/core/test_tokens.py +++ b/tests/openid/connect/core/test_tokens.py @@ -4,7 +4,7 @@ import mock from oauthlib.openid.connect.core.tokens import JWTToken -from ....unittest import TestCase +from tests.unittest import TestCase class JWTTokenTestCase(TestCase): -- cgit v1.2.1