Skip to content

Commit 850833e

Browse files
author
Andrew Butterfield
committed
Add RootAccountId to jwt for LiveEventSubscriptionService
fixes PLAT-2280 Test plan: * Install an LTI 2.1 tool with a developer key * Start a rails console and run any of the Services::LiveEventsSubscriptionService methods and save the result * Inspect the request that was sent out with result.request.options * Grab the JWT from the headers and decrypt it using Canvas Security * Ensure that the RootAccountId is there and that the DeveloperKey is there Change-Id: I688b45efe1dd16db0d48adcaf718de801a681415 Reviewed-on: https://gerrit.instructure.com/103076 Reviewed-by: Nathan Mills <nathanm@instructure.com> Tested-by: Jenkins QA-Review: August Thornton <august@instructure.com> Product-Review: Andrew Butterfield <abutterfield@instructure.com>
1 parent becb8ed commit 850833e

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

lib/services/live_events_subscription_service.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def settings
6262
def tool_proxy_jwt_body(tool_proxy, options = {})
6363
options.merge({
6464
sub: "ltiToolProxy:#{tool_proxy.guid}",
65-
developerKey: tool_proxy.product_family.developer_key.global_id.to_s
65+
DeveloperKey: tool_proxy.product_family.developer_key.global_id.to_s,
66+
RootAccountId: (tool_proxy.context.global_root_account_id || tool_proxy.context.global_id).to_s
6667
})
6768
end
6869
end

spec/lib/services/live_events_subscription_service_spec.rb

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ module Services
4343
developer_key
4444
end
4545

46+
let(:non_root_account_context) do
47+
non_root_account = mock()
48+
non_root_account.stubs(:global_root_account_id).returns(10000000000007)
49+
non_root_account
50+
end
51+
52+
let(:root_account_context) do
53+
root_account = mock()
54+
root_account.stubs(:global_root_account_id).returns(nil)
55+
root_account.stubs(:global_id).returns(10000000000004)
56+
root_account
57+
end
58+
4659
let(:product_family) do
4760
product_family = mock()
4861
product_family.stubs(:developer_key).returns(developer_key)
@@ -64,11 +77,13 @@ module Services
6477

6578
describe '.destroy_tool_proxy_subscription' do
6679
it 'makes the expected request' do
80+
tool_proxy.stubs(:context).returns(root_account_context)
6781
HTTParty.expects(:send).with do |method, endpoint, options|
6882
expect(method).to eq(:delete)
6983
expect(endpoint).to eq('http://example.com/api/subscriptions/subscription_id')
7084
jwt = Canvas::Security::ServicesJwt.new(options[:headers]['Authorization'].gsub('Bearer ',''), false).original_token
71-
expect(jwt["developerKey"]).to eq('10000000000003')
85+
expect(jwt["DeveloperKey"]).to eq('10000000000003')
86+
expect(jwt["RootAccountId"]).to eq('10000000000004')
7287
expect(jwt["sub"]).to eq('ltiToolProxy:151b52cd-d670-49fb-bf65-6a327e3aaca0')
7388
end
7489
LiveEventsSubscriptionService.destroy_tool_proxy_subscription(tool_proxy, 'subscription_id')
@@ -77,11 +92,13 @@ module Services
7792

7893
describe '.tool_proxy_subscription' do
7994
it 'makes the expected request' do
95+
tool_proxy.stubs(:context).returns(non_root_account_context)
8096
HTTParty.expects(:send).with do |method, endpoint, options|
8197
expect(method).to eq(:get)
8298
expect(endpoint).to eq('http://example.com/api/subscriptions/subscription_id')
8399
jwt = Canvas::Security::ServicesJwt.new(options[:headers]['Authorization'].gsub('Bearer ',''), false).original_token
84-
expect(jwt["developerKey"]).to eq('10000000000003')
100+
expect(jwt["DeveloperKey"]).to eq('10000000000003')
101+
expect(jwt["RootAccountId"]).to eq('10000000000007')
85102
expect(jwt["sub"]).to eq('ltiToolProxy:151b52cd-d670-49fb-bf65-6a327e3aaca0')
86103
end
87104
LiveEventsSubscriptionService.tool_proxy_subscription(tool_proxy, 'subscription_id')
@@ -90,11 +107,13 @@ module Services
90107

91108
describe '.tool_proxy_subscriptions' do
92109
it 'makes the expected request' do
110+
tool_proxy.stubs(:context).returns(non_root_account_context)
93111
HTTParty.expects(:send).with do |method, endpoint, options|
94112
expect(method).to eq(:get)
95113
expect(endpoint).to eq('http://example.com/api/subscriptions')
96114
jwt = Canvas::Security::ServicesJwt.new(options[:headers]['Authorization'].gsub('Bearer ',''), false).original_token
97-
expect(jwt["developerKey"]).to eq('10000000000003')
115+
expect(jwt["DeveloperKey"]).to eq('10000000000003')
116+
expect(jwt["RootAccountId"]).to eq('10000000000007')
98117
expect(jwt["sub"]).to eq('ltiToolProxy:151b52cd-d670-49fb-bf65-6a327e3aaca0')
99118
end
100119
LiveEventsSubscriptionService.tool_proxy_subscriptions(tool_proxy)
@@ -103,14 +122,16 @@ module Services
103122

104123
describe '.create_tool_proxy_subscription' do
105124
it 'makes the expected request' do
125+
tool_proxy.stubs(:context).returns(root_account_context)
106126
subscription = { 'my' => 'subscription' }
107127

108128
HTTParty.expects(:send).with do |method, endpoint, options|
109129
expect(method).to eq(:post)
110130
expect(endpoint).to eq('http://example.com/api/subscriptions')
111131
expect(options[:headers]['Content-Type']).to eq('application/json')
112132
jwt = Canvas::Security::ServicesJwt.new(options[:headers]['Authorization'].gsub('Bearer ',''), false).original_token
113-
expect(jwt['developerKey']).to eq('10000000000003')
133+
expect(jwt['DeveloperKey']).to eq('10000000000003')
134+
expect(jwt["RootAccountId"]).to eq('10000000000004')
114135
expect(jwt['sub']).to eq('ltiToolProxy:151b52cd-d670-49fb-bf65-6a327e3aaca0')
115136
expect(JSON.parse(options[:body])).to eq(subscription)
116137
end
@@ -121,14 +142,16 @@ module Services
121142

122143
describe '.update_tool_proxy_subscription' do
123144
it 'makes the expected request' do
145+
tool_proxy.stubs(:context).returns(root_account_context)
124146
subscription = { 'my' => 'subscription' }
125147

126148
HTTParty.expects(:send).with do |method, endpoint, options|
127149
expect(method).to eq(:put)
128150
expect(endpoint).to eq('http://example.com/api/subscriptions/subscription_id')
129151
expect(options[:headers]['Content-Type']).to eq('application/json')
130152
jwt = Canvas::Security::ServicesJwt.new(options[:headers]['Authorization'].gsub('Bearer ',''), false).original_token
131-
expect(jwt['developerKey']).to eq('10000000000003')
153+
expect(jwt['DeveloperKey']).to eq('10000000000003')
154+
expect(jwt["RootAccountId"]).to eq('10000000000004')
132155
expect(jwt['sub']).to eq('ltiToolProxy:151b52cd-d670-49fb-bf65-6a327e3aaca0')
133156
expect(JSON.parse(options[:body])).to eq(subscription)
134157
end
@@ -139,6 +162,7 @@ module Services
139162

140163
context 'timeout protection' do
141164
it 'throws an exception for .tool_proxy_subscriptions' do
165+
tool_proxy.stubs(:context).returns(root_account_context)
142166
Timeout.expects(:timeout).raises(Timeout::Error)
143167
expect { LiveEventsSubscriptionService.tool_proxy_subscriptions(tool_proxy) }.to raise_error(Timeout::Error)
144168
end

0 commit comments

Comments
 (0)