From add0c23e007e296eb875830c5af02e037ace50f3 Mon Sep 17 00:00:00 2001 From: NAshwini Date: Tue, 26 Jun 2018 17:18:25 +0530 Subject: [PATCH 1/2] Fix nil class error when profile not found on automate server Signed-off-by: NAshwini --- files/default/vendor/chef-server/fetcher.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/files/default/vendor/chef-server/fetcher.rb b/files/default/vendor/chef-server/fetcher.rb index f341d08d..3d206a83 100644 --- a/files/default/vendor/chef-server/fetcher.rb +++ b/files/default/vendor/chef-server/fetcher.rb @@ -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 From ecafa89a575c3a534e70a44f711d2608f7c6fd59 Mon Sep 17 00:00:00 2001 From: NAshwini Date: Thu, 28 Jun 2018 17:11:19 +0530 Subject: [PATCH 2/2] Add unit spec Signed-off-by: NAshwini --- spec/unit/report/fetcher_spec.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/spec/unit/report/fetcher_spec.rb b/spec/unit/report/fetcher_spec.rb index 0728306d..87ed6b4e 100644 --- a/spec/unit/report/fetcher_spec.rb +++ b/spec/unit/report/fetcher_spec.rb @@ -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 @@ -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