From 8019b2c487e8cdf71e40cb78d9d77bbbff6850b9 Mon Sep 17 00:00:00 2001 From: Jerry Aldrich Date: Wed, 12 Dec 2018 10:05:51 -0800 Subject: [PATCH] Modify URL fetcher to accept URI (#3633) Signed-off-by: Jerry Aldrich --- lib/fetchers/url.rb | 6 ++++-- test/unit/fetchers/url_test.rb | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/fetchers/url.rb b/lib/fetchers/url.rb index 18e30fcfd..d90b3b7e2 100644 --- a/lib/fetchers/url.rb +++ b/lib/fetchers/url.rb @@ -24,6 +24,8 @@ module Fetchers resolve_from_string(target[:url], opts, target[:username], target[:password]) elsif target.is_a?(String) resolve_from_string(target, opts) + elsif target.is_a?(URI) + resolve_from_string(target.to_s, opts) end end @@ -94,8 +96,8 @@ module Fetchers attr_reader :files, :archive_path def initialize(url, opts) - @target = url - @target_uri = parse_uri(@target) + @target = url.to_s + @target_uri = url.is_a?(URI) ? url : parse_uri(url) @insecure = opts['insecure'] @token = opts['token'] @config = opts diff --git a/test/unit/fetchers/url_test.rb b/test/unit/fetchers/url_test.rb index 807e2a351..90194d784 100644 --- a/test/unit/fetchers/url_test.rb +++ b/test/unit/fetchers/url_test.rb @@ -34,7 +34,14 @@ describe Fetchers::Url do res.expects(:open).returns(mock_open) _(res).must_be_kind_of Fetchers::Url _(res.resolved_source).must_equal({url: 'https://chef.io/some.tar.gz', sha256: expected_shasum}) + end + it 'handles an https URI' do + uri = URI.parse('https://chef.io/some.tar.gz') + res = Fetchers::Url.resolve(uri) + res.expects(:open).returns(mock_open) + _(res).must_be_kind_of Fetchers::Url + _(res.resolved_source).must_equal({url: 'https://chef.io/some.tar.gz', sha256: expected_shasum}) end it 'doesnt handle other schemas' do