@@ -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