You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've a working system - I can connect from a test moodle to my tool - and now I want to add a test for the code.
My test code starts:
Overall imports
from rest_framework_jwt.settings import api_settings as jwt_settings
from mock import patch
from unittest.mock import Mock
from urllib import parse
from django.test import Client
from myApp.lti1p3_backend import ToolConfMyApp # My version of DjangoDbToolConf
from myApp_utils.test_utils import TestCreators # some helper methods for creating test objects in the db
class TestToolConfMyApp(TestCreators):
There are a whole suite of tests for the ToolConfMyApp functions: check_iss_has_one_client, check_iss_has_many_clients, get_public_key, get_iss_config, etc...
I've even got POST and GET tests for login - and test the parameters in the response.url from those calls
For the specific launch test - this is what I start with:
@patch('pylti1p3.message_launch.MessageLaunch.fetch_public_key')
def test_launch(self, mock_fpk: Mock):
# Set up the environment, and the initial login
key = self.create_lti1p3_tool_key(name="test", private_key="foo", public_key=pub_key)
self.create_lti1p3_tool(
title="test",
tool_key=key,
issuer="example_dot_com",
client_id="foo",
auth_login_url="http://example.com/a",
auth_token_url="http://example.com/b",
deployment_ids='["test-id-1", "test-id-2"]',
key_set_url="http://example.com/c",
)
c = Client()
response = c.get("/lti1p3/login/?lti1p3_new_window=1&iss=example_dot_com&login_hint=5&target_link_uri=http%3A%2F%2Fexample.com%2Flti1p3%2Flaunch%2F<i_message_hint=5<i_deployment_id=3&client_id=foo")
# Cookies should now exist, test launch
.... and it fails with a pylti1p3.exception.LtiException: JWT KID not found error.
The full error reads:
Traceback (most recent call last):
File \"/path/to/lib/python3.7/site-packages/django/core/handlers/exception.py\", line 47, in inner
response = get_response(request)
File \"/path/to/lib/python3.7/site-packages/django/core/handlers/base.py\", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File \"/path/to/lib/python3.7/site-packages/sentry_sdk/integrations/django/views.py\", line 36, in sentry_wrapped_callback
return callback(request, *args, **kwargs)
File \"/path/to/lib/python3.7/site-packages/django/views/generic/base.py\", line 70, in view
return self.dispatch(request, *args, **kwargs)
File \"/different/path/to/mycomponent/api/views.py\", line 554, in dispatch
return super().dispatch(*args, **kwargs)
File \"/different/path/to/mycomponent/api/views.py\", line 494, in dispatch
payload = self.add_extra_jwt_claims(payload)
File \"/different/path/to/mycomponent/api/views.py\", line 564, in add_extra_jwt_claims
message_launch_data = message_launch.get_launch_data()
File \"/path/to/lib/python3.7/site-packages/pylti1p3/message_launch.py\", line 494, in get_launch_data
return self._get_jwt_body()
File \"/path/to/lib/python3.7/site-packages/pylti1p3/message_launch.py\", line 299, in _get_jwt_body
self.validate()
File \"/path/to/lib/python3.7/site-packages/pylti1p3/message_launch.py\", line 284, in validate
return self.validate_state()\\
File \"/path/to/lib/python3.7/site-packages/pylti1p3/message_launch.py\", line 671, in validate_jwt_signature
public_key = self.get_public_key()
File \"/path/to/lib/python3.7/site-packages/pylti1p3/message_launch.py\", line 569, in get_public_key
raise LtiException(\"JWT KID not found\")
pylti1p3.exception.LtiException: JWT KID not found
Digging into the code, the problem seems to be the contents of self._jwt in the MessageLaunch.get_public_key method has the id_token rather than the jwks
Any hints as to where I'm going wrong?
EDIT:
I can confirm that tool_conf.get_jwks("example_dot_com") returns an appropriate token:
I've a working system - I can connect from a test moodle to my tool - and now I want to add a test for the code.
My test code starts:
Overall imports
There are a whole suite of tests for the
ToolConfMyApp
functions:check_iss_has_one_client
,check_iss_has_many_clients
,get_public_key
,get_iss_config
, etc...I've even got
POST
andGET
tests for login - and test the parameters in theresponse.url
from those callsFor the specific launch test - this is what I start with:
Then we want to set up the token for actual call:
.... and it fails with a
pylti1p3.exception.LtiException: JWT KID not found
error.The full error reads:
Digging into the code, the problem seems to be the contents of
self._jwt
in theMessageLaunch.get_public_key
method has theid_token
rather than thejwks
Any hints as to where I'm going wrong?
EDIT:
I can confirm that
tool_conf.get_jwks("example_dot_com")
returns an appropriate token:The text was updated successfully, but these errors were encountered: