Skip to content

Commit

Permalink
chore: Removed unused dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Jan 10, 2025
1 parent 5817974 commit fe71169
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 75 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/check_python_dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install repo-tools
run: pip install edx-repo-tools[find_dependencies]

- name: Install setuptool
run: pip install setuptools
run: pip install setuptools

- name: Run Python script
run: |
find_python_dependencies \
Expand All @@ -35,6 +35,5 @@ jobs:
--ignore https://github.com/edx/braze-client \
--ignore https://github.com/edx/edx-name-affirmation \
--ignore https://github.com/mitodl/edx-sga \
--ignore https://github.com/edx/token-utils \
--ignore https://github.com/open-craft/xblock-poll
12 changes: 9 additions & 3 deletions lms/djangoapps/courseware/tests/test_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

from lms.djangoapps.courseware.jwt import _encode_and_sign, create_jwt, unpack_jwt

import unittest
from unittest.mock import patch


test_user_id = 121
invalid_test_user_id = 120
Expand All @@ -28,6 +25,10 @@


class TestSign(unittest.TestCase):
"""
Tests for JWT creation and signing.
"""

def test_create_jwt(self):
token = create_jwt(test_user_id, test_timeout, {}, test_now)

Expand All @@ -53,6 +54,7 @@ def test_malformed_token(self):
with self.assertRaises(BadSignature):
_verify_jwt(token)


def _verify_jwt(jwt_token):
"""
Helper function which verifies the signature and decodes the token
Expand All @@ -65,6 +67,10 @@ def _verify_jwt(jwt_token):


class TestUnpack(unittest.TestCase):
"""
Tests for JWT unpacking.
"""

def test_unpack_jwt(self):
token = create_jwt(test_user_id, test_timeout, {}, test_now)
decoded = unpack_jwt(token, test_user_id, test_now)
Expand Down
33 changes: 0 additions & 33 deletions lms/djangoapps/courseware/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,36 +234,3 @@ def _use_new_financial_assistance_flow(course_id):
):
return True
return False



def unpack_jwt(token, lms_user_id, now=None):
"""
Unpack and verify an encoded JWT.
Validate the user and expiration.
Arguments:
token (string): The token to be unpacked and verified.
lms_user_id (int): LMS user ID this token should match with.
now (int): Optional now value for testing.
Returns a valid, decoded json payload (string).
"""
now = now or int(time())

# Unpack and verify token
keys = jwk.KEYS()
keys.load_jwks(settings.TOKEN_SIGNING['JWT_PUBLIC_SIGNING_JWK_SET'])
payload = JWS().verify_compact(token.encode('utf-8'), keys)

if "lms_user_id" not in payload:
raise MissingKey("LMS user id is missing")
if "exp" not in payload:
raise MissingKey("Expiration is missing")
if payload["lms_user_id"] != lms_user_id:
raise Invalid("User does not match")
if payload["exp"] < now:
raise Expired("Token is expired")

return payload
3 changes: 2 additions & 1 deletion lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
)
from lms.djangoapps.courseware.date_summary import verified_upgrade_deadline_link
from lms.djangoapps.courseware.exceptions import CourseAccessRedirect, Redirect
from lms.djangoapps.courseware.jwt import unpack_jwt
from lms.djangoapps.courseware.masquerade import is_masquerading_as_specific_student, setup_masquerade
from lms.djangoapps.courseware.model_data import FieldDataCache
from lms.djangoapps.courseware.models import BaseStudentModuleHistory, StudentModule
Expand All @@ -105,7 +106,7 @@
from lms.djangoapps.courseware.utils import (
_use_new_financial_assistance_flow,
create_financial_assistance_application,
is_eligible_for_financial_aid, unpack_jwt
is_eligible_for_financial_aid
)
from lms.djangoapps.edxnotes.helpers import is_feature_enabled
from lms.djangoapps.experiments.utils import get_experiment_user_metadata_context
Expand Down
8 changes: 2 additions & 6 deletions requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ django==4.2.17
# edx-search
# edx-submissions
# edx-toggles
# edx-token-utils
# edx-when
# edxval
# enmerkar
Expand Down Expand Up @@ -538,15 +537,13 @@ edx-toggles==5.2.0
# edxval
# event-tracking
# ora2
edx-token-utils==0.2.1
# via -r requirements/edx/kernel.in
edx-when==2.5.0
# via
# -r requirements/edx/kernel.in
# edx-proctoring
edxval==2.8.0
# via -r requirements/edx/kernel.in
elasticsearch==7.9.1
elasticsearch==7.13.4
# via
# -c requirements/edx/../common_constraints.txt
# -c requirements/edx/../constraints.txt
Expand Down Expand Up @@ -933,7 +930,6 @@ pygments==2.19.1
pyjwkest==1.4.2
# via
# -r requirements/edx/kernel.in
# edx-token-utils
# lti-consumer-xblock
pyjwt[crypto]==2.10.1
# via
Expand Down Expand Up @@ -1213,7 +1209,7 @@ uritemplate==4.1.1
# drf-spectacular
# drf-yasg
# google-api-python-client
urllib3==2.2.3
urllib3==1.26.20
# via
# -c requirements/edx/../common_constraints.txt
# botocore
Expand Down
10 changes: 2 additions & 8 deletions requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ django==4.2.17
# edx-search
# edx-submissions
# edx-toggles
# edx-token-utils
# edx-when
# edxval
# enmerkar
Expand Down Expand Up @@ -845,10 +844,6 @@ edx-toggles==5.2.0
# edxval
# event-tracking
# ora2
edx-token-utils==0.2.1
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
edx-when==2.5.0
# via
# -r requirements/edx/doc.txt
Expand All @@ -858,7 +853,7 @@ edxval==2.8.0
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
elasticsearch==7.9.1
elasticsearch==7.13.4
# via
# -c requirements/edx/../common_constraints.txt
# -c requirements/edx/../constraints.txt
Expand Down Expand Up @@ -1599,7 +1594,6 @@ pyjwkest==1.4.2
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
# edx-token-utils
# lti-consumer-xblock
pyjwt[crypto]==2.10.1
# via
Expand Down Expand Up @@ -2169,7 +2163,7 @@ uritemplate==4.1.1
# drf-spectacular
# drf-yasg
# google-api-python-client
urllib3==2.2.3
urllib3==1.26.20
# via
# -c requirements/edx/../common_constraints.txt
# -r requirements/edx/doc.txt
Expand Down
8 changes: 2 additions & 6 deletions requirements/edx/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ django==4.2.17
# edx-search
# edx-submissions
# edx-toggles
# edx-token-utils
# edx-when
# edxval
# enmerkar
Expand Down Expand Up @@ -629,15 +628,13 @@ edx-toggles==5.2.0
# edxval
# event-tracking
# ora2
edx-token-utils==0.2.1
# via -r requirements/edx/base.txt
edx-when==2.5.0
# via
# -r requirements/edx/base.txt
# edx-proctoring
edxval==2.8.0
# via -r requirements/edx/base.txt
elasticsearch==7.9.1
elasticsearch==7.13.4
# via
# -c requirements/edx/../common_constraints.txt
# -c requirements/edx/../constraints.txt
Expand Down Expand Up @@ -1149,7 +1146,6 @@ pygments==2.19.1
pyjwkest==1.4.2
# via
# -r requirements/edx/base.txt
# edx-token-utils
# lti-consumer-xblock
pyjwt[crypto]==2.10.1
# via
Expand Down Expand Up @@ -1527,7 +1523,7 @@ uritemplate==4.1.1
# drf-spectacular
# drf-yasg
# google-api-python-client
urllib3==2.2.3
urllib3==1.26.20
# via
# -c requirements/edx/../common_constraints.txt
# -r requirements/edx/base.txt
Expand Down
1 change: 0 additions & 1 deletion requirements/edx/kernel.in
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ edx-rest-api-client
edx-search
edx-submissions
edx-toggles # Feature toggles management
edx-token-utils # Validate exam access tokens
edx-when
edxval
event-tracking
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/semgrep.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ typing-extensions==4.12.2
# via
# opentelemetry-sdk
# semgrep
urllib3==2.2.3
urllib3==2.3.0
# via
# -c requirements/edx/../common_constraints.txt
# requests
Expand Down
8 changes: 2 additions & 6 deletions requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ django==4.2.17
# edx-search
# edx-submissions
# edx-toggles
# edx-token-utils
# edx-when
# edxval
# enmerkar
Expand Down Expand Up @@ -652,15 +651,13 @@ edx-toggles==5.2.0
# edxval
# event-tracking
# ora2
edx-token-utils==0.2.1
# via -r requirements/edx/base.txt
edx-when==2.5.0
# via
# -r requirements/edx/base.txt
# edx-proctoring
edxval==2.8.0
# via -r requirements/edx/base.txt
elasticsearch==7.9.1
elasticsearch==7.13.4
# via
# -c requirements/edx/../common_constraints.txt
# -c requirements/edx/../constraints.txt
Expand Down Expand Up @@ -1213,7 +1210,6 @@ pygments==2.19.1
pyjwkest==1.4.2
# via
# -r requirements/edx/base.txt
# edx-token-utils
# lti-consumer-xblock
pyjwt[crypto]==2.10.1
# via
Expand Down Expand Up @@ -1613,7 +1609,7 @@ uritemplate==4.1.1
# drf-spectacular
# drf-yasg
# google-api-python-client
urllib3==2.2.3
urllib3==1.26.20
# via
# -c requirements/edx/../common_constraints.txt
# -r requirements/edx/base.txt
Expand Down
6 changes: 2 additions & 4 deletions scripts/xblock/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ idna==3.10
# via requests
requests==2.32.3
# via -r scripts/xblock/requirements.in
urllib3==2.2.3
# via
# -c scripts/xblock/../../requirements/common_constraints.txt
# requests
urllib3==2.3.0
# via requests

0 comments on commit fe71169

Please sign in to comment.