forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal_tools_spec.rb
More file actions
213 lines (179 loc) · 9.81 KB
/
Copy pathexternal_tools_spec.rb
File metadata and controls
213 lines (179 loc) · 9.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#
# Copyright (C) 2011 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/>.
#
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'nokogiri'
describe "External Tools" do
describe "Assignments" do
before do
course_factory(active_all: true)
assignment_model(:course => @course, :submission_types => "external_tool", :points_possible => 25)
@tool = @course.context_external_tools.create!(:shared_secret => 'test_secret', :consumer_key => 'test_key', :name => 'my grade passback test tool', :domain => 'example.com')
@tag = @assignment.build_external_tool_tag(:url => "http://example.com/one")
@tag.content_type = 'ContextExternalTool'
@tag.save!
end
it "should generate valid LTI parameters" do
student_in_course(:course => @course, :active_all => true)
user_session(@user)
get "/courses/#{@course.id}/assignments/#{@assignment.id}"
expect(response).to be_success
doc = Nokogiri::HTML.parse(response.body)
form = doc.at_css('form#tool_form')
expect(form.at_css('input#launch_presentation_locale')['value']).to eq 'en'
expect(form.at_css('input#oauth_callback')['value']).to eq 'about:blank'
expect(form.at_css('input#oauth_signature_method')['value']).to eq 'HMAC-SHA1'
expect(form.at_css('input#launch_presentation_return_url')['value']).to eq "http://www.example.com/courses/#{@course.id}/external_content/success/external_tool_redirect"
expect(form.at_css('input#lti_message_type')['value']).to eq "basic-lti-launch-request"
expect(form.at_css('input#lti_version')['value']).to eq "LTI-1p0"
expect(form.at_css('input#oauth_version')['value']).to eq "1.0"
expect(form.at_css('input#roles')['value']).to eq "Learner"
end
it "should include outcome service params when viewing as student" do
student_in_course(:course => @course, :active_all => true)
user_session(@user)
Canvas::Security.stubs(:hmac_sha1).returns('some_sha')
payload = [@tool.id, @course.id, @assignment.id, @user.id].join('-')
get "/courses/#{@course.id}/assignments/#{@assignment.id}"
expect(response).to be_success
doc = Nokogiri::HTML.parse(response.body)
expect(doc.at_css('form#tool_form input#lis_result_sourcedid')['value']).to eq "#{payload}-some_sha"
expect(doc.at_css('form#tool_form input#lis_outcome_service_url')['value']).to eq lti_grade_passback_api_url(@tool)
expect(doc.at_css('form#tool_form input#ext_ims_lis_basic_outcome_url')['value']).to eq blti_legacy_grade_passback_api_url(@tool)
end
it "should not include outcome service sourcedid when viewing as teacher" do
@course.enroll_teacher(user_factory(:active_all => true))
user_session(@user)
get "/courses/#{@course.id}/assignments/#{@assignment.id}"
expect(response).to be_success
doc = Nokogiri::HTML.parse(response.body)
expect(doc.at_css('form#tool_form input#lis_result_sourcedid')).to be_nil
expect(doc.at_css('form#tool_form input#lis_outcome_service_url')).not_to be_nil
end
it "should include time zone in LTI paramaters if included in custom fields" do
@tool.custom_fields = {
"custom_time_zone" => "$Person.address.timezone",
}
@tool.save!
student_in_course(:course => @course, :active_all => true)
user_session(@user)
account = @course.root_account
account.default_time_zone = 'Alaska'
account.save!
get "/courses/#{@course.id}/assignments/#{@assignment.id}"
expect(response).to be_success
doc = Nokogiri::HTML.parse(response.body)
expect(doc.at_css('form#tool_form input#custom_time_zone')['value']).to eq "America/Juneau"
@user.time_zone = "Hawaii"
@user.save!
get "/courses/#{@course.id}/assignments/#{@assignment.id}"
expect(response).to be_success
doc = Nokogiri::HTML.parse(response.body)
expect(doc.at_css('form#tool_form input#custom_time_zone')['value']).to eq "Pacific/Honolulu"
end
it "should redirect if the tool can't be configured" do
@tag.update_attribute(:url, "http://example.net")
student_in_course(:active_all => true)
user_session(@user)
get "/courses/#{@course.id}/assignments/#{@assignment.id}"
expect(response).to redirect_to(course_url(@course))
expect(flash[:error]).to be_present
end
it "should render inline external tool links with a full return url" do
student_in_course(:active_all => true)
user_session(@user)
get "/courses/#{@course.id}/external_tools/retrieve?url=#{CGI.escape(@tag.url)}"
expect(response).to be_success
doc = Nokogiri::HTML.parse(response.body)
expect(doc.at_css('#tool_form')).not_to be_nil
expect(doc.at_css("input[name='launch_presentation_return_url']")['value']).to match(/^http/)
end
it "should render user navigation tools with a full return url" do
tool = @course.root_account.context_external_tools.build(:shared_secret => 'test_secret', :consumer_key => 'test_key', :name => 'my grade passback test tool', :domain => 'example.com', :privacy_level => 'public')
tool.user_navigation = {:url => "http://www.example.com", :text => "Example URL"}
tool.save!
student_in_course(:active_all => true)
user_session(@user)
get "/users/#{@user.id}/external_tools/#{tool.id}"
expect(response).to be_success
doc = Nokogiri::HTML.parse(response.body)
expect(doc.at_css('#tool_form')).not_to be_nil
expect(doc.at_css("input[name='launch_presentation_return_url']")['value']).to match(/^http/)
end
end
it "should highlight the navigation tab when using an external tool" do
course_with_teacher_logged_in(:active_all => true)
@tool = @course.context_external_tools.create!(:shared_secret => 'test_secret', :consumer_key => 'test_key', :name => 'my grade passback test tool', :domain => 'example.com')
@tool.course_navigation = {:url => "http://www.example.com", :text => "Example URL"}
@tool.save!
get "/courses/#{@course.id}/external_tools/#{@tool.id}"
expect(response).to be_success
doc = Nokogiri::HTML.parse(response.body)
tab = doc.at_css("a.#{@tool.asset_string}")
expect(tab).not_to be_nil
expect(tab['class'].split).to include("active")
end
context 'global navigation' do
before :once do
Account.default.enable_feature!(:lor_for_account)
@admin_tool = Account.default.context_external_tools.new(:name => "a", :domain => "google.com", :consumer_key => '12345', :shared_secret => 'secret')
@admin_tool.global_navigation = {:visibility => 'admins', :url => "http://www.example.com", :text => "Example URL"}
@admin_tool.save!
@member_tool = Account.default.context_external_tools.new(:name => "b", :domain => "google.com", :consumer_key => '12345', :shared_secret => 'secret')
@member_tool.global_navigation = {:url => "http://www.example.com", :text => "Example URL 2"}
@member_tool.save!
end
it "should show the admin level global navigation menu items to teachers" do
course_with_teacher_logged_in(:account => @account, :active_all => true)
get "/courses"
expect(response).to be_success
doc = Nokogiri::HTML.parse(response.body)
menu_link1 = doc.at_css("##{@admin_tool.asset_string}_menu_item a")
expect(menu_link1).not_to be_nil
expect(menu_link1['href']).to eq account_external_tool_path(Account.default, @admin_tool, :launch_type => 'global_navigation')
expect(menu_link1.text).to match_ignoring_whitespace(@admin_tool.label_for(:global_navigation))
menu_link2 = doc.at_css("##{@member_tool.asset_string}_menu_item a")
expect(menu_link2).not_to be_nil
expect(menu_link2['href']).to eq account_external_tool_path(Account.default, @member_tool, :launch_type => 'global_navigation')
expect(menu_link2.text).to match_ignoring_whitespace(@member_tool.label_for(:global_navigation))
end
it "should only show the member level global navigation menu items to students" do
course_with_student_logged_in(:account => @account, :active_all => true)
get "/courses"
expect(response).to be_success
doc = Nokogiri::HTML.parse(response.body)
menu_link1 = doc.at_css("##{@admin_tool.asset_string}_menu_item a")
expect(menu_link1).to be_nil
menu_link2 = doc.at_css("##{@member_tool.asset_string}_menu_item a")
expect(menu_link2).not_to be_nil
expect(menu_link2['href']).to eq account_external_tool_path(Account.default, @member_tool, :launch_type => 'global_navigation')
expect(menu_link2.text).to match_ignoring_whitespace(@member_tool.label_for(:global_navigation))
end
end
it "should include the apps tab on account settings even without account settings management rights" do
account_admin_user_with_role_changes(:role_changes => {:manage_account_settings => false})
user_session(@admin)
get "/accounts/#{Account.default.id}/settings"
expect(response.body).to include("tab-tools-link")
end
it "should not include the apps tab on account settings without lti rights" do
account_admin_user_with_role_changes(:role_changes => {:lti_add_edit => false})
user_session(@admin)
get "/accounts/#{Account.default.id}/settings"
expect(response.body).to_not include("tab-tools-link")
end
end