Skip to content

Commit

Permalink
Revert "Add new method to encrypt dicts as JWEs"
Browse files Browse the repository at this point in the history
This reverts commit 2de109d.
  • Loading branch information
marcospri committed Oct 17, 2023
1 parent 156feba commit 34ccdca
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 39 deletions.
15 changes: 0 additions & 15 deletions lms/services/jwt.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import copy
import datetime
import json
import logging
from functools import lru_cache

import jwt
import requests
from jose import constants, jwe
from jwt.exceptions import ExpiredSignatureError, InvalidTokenError, PyJWTError

from lms.services.exceptions import ExpiredJWTError, InvalidJWTError
Expand All @@ -26,9 +24,6 @@ class JWTService:
JWT and us.
"""

JWE_ALGORITHM = constants.ALGORITHMS.DIR
JWE_ENCRYPTION = constants.ALGORITHMS.A128CBC_HS256

def __init__(self, registration_service, rsa_key_service):
self._registration_service = registration_service
self._rsa_key_service = rsa_key_service
Expand Down Expand Up @@ -144,16 +139,6 @@ def encode_with_private_key(self, payload: dict):
headers={"kid": key.kid},
)

def encrypt_dict(self, secret, payload: dict) -> str:
"""Encrypt a dictionary as a JWE."""

return jwe.encrypt(
json.dumps(payload),
secret,
algorithm=self.JWE_ALGORITHM,
encryption=self.JWE_ENCRYPTION,
).decode("utf-8")

@staticmethod
@lru_cache
def _get_jwk_client(jwk_url: str):
Expand Down
24 changes: 0 additions & 24 deletions tests/unit/lms/services/jwt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import jwt
import pytest
from freezegun import freeze_time
from jose import constants
from jwt.exceptions import InvalidTokenError
from pyramid.config import Configurator
from pytest import param
Expand Down Expand Up @@ -146,21 +145,6 @@ def test_decode_lti_token_with_invalid_jwt(self, svc, jwt):

assert "jwt" in exc_info.value.messages

def test_encrypt_dict(self, svc, json, jwe):
payload_dict = {"some": "data"}
secret = "SECRET" * 10

encrypted = svc.encrypt_dict(secret, payload_dict)

json.dumps.assert_called_with(payload_dict)
jwe.encrypt.assert_called_once_with(
json.dumps.return_value,
secret.ljust(32),
algorithm=constants.ALGORITHMS.DIR,
encryption=constants.ALGORITHMS.A128CBC_HS256,
)
assert encrypted == jwe.encrypt.return_value.decode.return_value

@staticmethod
def encode_jwt(
payload,
Expand Down Expand Up @@ -198,14 +182,6 @@ def svc(self, lti_registration_service, rsa_key_service):
svc._get_jwk_client.cache_clear() # pylint: disable=protected-access
return svc

@pytest.fixture
def json(self, patch):
return patch("lms.services.jwt.json")

@pytest.fixture
def jwe(self, patch):
return patch("lms.services.jwt.jwe")


class Test_RequestsPyJWKClient:
def test_fetch_data(self, requests):
Expand Down

0 comments on commit 34ccdca

Please sign in to comment.