mirror of
https://github.com/inspec/inspec
synced 2024-12-25 12:33:25 +00:00
88581ae3dd
When attempting to parse the profile out of the target URL, we were not raising an exception if we failed to do so. Such a situation could arise if a user's inspec config.json is incorrect either due to manual editing or failure to re-login after an upgrade past Automate 0.8.0. This change provides a clear exception if this occurs and also adds tests for the compliance_profile_name method. Signed-off-by: Adam Leff <adam@leff.co>
53 lines
2.1 KiB
Ruby
53 lines
2.1 KiB
Ruby
require 'helper'
|
|
|
|
describe Compliance::Fetcher do
|
|
let(:config) { { 'server' => 'myserver' } }
|
|
|
|
describe 'when the server is an automate server pre-0.8.0' do
|
|
before { Compliance::API.expects(:is_automate_server_pre_080?).with(config).returns(true) }
|
|
|
|
it 'returns the correct profile name when the url is correct' do
|
|
fetcher = Compliance::Fetcher.new('myserver/myowner/myprofile/tar', config)
|
|
fetcher.send(:compliance_profile_name).must_equal 'myowner/myprofile'
|
|
end
|
|
|
|
it 'raises an exception if the url is malformed' do
|
|
fetcher = Compliance::Fetcher.new('a/bad/url', config)
|
|
proc { fetcher.send(:compliance_profile_name) }.must_raise RuntimeError
|
|
end
|
|
end
|
|
|
|
describe 'when the server is an automate server 0.8.0-or-later' do
|
|
before do
|
|
Compliance::API.expects(:is_automate_server_pre_080?).with(config).returns(false)
|
|
Compliance::API.expects(:is_automate_server_080_and_later?).with(config).returns(true)
|
|
end
|
|
|
|
it 'returns the correct profile name when the url is correct' do
|
|
fetcher = Compliance::Fetcher.new('myserver/profiles/myowner/myprofile/tar', config)
|
|
fetcher.send(:compliance_profile_name).must_equal 'myowner/myprofile'
|
|
end
|
|
|
|
it 'raises an exception if the url is malformed' do
|
|
fetcher = Compliance::Fetcher.new('a/bad/url', config)
|
|
proc { fetcher.send(:compliance_profile_name) }.must_raise RuntimeError
|
|
end
|
|
end
|
|
|
|
describe 'when the server is not an automate server (likely a compliance server)' do
|
|
before do
|
|
Compliance::API.expects(:is_automate_server_pre_080?).with(config).returns(false)
|
|
Compliance::API.expects(:is_automate_server_080_and_later?).with(config).returns(false)
|
|
end
|
|
|
|
it 'returns the correct profile name when the url is correct' do
|
|
fetcher = Compliance::Fetcher.new('myserver/owners/myowner/compliance/myprofile/tar', config)
|
|
fetcher.send(:compliance_profile_name).must_equal 'myowner/myprofile'
|
|
end
|
|
|
|
it 'raises an exception if the url is malformed' do
|
|
fetcher = Compliance::Fetcher.new('a/bad/url', config)
|
|
proc { fetcher.send(:compliance_profile_name) }.must_raise RuntimeError
|
|
end
|
|
end
|
|
end
|