chore: Removed unused dependency

This commit is contained in:
Marcos
2025-01-07 10:46:54 -03:00
committed by Marcos Rigoli
parent 825931a9b4
commit 3bcbcaac2d
11 changed files with 27 additions and 65 deletions

View File

@@ -9,9 +9,6 @@ from jwkest.jws import JWS
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
@@ -28,6 +25,10 @@ expected_full_token = {
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)
@@ -53,6 +54,7 @@ class TestSign(unittest.TestCase):
with self.assertRaises(BadSignature):
_verify_jwt(token)
def _verify_jwt(jwt_token):
"""
Helper function which verifies the signature and decodes the token
@@ -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)

View File

@@ -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

View File

@@ -91,6 +91,7 @@ from lms.djangoapps.courseware.courses import (
)
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
@@ -105,7 +106,7 @@ from lms.djangoapps.courseware.user_state_client import DjangoXBlockUserStateCli
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