dd public_jwk_url and is_lti_key fields to developer key model

refs PLAT-4493

Test Plan:
-Create a developer key and verify that it has the new fields
	(public-jwk_url and is_lti_key)

Change-Id: I72508ae26709ce5f7560de35d5ee0c03d4000b5d
Reviewed-on: https://gerrit.instructure.com/197314
Tested-by: Jenkins
Reviewed-by: James Williams <jamesw@instructure.com>
Reviewed-by: Clint Furse <cfurse@instructure.com>
Reviewed-by: Weston Dransfield <wdransfield@instructure.com>
QA-Review: Weston Dransfield <wdransfield@instructure.com>
Product-Review: Drake Harper <dharper@instructure.com>
This commit is contained in:
Drake Harper 2019-06-11 15:25:08 -06:00
parent bb3f8a0c04
commit 0df1e52bb0
5 changed files with 77 additions and 3 deletions

View File

@ -164,7 +164,9 @@ class Lti::ToolConfigurationsApiController < ApplicationController
developer_key = tool_config.developer_key
developer_key.redirect_uris = redirect_uris unless redirect_uris.nil?
developer_key.public_jwk = tool_config.settings['public_jwk']
developer_key.public_jwk_url = tool_config.settings['public_jwk_url']
developer_key.oidc_initiation_url = tool_config.settings['oidc_initiation_url']
developer_key.is_lti_key = true
developer_key.update!(developer_key_params)
end

View File

@ -38,6 +38,7 @@ class DeveloperKey < ActiveRecord::Base
before_create :generate_api_key
before_create :set_auto_expire_tokens
before_create :set_visible
before_create :infer_key_type
before_save :nullify_empty_icon_url
before_save :protect_default_key
before_save :set_require_scopes
@ -46,7 +47,7 @@ class DeveloperKey < ActiveRecord::Base
after_update :destroy_external_tools!, if: :destroy_external_tools?
after_create :create_default_account_binding
validates_as_url :redirect_uri, :oidc_initiation_url, allowed_schemes: nil
validates_as_url :redirect_uri, :oidc_initiation_url, :public_jwk_url, allowed_schemes: nil
validate :validate_redirect_uris
validate :validate_public_jwk
@ -296,6 +297,10 @@ class DeveloperKey < ActiveRecord::Base
private
def infer_key_type
self.is_lti_key = self.public_jwk.present? || self.public_jwk_url.present?
end
def manage_external_tools(enqueue_args, method, affected_account)
return if tool_configuration.blank?

View File

@ -0,0 +1,30 @@
#
# Copyright (C) 2019 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
class AddPublicJwkFieldsToDeveloperKey < ActiveRecord::Migration[5.1]
tag :predeploy
def change
add_column :developer_keys, :public_jwk_url, :string
add_column :developer_keys, :is_lti_key, :boolean
change_column_default(:developer_keys, :is_lti_key, false)
DataFixup::BackfillNulls.run(DeveloperKey, :is_lti_key, default_value: false)
change_column_null(:developer_keys, :is_lti_key, false)
end
end

View File

@ -49,6 +49,7 @@ module Api::V1::DeveloperKey
hash['last_used_at'] = key.last_used_at
hash['vendor_code'] = key.vendor_code
hash['public_jwk'] = key.public_jwk
hash['public_jwk_url'] = key.public_jwk_url
end
if account_binding.present?
@ -60,7 +61,7 @@ module Api::V1::DeveloperKey
hash['visible'] = key.visible
end
hash['tool_configuration'] = key.tool_configuration&.configuration if include_tool_config
hash['is_lti_key'] = key.public_jwk.present?
hash['is_lti_key'] = (key.is_lti_key.nil? ? key.public_jwk.present? : key.is_lti_key)
hash['id'] = key.global_id
end
end

View File

@ -41,6 +41,42 @@ describe DeveloperKey do
)
end
describe 'default values for is_lti_key' do
let(:public_jwk) do
key_hash = Lti::RSAKeyPair.new.public_jwk.to_h
key_hash['kty'] = key_hash['kty'].to_s
key_hash
end
let(:developer_key_with_jwk) { DeveloperKey.create!(public_jwk: public_jwk) }
let(:developer_key_with_url) { DeveloperKey.create!(public_jwk_url: "https://hello.world.com") }
let(:developer_key_with_key_and_url) { DeveloperKey.create!(public_jwk: public_jwk, public_jwk_url: "https://hello.world.com") }
let(:developer_key_none) { DeveloperKey.create! }
context 'when public jwk is present' do
it 'is_lti_key should return true' do
expect(developer_key_with_jwk.is_lti_key).to eq true
end
end
context 'when public jwk url is present' do
it 'is_lti_key should return true' do
expect(developer_key_with_url.is_lti_key).to eq true
end
end
context 'when public jwk url and public jwk is not present' do
it 'is_lti_key should return false' do
expect(developer_key_none.is_lti_key).to eq false
end
end
context 'when public jwk url and public jwk is present' do
it 'is_lti_key should return true' do
expect(developer_key_with_key_and_url.is_lti_key).to eq true
end
end
end
describe 'external tool management' do
specs_require_sharding
include_context 'lti_1_3_spec_helper'
@ -345,7 +381,7 @@ describe DeveloperKey do
it { is_expected.to match_array [lti_site_admin_key] }
end
end
end
describe "sets a default value" do
it "when visible is not specified" do