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 7, 2025
1 parent da81819 commit 03cf226
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 287 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
12 changes: 6 additions & 6 deletions requirements/edx-sandbox/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ cryptography==44.0.0
# via -r requirements/edx-sandbox/base.in
cycler==0.12.1
# via matplotlib
fonttools==4.55.2
fonttools==4.55.3
# via matplotlib
joblib==1.4.2
# via nltk
kiwisolver==1.4.7
kiwisolver==1.4.8
# via matplotlib
lxml[html-clean,html_clean]==5.3.0
# via
Expand All @@ -37,7 +37,7 @@ markupsafe==3.0.2
# via
# chem
# openedx-calc
matplotlib==3.9.3
matplotlib==3.10.0
# via -r requirements/edx-sandbox/base.in
mpmath==1.3.0
# via sympy
Expand All @@ -59,11 +59,11 @@ openedx-calc==4.0.1
# via -r requirements/edx-sandbox/base.in
packaging==24.2
# via matplotlib
pillow==11.0.0
pillow==11.1.0
# via matplotlib
pycparser==2.22
# via cffi
pyparsing==3.2.0
pyparsing==3.2.1
# via
# -r requirements/edx-sandbox/base.in
# chem
Expand All @@ -75,7 +75,7 @@ random2==1.0.2
# via -r requirements/edx-sandbox/base.in
regex==2024.11.6
# via nltk
scipy==1.14.1
scipy==1.15.0
# via
# -r requirements/edx-sandbox/base.in
# chem
Expand Down
Loading

0 comments on commit 03cf226

Please sign in to comment.