Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSYS-829] Fix nil class error when profile not found on automate server #321

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions files/default/vendor/chef-server/fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def download_archive_to_temp
rest.streaming_request(@target)
end
@archive_type = '.tar.gz'
raise "Unable to find requested profile on path: '#{@target.path}' on the Automate system." if archive.nil?
Inspec::Log.debug("Archive stored at temporary location: #{archive.path}")
@temp_archive_path = archive.path
end
Expand Down
27 changes: 27 additions & 0 deletions spec/unit/report/fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
let(:profile_hash_target) {
'/organizations/org/owners/user/compliance/linux-baseline/version/2.1.0/tar'
}
let(:non_profile_url){
'http://127.0.0.1:8889/organizations/org/owners/user/compliance/linux-baseline/version/2.1.0/tar'
}

context 'when target is a string' do
before :each do
Expand Down Expand Up @@ -70,4 +73,28 @@
expect(res.target.request_uri).to eq(profile_hash_target)
end
end

context 'when profile not found' do
before :each do
Chef::Config[:verify_api_cert] = false
Chef::Config[:ssl_verify_mode] = :verify_none
allow(Chef).to receive(:node).and_return(mynode)
end

it 'should raise error' do
myproc = proc {
config = {
'server_type' => 'automate',
'automate' => {
'ent' => 'my_ent',
'token_type' => 'dctoken',
},
'profile' => ['admin', 'linux-baseline', '2.0']
}

Fetchers::Url.new('non_profile_url', config).send(:http_opts)
}
expect {myproc.call}.to raise_error(RuntimeError)
end
end
end