Skip to content

Commit

Permalink
support https for retrieving lti xml configs
Browse files Browse the repository at this point in the history
net http needs some additional config in order
to support https requests.

fixes #6938

test plan:
- try adding an external tool with an http url config
  (like http://lti-examples.heroku.com/config/course_navigation.xml)
- make sure it adds correctly

- try adding an external tool with an https url config
  (like https://lti-examples.heroku.com/config/course_navigation.xml)
- make sure it adds correctly

Change-Id: Ia26c7d383069bccf761f18a2993f352002cc868a
Reviewed-on: https://gerrit.instructure.com/8139
Tested-by: Hudson <[email protected]>
Reviewed-by: Bracken Mosbacker <[email protected]>
  • Loading branch information
whitmer committed Jan 19, 2012
1 parent 5ec76f2 commit 5e500c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/cc/importer/blti_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ def convert_blti_xml(xml)

def retrieve_and_convert_blti_url(url)
begin
config_xml = Net::HTTP.get(URI.parse(url))
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == 'https'
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
config_xml = response.body

convert_blti_xml(config_xml)
rescue Timeout::Error
raise CCImportError.new(I18n.t(:retrieve_timeout, "could not retrieve configuration, the server response timed out"))
Expand Down
5 changes: 3 additions & 2 deletions spec/controllers/external_tools_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@
<cartridge_icon identifierref="BLTI001_Icon"/>
</cartridge_basiclti_link>
XML
Net::HTTP.expects(:get).with(URI.parse("http://config.example.com")).returns(xml)
obj = OpenStruct.new({:body => xml})
Net::HTTP.any_instance.stubs(:request).returns(obj)
post 'create', :course_id => @course.id, :external_tool => {:name => "tool name", :url => "http://example.com", :consumer_key => "key", :shared_secret => "secret", :config_type => "by_url", :config_url => "http://config.example.com"}
response.should be_success
assigns[:tool].should_not be_nil
Expand All @@ -216,7 +217,7 @@
end

it "should fail gracefully on invalid URL retrieval or timeouts" do
Net::HTTP.expects(:get).with(URI.parse("http://config.example.com")).raises(Timeout::Error)
Net::HTTP.any_instance.stubs(:request).raises(Timeout::Error)
course_with_teacher_logged_in(:active_all => true)
xml = "bob"
post 'create', :course_id => @course.id, :external_tool => {:name => "tool name", :url => "http://example.com", :consumer_key => "key", :shared_secret => "secret", :config_type => "by_url", :config_url => "http://config.example.com"}
Expand Down

0 comments on commit 5e500c6

Please sign in to comment.