2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
2019-06-07 23:33:56 +00:00
|
|
|
require "inspec/fetcher" # TODO: require fetchers/url directly
|
2016-02-21 03:00:52 +00:00
|
|
|
|
|
|
|
describe Fetchers::Url do
|
2019-06-11 22:24:35 +00:00
|
|
|
it "registers with the fetchers registry" do
|
2016-02-21 03:00:52 +00:00
|
|
|
reg = Inspec::Fetcher.registry
|
2019-06-11 22:24:35 +00:00
|
|
|
_(reg["url"]).must_equal Fetchers::Url
|
2016-02-21 03:00:52 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "testing different urls" do
|
2016-09-20 10:36:23 +00:00
|
|
|
# We don't use the MockLoader here becuase it produces tarballs
|
|
|
|
# with different sha's on each run
|
|
|
|
let(:expected_shasum) { "98b1ae45059b004178a8eee0c1f6179dcea139c0fd8a69ee47a6f02d97af1f17" }
|
2019-06-11 22:24:35 +00:00
|
|
|
let(:mock_open) do
|
2016-09-20 10:36:23 +00:00
|
|
|
m = Minitest::Mock.new
|
2019-06-11 22:24:35 +00:00
|
|
|
m.expect :meta, { "content-type" => "application/gzip" }
|
2016-09-20 10:36:23 +00:00
|
|
|
m.expect :read, "fake content"
|
|
|
|
m
|
2019-06-11 22:24:35 +00:00
|
|
|
end
|
2016-09-20 10:36:23 +00:00
|
|
|
|
2019-02-22 07:20:00 +00:00
|
|
|
def expect_url_transform
|
|
|
|
@mock_logger = Minitest::Mock.new
|
|
|
|
@mock_logger.expect(:warn, nil, [/URL target.*transformed/])
|
|
|
|
|
2019-05-31 21:59:06 +00:00
|
|
|
Inspec::Log.stub :warn, (proc { |message| @mock_logger.warn(message) }) do
|
2019-02-22 07:20:00 +00:00
|
|
|
yield
|
|
|
|
end
|
|
|
|
|
|
|
|
@mock_logger.verify
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "handles a http url" do
|
|
|
|
url = "http://chef.io/some.tar.gz"
|
2017-06-15 16:10:47 +00:00
|
|
|
res = Fetchers::Url.resolve(url)
|
2016-09-20 10:36:23 +00:00
|
|
|
res.expects(:open).returns(mock_open)
|
2016-09-08 09:11:44 +00:00
|
|
|
_(res).must_be_kind_of Fetchers::Url
|
2019-06-11 22:24:35 +00:00
|
|
|
_(res.resolved_source).must_equal({ url: "http://chef.io/some.tar.gz", sha256: expected_shasum })
|
2016-02-21 20:32:56 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "handles a https url" do
|
|
|
|
url = "https://chef.io/some.tar.gz"
|
2017-06-15 16:10:47 +00:00
|
|
|
res = Fetchers::Url.resolve(url)
|
2016-09-20 10:36:23 +00:00
|
|
|
res.expects(:open).returns(mock_open)
|
2016-09-08 09:11:44 +00:00
|
|
|
_(res).must_be_kind_of Fetchers::Url
|
2019-06-11 22:24:35 +00:00
|
|
|
_(res.resolved_source).must_equal({ url: "https://chef.io/some.tar.gz", sha256: expected_shasum })
|
2018-12-12 18:05:51 +00:00
|
|
|
end
|
2016-09-08 09:11:44 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "handles an https URI" do
|
|
|
|
uri = URI.parse("https://chef.io/some.tar.gz")
|
2018-12-12 18:05:51 +00:00
|
|
|
res = Fetchers::Url.resolve(uri)
|
|
|
|
res.expects(:open).returns(mock_open)
|
|
|
|
_(res).must_be_kind_of Fetchers::Url
|
2019-06-11 22:24:35 +00:00
|
|
|
_(res.resolved_source).must_equal({ url: "https://chef.io/some.tar.gz", sha256: expected_shasum })
|
2016-02-21 20:32:56 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "doesnt handle other schemas" do
|
|
|
|
Fetchers::Url.resolve("gopher://chef.io/some.tar.gz").must_be_nil
|
2016-02-21 20:32:56 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "only handles URLs" do
|
2017-06-15 16:10:47 +00:00
|
|
|
Fetchers::Url.resolve(__FILE__).must_be_nil
|
2016-02-21 20:32:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
%w{https://github.com/chef/inspec
|
|
|
|
https://github.com/chef/inspec.git
|
|
|
|
https://www.github.com/chef/inspec.git
|
|
|
|
http://github.com/chef/inspec
|
|
|
|
http://github.com/chef/inspec.git
|
|
|
|
http://www.github.com/chef/inspec.git}.each do |github|
|
2019-07-09 00:20:30 +00:00
|
|
|
it "resolves a github url #{github}" do
|
|
|
|
expect_url_transform do
|
|
|
|
res = Fetchers::Url.resolve(github)
|
|
|
|
res.expects(:open).returns(mock_open)
|
|
|
|
_(res).wont_be_nil
|
|
|
|
_(res.resolved_source).must_equal({ url: "https://github.com/chef/inspec/archive/master.tar.gz", sha256: expected_shasum })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-02-21 20:32:56 +00:00
|
|
|
|
2019-05-18 17:50:39 +00:00
|
|
|
it "resolves a github url with dot" do
|
|
|
|
expect_url_transform do
|
2019-06-11 22:24:35 +00:00
|
|
|
github = "https://github.com/mitre/aws-rds-oracle-mysql-ee-5.7-cis-baseline"
|
2019-05-18 17:50:39 +00:00
|
|
|
res = Fetchers::Url.resolve(github)
|
|
|
|
res.expects(:open).returns(mock_open)
|
|
|
|
_(res).wont_be_nil
|
2019-06-11 22:24:35 +00:00
|
|
|
_(res.resolved_source).must_equal({ url: "https://github.com/mitre/aws-rds-oracle-mysql-ee-5.7-cis-baseline/archive/master.tar.gz", sha256: expected_shasum })
|
2019-05-18 17:50:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-21 20:32:56 +00:00
|
|
|
it "resolves a github branch url" do
|
2019-02-22 07:20:00 +00:00
|
|
|
expect_url_transform do
|
2019-06-11 22:24:35 +00:00
|
|
|
github = "https://github.com/hardening-io/tests-os-hardening/tree/2.0"
|
2019-02-22 07:20:00 +00:00
|
|
|
res = Fetchers::Url.resolve(github)
|
|
|
|
res.expects(:open).returns(mock_open)
|
|
|
|
_(res).wont_be_nil
|
2019-06-11 22:24:35 +00:00
|
|
|
_(res.resolved_source).must_equal({ url: "https://github.com/hardening-io/tests-os-hardening/archive/2.0.tar.gz", sha256: expected_shasum })
|
2019-02-22 07:20:00 +00:00
|
|
|
end
|
2016-02-21 20:32:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "resolves a github commit url" do
|
2019-02-22 07:20:00 +00:00
|
|
|
expect_url_transform do
|
2019-06-11 22:24:35 +00:00
|
|
|
github = "https://github.com/hardening-io/tests-os-hardening/tree/48bd4388ddffde68badd83aefa654e7af3231876"
|
2019-02-22 07:20:00 +00:00
|
|
|
res = Fetchers::Url.resolve(github)
|
|
|
|
res.expects(:open).returns(mock_open)
|
|
|
|
_(res).wont_be_nil
|
2019-06-11 22:24:35 +00:00
|
|
|
_(res.resolved_source).must_equal({ url: "https://github.com/hardening-io/tests-os-hardening/archive/48bd4388ddffde68badd83aefa654e7af3231876.tar.gz",
|
|
|
|
sha256: expected_shasum })
|
2019-02-22 07:20:00 +00:00
|
|
|
end
|
2016-02-21 20:32:56 +00:00
|
|
|
end
|
2017-06-05 14:02:56 +00:00
|
|
|
|
|
|
|
%w{https://bitbucket.org/chef/inspec
|
|
|
|
https://bitbucket.org/chef/inspec.git
|
|
|
|
https://www.bitbucket.org/chef/inspec.git
|
|
|
|
http://bitbucket.org/chef/inspec
|
|
|
|
http://bitbucket.org/chef/inspec.git
|
|
|
|
http://www.bitbucket.org/chef/inspec.git}.each do |bitbucket|
|
2019-07-09 00:20:30 +00:00
|
|
|
it "resolves a bitbucket url #{bitbucket}" do
|
|
|
|
expect_url_transform do
|
|
|
|
res = Fetchers::Url.resolve(bitbucket)
|
|
|
|
res.expects(:open).returns(mock_open)
|
|
|
|
_(res).wont_be_nil
|
|
|
|
_(res.resolved_source).must_equal({ url: "https://bitbucket.org/chef/inspec/get/master.tar.gz", sha256: expected_shasum })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-06-05 14:02:56 +00:00
|
|
|
|
|
|
|
it "resolves a bitbucket branch url" do
|
2019-02-22 07:20:00 +00:00
|
|
|
expect_url_transform do
|
2019-06-11 22:24:35 +00:00
|
|
|
bitbucket = "https://bitbucket.org/chef/inspec/branch/newbranch"
|
2019-02-22 07:20:00 +00:00
|
|
|
res = Fetchers::Url.resolve(bitbucket)
|
|
|
|
res.expects(:open).returns(mock_open)
|
|
|
|
_(res).wont_be_nil
|
2019-06-11 22:24:35 +00:00
|
|
|
_(res.resolved_source).must_equal({ url: "https://bitbucket.org/chef/inspec/get/newbranch.tar.gz", sha256: expected_shasum })
|
2019-02-22 07:20:00 +00:00
|
|
|
end
|
2017-06-05 14:02:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "resolves a bitbucket commit url" do
|
2019-02-22 07:20:00 +00:00
|
|
|
expect_url_transform do
|
2019-06-11 22:24:35 +00:00
|
|
|
bitbucket = "https://bitbucket.org/chef/inspec/commits/48bd4388ddffde68badd83aefa654e7af3231876"
|
2019-02-22 07:20:00 +00:00
|
|
|
res = Fetchers::Url.resolve(bitbucket)
|
|
|
|
res.expects(:open).returns(mock_open)
|
|
|
|
_(res).wont_be_nil
|
2019-06-11 22:24:35 +00:00
|
|
|
_(res.resolved_source).must_equal({ url: "https://bitbucket.org/chef/inspec/get/48bd4388ddffde68badd83aefa654e7af3231876.tar.gz", sha256: expected_shasum })
|
2019-02-22 07:20:00 +00:00
|
|
|
end
|
2017-06-05 14:02:56 +00:00
|
|
|
end
|
|
|
|
|
2016-02-21 20:32:56 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "download_automate2_archive_to_temp" do
|
|
|
|
let(:target) { "https://myurl/file.tar.gz" }
|
2018-05-03 18:07:38 +00:00
|
|
|
let(:options) do
|
|
|
|
{
|
2019-06-11 22:24:35 +00:00
|
|
|
"automate" => {
|
|
|
|
"ent" => "automate",
|
|
|
|
"token_type" => "dctoken",
|
2018-05-03 18:07:38 +00:00
|
|
|
},
|
2019-06-11 22:24:35 +00:00
|
|
|
"token" => "1234abcd",
|
|
|
|
"server_type" => "automate2",
|
|
|
|
"profile" => ["admin", "ssh-baseline", "2.0"],
|
2018-05-03 18:07:38 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:subject) { Fetchers::Url.resolve(target, options) }
|
|
|
|
|
|
|
|
it "downloads tar to tmp file" do
|
|
|
|
mock = Object.new
|
2019-06-11 22:24:35 +00:00
|
|
|
mock.stubs(:body).returns("this is the body")
|
2018-05-03 18:07:38 +00:00
|
|
|
Net::HTTP.expects(:start)
|
2019-07-09 00:20:30 +00:00
|
|
|
.returns(mock)
|
2018-05-03 18:07:38 +00:00
|
|
|
|
|
|
|
path = subject.send(:download_automate2_archive_to_temp)
|
2019-06-11 22:24:35 +00:00
|
|
|
File.read(path).must_equal "this is the body"
|
2018-05-03 18:07:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets default http options" do
|
|
|
|
mock = Object.new
|
2019-06-11 22:24:35 +00:00
|
|
|
mock.stubs(:body).returns("this is the body")
|
|
|
|
opts = { "chef-delivery-enterprise" => "automate", "x-data-collector-token" => "1234abcd", :use_ssl => true, :verify_mode => 1 }
|
2018-05-03 18:07:38 +00:00
|
|
|
Net::HTTP.expects(:start)
|
2019-07-09 00:20:30 +00:00
|
|
|
.with("myurl", 443, opts)
|
|
|
|
.returns(mock)
|
2018-05-03 18:07:38 +00:00
|
|
|
|
|
|
|
subject.send(:download_automate2_archive_to_temp)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets insecure http options" do
|
2019-06-11 22:24:35 +00:00
|
|
|
options["insecure"] = true
|
2018-05-03 18:07:38 +00:00
|
|
|
mock = Object.new
|
2019-06-11 22:24:35 +00:00
|
|
|
mock.stubs(:body).returns("this is the body")
|
|
|
|
opts = { :ssl_verify_mode => 0, "chef-delivery-enterprise" => "automate", "x-data-collector-token" => "1234abcd", :use_ssl => true, :verify_mode => 0 }
|
2018-05-03 18:07:38 +00:00
|
|
|
Net::HTTP.expects(:start)
|
2019-07-09 00:20:30 +00:00
|
|
|
.with("myurl", 443, opts)
|
|
|
|
.returns(mock)
|
2018-05-03 18:07:38 +00:00
|
|
|
|
|
|
|
subject.send(:download_automate2_archive_to_temp)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "applied to a valid url (mocked tar.gz)" do
|
|
|
|
let(:mock_file) { MockLoader.profile_tgz("complete-profile") }
|
|
|
|
let(:target) { "http://myurl/file.tar.gz" }
|
2017-06-15 16:10:47 +00:00
|
|
|
let(:subject) { Fetchers::Url.resolve(target) }
|
2019-06-11 22:24:35 +00:00
|
|
|
let(:mock_open) do
|
2016-09-08 09:11:44 +00:00
|
|
|
m = Minitest::Mock.new
|
2019-06-11 22:24:35 +00:00
|
|
|
m.expect :meta, { "content-type" => "application/gzip" }
|
|
|
|
m.expect :read, File.open(mock_file, "rb").read
|
2016-09-08 09:11:44 +00:00
|
|
|
m
|
2019-06-11 22:24:35 +00:00
|
|
|
end
|
2016-02-21 03:00:52 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
let(:mock_dest) do
|
2016-09-08 09:11:44 +00:00
|
|
|
f = Tempfile.new("url-fetch-test")
|
|
|
|
f.path
|
2019-06-11 22:24:35 +00:00
|
|
|
end
|
2016-02-21 03:00:52 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "tries to fetch the file" do
|
2016-09-08 09:11:44 +00:00
|
|
|
subject.expects(:open).returns(mock_open)
|
|
|
|
subject.fetch(mock_dest)
|
2016-02-21 03:00:52 +00:00
|
|
|
end
|
|
|
|
|
2016-09-08 09:11:44 +00:00
|
|
|
it "returns the resolved_source hash" do
|
2016-09-20 10:36:23 +00:00
|
|
|
subject.expects(:open).returns(mock_open)
|
|
|
|
subject.resolved_source[:url].must_equal(target)
|
2016-02-21 20:32:56 +00:00
|
|
|
end
|
|
|
|
end
|
2017-06-22 00:09:13 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#http_opts" do
|
|
|
|
let(:subject) { Fetchers::Url.new("fake_url", config) }
|
2017-06-22 00:09:13 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when username and password is specified" do
|
|
|
|
let(:config) { { username: "dummy", password: "dummy" } }
|
|
|
|
it "returns a hash containing http_basic_authentication setting" do
|
|
|
|
subject.send(:http_opts)[:http_basic_authentication].must_equal %w{dummy dummy}
|
2018-08-30 16:57:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when only password is specified" do
|
|
|
|
let(:config) { { password: "dummy" } }
|
|
|
|
it "returns a hash containing http_basic_authentication setting as nil" do
|
2019-01-12 05:22:30 +00:00
|
|
|
subject.send(:http_opts)[:http_basic_authentication].must_be_nil
|
2018-08-30 16:57:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when insecure is specified" do
|
|
|
|
let(:config) { { "insecure" => true } }
|
|
|
|
it "returns a hash containing an ssl_verify_mode setting" do
|
2017-06-22 00:09:13 +00:00
|
|
|
subject.send(:http_opts)[:ssl_verify_mode].must_equal OpenSSL::SSL::VERIFY_NONE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when insecure is not specific" do
|
2017-06-22 00:09:13 +00:00
|
|
|
let(:config) { {} }
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns a hash that does not contain an ssl_verify_mode setting" do
|
2017-06-22 00:09:13 +00:00
|
|
|
subject.send(:http_opts).key?(:ssl_verify_mode).must_equal false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the server is an automate server using dctoken" do
|
|
|
|
describe "when the config is properly populated" do
|
2017-06-22 00:09:13 +00:00
|
|
|
let(:config) do
|
|
|
|
{
|
2019-06-11 22:24:35 +00:00
|
|
|
"server_type" => "automate",
|
|
|
|
"automate" => {
|
|
|
|
"ent" => "my_ent",
|
|
|
|
"token_type" => "dctoken",
|
2017-06-22 00:09:13 +00:00
|
|
|
},
|
2019-06-11 22:24:35 +00:00
|
|
|
"token" => "my_token",
|
2017-06-22 00:09:13 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns a properly formatted headers hash" do
|
2017-06-22 00:09:13 +00:00
|
|
|
headers = subject.send(:http_opts)
|
2019-06-11 22:24:35 +00:00
|
|
|
headers["chef-delivery-enterprise"].must_equal "my_ent"
|
|
|
|
headers["x-data-collector-token"].must_equal "my_token"
|
2017-06-22 00:09:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the enterprise is not supplied" do
|
|
|
|
it "raises an exception" do
|
2017-06-22 00:09:13 +00:00
|
|
|
proc {
|
|
|
|
config = {
|
2019-06-11 22:24:35 +00:00
|
|
|
"server_type" => "automate",
|
|
|
|
"automate" => { "token_type" => "dctoken" },
|
|
|
|
"token" => "my_token",
|
2017-06-22 00:09:13 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
Fetchers::Url.new("fake_url", config).send(:http_opts)
|
2017-06-22 00:09:13 +00:00
|
|
|
}.must_raise RuntimeError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the token is not supplied" do
|
|
|
|
it "raises an exception" do
|
2017-06-22 00:09:13 +00:00
|
|
|
proc {
|
|
|
|
config = {
|
2019-06-11 22:24:35 +00:00
|
|
|
"server_type" => "automate",
|
|
|
|
"automate" => {
|
|
|
|
"ent" => "my_ent",
|
|
|
|
"token_type" => "dctoken",
|
2017-06-22 00:09:13 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
Fetchers::Url.new("fake_url", config).send(:http_opts)
|
2017-06-22 00:09:13 +00:00
|
|
|
}.must_raise RuntimeError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the server is an automate server not using dctoken" do
|
|
|
|
describe "when the config is properly populated" do
|
2017-06-22 00:09:13 +00:00
|
|
|
let(:config) do
|
|
|
|
{
|
2019-06-11 22:24:35 +00:00
|
|
|
"server_type" => "automate",
|
|
|
|
"automate" => {
|
|
|
|
"ent" => "my_ent",
|
|
|
|
"token_type" => "usertoken",
|
2017-06-22 00:09:13 +00:00
|
|
|
},
|
2019-06-11 22:24:35 +00:00
|
|
|
"user" => "my_user",
|
|
|
|
"token" => "my_token",
|
2017-06-22 00:09:13 +00:00
|
|
|
}
|
|
|
|
end
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns a properly formatted headers hash" do
|
2017-06-22 00:09:13 +00:00
|
|
|
headers = subject.send(:http_opts)
|
2019-06-11 22:24:35 +00:00
|
|
|
headers["chef-delivery-enterprise"].must_equal "my_ent"
|
|
|
|
headers["chef-delivery-user"].must_equal "my_user"
|
|
|
|
headers["chef-delivery-token"].must_equal "my_token"
|
2017-06-22 00:09:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the user is not supplied" do
|
|
|
|
it "raises an exception" do
|
2017-06-22 00:09:13 +00:00
|
|
|
proc {
|
|
|
|
config = {
|
2019-06-11 22:24:35 +00:00
|
|
|
"server_type" => "automate",
|
|
|
|
"automate" => {
|
|
|
|
"ent" => "my_ent",
|
|
|
|
"token_type" => "usertoken",
|
2017-06-22 00:09:13 +00:00
|
|
|
},
|
2019-06-11 22:24:35 +00:00
|
|
|
"token" => "my_token",
|
2017-06-22 00:09:13 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
Fetchers::Url.new("fake_url", config).send(:http_opts)
|
2017-06-22 00:09:13 +00:00
|
|
|
}.must_raise RuntimeError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when the token is not supplied" do
|
|
|
|
it "raises an exception" do
|
2017-06-22 00:09:13 +00:00
|
|
|
proc {
|
|
|
|
config = {
|
2019-06-11 22:24:35 +00:00
|
|
|
"server_type" => "automate",
|
|
|
|
"automate" => {
|
|
|
|
"ent" => "my_ent",
|
|
|
|
"token_type" => "usertoken",
|
2017-06-22 00:09:13 +00:00
|
|
|
},
|
2019-06-11 22:24:35 +00:00
|
|
|
"user" => "my_user",
|
2017-06-22 00:09:13 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
Fetchers::Url.new("fake_url", config).send(:http_opts)
|
2017-06-22 00:09:13 +00:00
|
|
|
}.must_raise RuntimeError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "when only a token is supplied" do
|
|
|
|
let(:config) { { "token" => "my_token" } }
|
|
|
|
it "returns a hash containing an Authorization header" do
|
|
|
|
subject.send(:http_opts)["Authorization"].must_equal "Bearer my_token"
|
2017-06-22 00:09:13 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-02-21 03:00:52 +00:00
|
|
|
end
|