Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions ecommerce/social_auth/tests/test_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
import uuid
from calendar import timegm

import jwt
import responses
from django.contrib.auth import get_user_model
from django.test import override_settings
from django.urls import reverse
from jwkest.jwk import SYMKey
from jwkest.jws import JWS
from social_django.models import DjangoStorage

from ecommerce.social_auth.strategies import CurrentSiteDjangoStrategy
Expand Down Expand Up @@ -58,12 +57,12 @@ def test_get_setting_raises_exception_on_missing_setting(self):

def create_jwt(self, user):
"""
Creates a signed (JWS) ID token.
Creates a signed JWT ID token.

Returns:
str: JWS
str: JWT
"""
key = SYMKey(key=self.site.siteconfiguration.oauth_settings['SOCIAL_AUTH_EDX_OAUTH2_SECRET'])
secret = self.site.siteconfiguration.oauth_settings['SOCIAL_AUTH_EDX_OAUTH2_SECRET']
now = datetime.datetime.utcnow()
expiration_datetime = now + datetime.timedelta(seconds=3600)
issue_datetime = now
Expand All @@ -76,7 +75,7 @@ def create_jwt(self, user):
'aud': self.site.siteconfiguration.oauth_settings['SOCIAL_AUTH_EDX_OAUTH2_KEY'],
'exp': timegm(expiration_datetime.utctimetuple()),
}
access_token = JWS(payload, jwk=key, alg='HS512').sign_compact()
access_token = jwt.encode(payload, secret, algorithm='HS512')
Copy link

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jwt.encode() method returns a string in newer versions of PyJWT (2.0+), but the original jwkest code expected bytes. This change may cause compatibility issues if the calling code expects bytes. Consider checking how access_token is used elsewhere and potentially add .encode() if bytes are required.

Copilot uses AI. Check for mistakes.
return access_token

def mock_access_token_jwt_response(self, user, status=200):
Expand Down
6 changes: 0 additions & 6 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ funcsigs==1.0.2
future==0.18.3
# via
# -r requirements/test.txt
# pyjwkest
getsmarter-api-clients==0.6.0
# via -r requirements/test.txt
gitdb==4.0.10
Expand Down Expand Up @@ -679,7 +678,6 @@ pycryptodomex==3.18.0
# via
# -r requirements/test.txt
# cybersource-rest-client-python
# pyjwkest
pydata-sphinx-theme==0.13.3
# via
# -r requirements/docs.txt
Expand All @@ -692,8 +690,6 @@ pygments==2.15.1
# diff-cover
# pydata-sphinx-theme
# sphinx
pyjwkest==1.4.2
# via -r requirements/test.txt
pyjwt[crypto]==2.7.0
# via
# -r requirements/test.txt
Expand Down Expand Up @@ -848,7 +844,6 @@ requests==2.31.0
# inapppy
# naked
# paypalrestsdk
# pyjwkest
# pytest-base-url
# pytest-selenium
# requests-file
Expand Down Expand Up @@ -928,7 +923,6 @@ six==1.16.0
# oauth2client
# paypalrestsdk
# purl
# pyjwkest
# python-dateutil
# python-memcached
# requests-file
Expand Down
1 change: 0 additions & 1 deletion requirements/e2e.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

# Packages required to run e2e tests
edx-rest-api-client
pyjwkest
pytest
pytest-randomly
pytest-selenium
Expand Down
7 changes: 0 additions & 7 deletions requirements/e2e.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ edx-rest-api-client==5.5.2
# -r requirements/e2e.in
exceptiongroup==1.1.1
# via pytest
future==0.18.3
# via pyjwkest
idna==2.7
# via
# -c requirements/base.txt
Expand Down Expand Up @@ -93,9 +91,6 @@ pycparser==2.21
pycryptodomex==3.18.0
# via
# -c requirements/base.txt
# pyjwkest
pyjwkest==1.4.2
# via -r requirements/e2e.in
pyjwt[crypto]==2.7.0
# via
# -c requirements/base.txt
Expand Down Expand Up @@ -142,7 +137,6 @@ requests==2.31.0
# via
# -c requirements/base.txt
# edx-rest-api-client
# pyjwkest
# pytest-base-url
# pytest-selenium
# slumber
Expand All @@ -154,7 +148,6 @@ selenium==3.141.0
six==1.16.0
# via
# -c requirements/base.txt
# pyjwkest
# tenacity
slumber==0.7.1
# via
Expand Down
6 changes: 0 additions & 6 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ funcsigs==1.0.2
future==0.18.3
# via
# -r requirements/e2e.txt
# pyjwkest
getsmarter-api-clients==0.6.0
# via -r requirements/base.txt
google-api-core==2.11.1
Expand Down Expand Up @@ -658,13 +657,10 @@ pycryptodomex==3.18.0
# -r requirements/base.txt
# -r requirements/e2e.txt
# cybersource-rest-client-python
# pyjwkest
pygments==2.15.1
# via
# -r requirements/base.txt
# diff-cover
pyjwkest==1.4.2
# via -r requirements/e2e.txt
pyjwt[crypto]==2.7.0
# via
# -r requirements/base.txt
Expand Down Expand Up @@ -823,7 +819,6 @@ requests==2.31.0
# inapppy
# naked
# paypalrestsdk
# pyjwkest
# pytest-base-url
# pytest-selenium
# requests-file
Expand Down Expand Up @@ -905,7 +900,6 @@ six==1.16.0
# oauth2client
# paypalrestsdk
# purl
# pyjwkest
# python-dateutil
# python-memcached
# requests-file
Expand Down
Loading