Add ability to get a single subscription

fixes PLAT-2185

Test plan:
* Configure canvas and the subscription service to use the same signing
  secret and encryption key
* With the subscription service running, open up a rails console and run
  the following commands
  ToolProxy = Struct.new("ToolProxy", :guid, :product_family)
  Family = Struct.new("Family", :developer_key)
  f = Family.new(10000000000002)
  tp = ToolProxy.new('hahahah', f)
  res = Services::LiveEventsSubscriptionService.tool_proxy_subscription(tp, "<id for a subscription>")
* Ensure that you get the subscription back successfully

Change-Id: If65ac06c6174cd16195c3bd218f7521b389ed0aa
Reviewed-on: https://gerrit.instructure.com/101425
Tested-by: Jenkins
QA-Review: August Thornton <august@instructure.com>
Reviewed-by: Nathan Mills <nathanm@instructure.com>
Product-Review: Andrew Butterfield <abutterfield@instructure.com>
This commit is contained in:
Andrew Butterfield 2017-02-08 12:04:05 -07:00
parent c9c86901b7
commit 461e68157a
2 changed files with 27 additions and 13 deletions

View File

@ -5,25 +5,19 @@ module Services
settings.present?
end
def tool_proxy_subscription(tool_proxy, subscription_id)
options = { headers: headers(tool_proxy_jwt_body(tool_proxy)) }
request(:get, "/api/subscriptions/#{subscription_id}", options)
end
def tool_proxy_subscriptions(tool_proxy)
options = {
headers: headers({
sub: "ltiToolProxy:#{tool_proxy.guid}",
developerKey: tool_proxy.product_family.developer_key.to_s
})
}
options = { headers: headers(tool_proxy_jwt_body(tool_proxy)) }
request(:get, '/api/subscriptions', options)
end
def create_tool_proxy_subscription(tool_proxy, subscription)
options = {
headers: headers({
sub: "ltiToolProxy:#{tool_proxy.guid}",
developerKey: tool_proxy.product_family.developer_key.to_s
},
{
'Content-Type' => 'application/json'
}),
headers: headers(tool_proxy_jwt_body(tool_proxy), { 'Content-Type' => 'application/json' }),
body: subscription.to_json
}
request(:post, '/api/subscriptions', options)
@ -51,6 +45,13 @@ module Services
Canvas::Errors.capture_exception(:live_events_subscription, e)
nil
end
def tool_proxy_jwt_body(tool_proxy, options = {})
options.merge({
sub: "ltiToolProxy:#{tool_proxy.guid}",
developerKey: tool_proxy.product_family.developer_key.to_s
})
end
end
end
end

View File

@ -56,6 +56,19 @@ module Services
end
end
describe '.tool_proxy_subscription' do
it 'makes the expected request' do
HTTParty.expects(:send).with do |method, endpoint, options|
expect(method).to eq(:get)
expect(endpoint).to eq('http://example.com/api/subscriptions/subscription_id')
jwt = Canvas::Security::ServicesJwt.new(options[:headers]['Authorization'].gsub('Bearer ',''), false).original_token
expect(jwt["developerKey"]).to eq('10000000000003')
expect(jwt["sub"]).to eq('ltiToolProxy:151b52cd-d670-49fb-bf65-6a327e3aaca0')
end
LiveEventsSubscriptionService.tool_proxy_subscription(tool_proxy, 'subscription_id')
end
end
describe '.tool_proxy_subscriptions' do
it 'makes the expected request' do
HTTParty.expects(:send).with do |method, endpoint, options|