doc/lti/11_testing.md
There are a few common scenarios for testing LTI tools that will be detailed here, so that test plans on commits can just reference the pertinent section of this document instead of typing out the installation/setup/reproduction instructions.
LTI 1.1 tools can pass grades back to Canvas, only after the student has launched the tool from the associated assignment. Using the Outcome Service Example tool, it's possible to locally perform this action.
?become_student and ?become_user_id=:id helpers may be useful here. While on the assignment page with url http://canvas.docker/courses/1/assignments/, add either of those parameters on to the end of the url to automatically masquerade as the student.lti_example.rb:100. Documentation for this XML is located in the Canvas API docs.The Assignments and Grades Service, which is part of LTI Advantage, allows 1.3 tools to pass grades back to Canvas with much more flexibility than the 1.1 Basic Outcomes methods. There are a couple of ways to make these kinds of requests locally.
LTI access tokens are different than normal API access tokens, in that they aren't directly tied to a User or a DeveloperKey, and that they are a JWT instead of a traditional encoded string. This JWT contains useful information about the tool that requested the token, the scopes that the key is allowed to access, and the expiration of the token.
Historically, generating an LTI access token requires an installed tool to create another JWT and send it to Canvas, and the best tool to do that with is the 1.3 test tool. Unfortunately, that tool is difficult to install in a production environment without using ngrok.
It's now possible to, as a Site Admin user, directly ask Canvas for an LTI access token for any 1.3 tool. This will make local development and troubleshooting much easier.
<host>/api/lti/advantage_token, and pass one of these two parameters: tool_id=<tool id> or client_id=<client id>. Example: http://canvas.docker/api/lti/token?tool_id=6 or office365.instructure.com/api/lti/token?client_id=170000000000401The test tool provides a nice UI for making all types of AGS requests, which can be nice for testing established features.
http://lti13testtool.docker/ags/new and populate the information needed for the call you want to make. Submit the form to make the request.ags_service.rb file in the test tool repository.For testing new features that may not have been added to the test tool, or for maximum flexibility, you can make requests to the AGS endpoints using any HTTP client you like (curl, Postman, Insomnia, etc). You will need to acquire an LTI access token, which is different than an API access token. In addition to the site admin token endpoint described above, the test tool also allows for this.
docker compose run --rm web jwt:access_token CLIENT_ID=<global DeveloperKey id>
Authentication: Bearer <jwt> header.This isn't exactly LTI-specific, but can come in handy. There isn't a great way to get
visibility into the calls made to InstStatsd::Statsd, which is the way to get metrics
sent to Datadog. It's possible to monkey-patch that class and stub the methods you care
about and just log them to stdout. If you're working entirely in the Rails console, you
can paste this patch directly into the console. If you're working with Canvas requests
at all, you can paste this patch into any Ruby file in Canvas and save it (I prefer the
one I'm currently working in, for consistency).
Replace increment with any Statsd method you need, or add more methods if needed.
class << InstStatsd::Statsd
def increment(*args)
puts "DEBUG STATSD increment: #{args.to_json}"
end
end
Then, look in the logs for your method calls. If you are working entirely in the Rails
console, they will appear there. If you are working with Canvas requests, tail the web
container's logs with docker compose logs -f --tail=100 web and then search for
DEBUG STATSD.