Skip to content

Commit

Permalink
Fix OIDC tests (#565)
Browse files Browse the repository at this point in the history
* Unmute ignored OIDC tests.

* Fix more import errors.

* Remove recently invalidated test for id_token_hint.

* Fix tested grants.

* Fix import on py27.
  • Loading branch information
skion authored and thedrow committed Sep 20, 2018
1 parent 7fb3bd4 commit 326456c
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 56 deletions.
Empty file.
30 changes: 16 additions & 14 deletions oauthlib/openid/connect/core/endpoints/pre_configured.py
Expand Up @@ -8,29 +8,31 @@
"""
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,
Expand Down
6 changes: 3 additions & 3 deletions 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

Expand All @@ -10,7 +10,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion tests/oauth1/rfc5849/endpoints/test_authorization.py
Expand Up @@ -6,7 +6,7 @@
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):
Expand Down
Empty file.
7 changes: 3 additions & 4 deletions tests/openid/connect/core/endpoints/test_claims_handling.py
Expand Up @@ -11,11 +11,10 @@
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):
Expand Down
Expand Up @@ -5,25 +5,23 @@
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
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})
Expand Down
Empty file.
10 changes: 3 additions & 7 deletions tests/openid/connect/core/grant_types/test_authorization_code.py
Expand Up @@ -11,8 +11,9 @@
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):
Expand Down Expand Up @@ -81,12 +82,7 @@ def test_no_prompt_authorization(self, generate_token):
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'
Expand Down
8 changes: 4 additions & 4 deletions tests/openid/connect/core/grant_types/test_dispatchers.py
Expand Up @@ -17,7 +17,7 @@
)


from ....unittest import TestCase
from tests.unittest import TestCase


class ImplicitTokenGrantDispatcherTest(TestCase):
Expand Down Expand Up @@ -47,12 +47,12 @@ def test_validate_authorization_request_openid(self):
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):
Expand All @@ -66,7 +66,7 @@ def setUp(self):

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):
Expand Down
3 changes: 2 additions & 1 deletion tests/openid/connect/core/grant_types/test_hybrid.py
Expand Up @@ -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):
Expand Down
18 changes: 4 additions & 14 deletions tests/openid/connect/core/grant_types/test_implicit.py
Expand Up @@ -4,18 +4,14 @@
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."""
Expand Down Expand Up @@ -80,13 +76,7 @@ def test_no_prompt_authorization(self, generate_token):
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)
Expand Down
2 changes: 1 addition & 1 deletion tests/openid/connect/core/test_request_validator.py
Expand Up @@ -3,7 +3,7 @@

from oauthlib.openid.connect.core.request_validator import RequestValidator

from ....unittest import TestCase
from tests.unittest import TestCase


class RequestValidatorTest(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/openid/connect/core/test_server.py
Expand Up @@ -14,7 +14,7 @@
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):
Expand Down
2 changes: 1 addition & 1 deletion tests/openid/connect/core/test_tokens.py
Expand Up @@ -4,7 +4,7 @@

from oauthlib.openid.connect.core.tokens import JWTToken

from ....unittest import TestCase
from tests.unittest import TestCase


class JWTTokenTestCase(TestCase):
Expand Down

0 comments on commit 326456c

Please sign in to comment.