Skip to content

Commit

Permalink
Merge pull request #461 from diego-plan9/feature/pyjwt-2-tests
Browse files Browse the repository at this point in the history
Support pyjwt >= 2 in tests
  • Loading branch information
minrk committed Nov 30, 2021
2 parents f2e0627 + 2a3cdbf commit beb31a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion oauthenticator/tests/test_azuread.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest

from ..azuread import AzureAdOAuthenticator
from ..azuread import PYJWT_2
from .mocks import setup_oauth_mock


Expand Down Expand Up @@ -40,7 +41,9 @@ def user_model(tenant_id, client_id, name):
"aio": "Df2UVXL1ix!lMCWMSOJBcFatzcGfvFGhjKv8q5g0x732dR5MB5BisvGQO7YWByjd8iQDLq!eGbIDakyp5mnOrcdqHeYSnltepQmRp6AIZ8jY",
},
os.urandom(5),
).decode("ascii")
)
if not PYJWT_2:
id_token = id_token.decode("ascii")

return {
"access_token": "abc123",
Expand Down
7 changes: 6 additions & 1 deletion oauthenticator/tests/test_mediawiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pytest import fixture
from tornado import web

from ..azuread import PYJWT_2
from ..mediawiki import AUTH_REQUEST_COOKIE_NAME
from ..mediawiki import MWOAuthenticator
from .mocks import mock_handler
Expand All @@ -20,7 +21,7 @@ def mediawiki():
def post_token(request, context):
authorization_header = request.headers['Authorization'].decode('utf8')
request_nonce = re.search(r'oauth_nonce="(.*?)"', authorization_header).group(1)
return jwt.encode(
content = jwt.encode(
{
'username': 'wash',
'aud': 'client_id',
Expand All @@ -30,6 +31,10 @@ def post_token(request, context):
},
'client_secret',
)
if PYJWT_2:
content = content.encode()

return content

with requests_mock.Mocker() as mock:
mock.post(
Expand Down

0 comments on commit beb31a4

Please sign in to comment.