Skip to content

Commit

Permalink
Changes based on feedback
Browse files Browse the repository at this point in the history
Update tests to pass travs

Signed-off-by: Alex Pop <[email protected]>
  • Loading branch information
Alex Pop authored and alexpop committed Mar 2, 2020
1 parent 1b54436 commit 2174881
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 63 deletions.
33 changes: 15 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,62 +28,59 @@ before_install:
- CHEF_LICENSE="accept-no-persist" sudo chef gem install webmock
- eval "$(chef shell-init bash)"
- chef --version
- cookstyle --version
- foodcritic --version
- kitchen --version
- kitchen list

matrix:
include:
# Run the style, unit and chefspec tests
- rvm: 2.6.3
- rvm: 2.6.5
script: rake
# Run integration tests with test-kitchen
- rvm: 2.6.3
- rvm: 2.6.5
script: rake $SUITE
env: SUITE=test:integration OS='default-centos-7'
- rvm: 2.6.3
- rvm: 2.6.5
script: rake $SUITE
env: SUITE=test:integration OS='default-ubuntu-1804'
- rvm: 2.6.3
- rvm: 2.6.5
script: rake $SUITE
env: SUITE=test:integration OS='missing-profile-no-fail-ubuntu-1804'
- rvm: 2.6.3
- rvm: 2.6.5
script: rake $SUITE && exit 1 || echo "OK"
env: SUITE=test:integration OS='missing-profile-fail-ubuntu-1804'

# Next 5 suites are disabled due to an issue with the gem() inspec resource
# see https://github.com/chef-cookbooks/audit/issues/406
#
# - rvm: 2.6.3
# - rvm: 2.6.5
# script: rake $SUITE
# env: SUITE=test:integration OS='chef15-compatible-inspec-ubuntu-1804'
# Next 4 suites test running inspec 3 or 4 on audit cookbook. This is only permitted on chef 14 or older.
# - rvm: 2.6.3
# - rvm: 2.6.5
# script: rake $SUITE
# env: SUITE=test:integration OS='gem-install-core-version4-centos-7' CHEF_VERSION=14
# - rvm: 2.6.3
# - rvm: 2.6.5
# script: rake $SUITE
# env: SUITE=test:integration OS='gem-install-core-version3-centos-7' CHEF_VERSION=14
# - rvm: 2.6.3
# - rvm: 2.6.5
# script: rake $SUITE
# env: SUITE=test:integration OS='gem-install-core-version4-ubuntu-1804' CHEF_VERSION=14
# - rvm: 2.6.3
# - rvm: 2.6.5
# script: rake $SUITE
# env: SUITE=test:integration OS='gem-install-core-version3-ubuntu-1804' CHEF_VERSION=14

- rvm: 2.6.3
- rvm: 2.6.5
script: rake $SUITE
env: SUITE=test:integration OS='inspec-attributes-ubuntu-1804'
- rvm: 2.6.3
- rvm: 2.6.5
script: rake $SUITE
env: SUITE=test:integration OS='chef-node-enabled-ubuntu-1804'
- rvm: 2.6.3
- rvm: 2.6.5
script: rake $SUITE
env: SUITE=test:integration OS='chef-node-disabled-ubuntu-1804'
- rvm: 2.6.3
- rvm: 2.6.5
script: rake $SUITE
env: SUITE=test:integration OS='hash-centos-7'
- rvm: 2.6.3
- rvm: 2.6.5
script: rake $SUITE
env: SUITE=test:integration OS='hash-ubuntu-1804'
4 changes: 4 additions & 0 deletions libraries/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ def load_audit_handler
# taking node['audit'] as parameter so that it can be called from the chef-server fetcher as well
# audit['collector'] is the legacy reporter,
def get_reporters(audit)
if audit.nil?
Chef::Log.warn("node ['audit'] is not defined")
return []
end
if audit['collector']
Chef::Log.warn("node ['audit']['collector'] is deprecated and will be removed from the next major version of the cookbook. Please use node ['audit']['reporter']")
return handle_reporters(audit['collector'])
Expand Down
3 changes: 0 additions & 3 deletions libraries/matchers.rb

This file was deleted.

2 changes: 1 addition & 1 deletion spec/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
describe 'audit::default' do
context 'When all attributes are default, on an unspecified platform' do
let(:chef_run) do
runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '14.04')
runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '18.04')
runner.converge(described_recipe)
end

Expand Down
6 changes: 3 additions & 3 deletions spec/unit/report/fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@
},
'profile' => ['admin', 'linux-baseline', '2.0'],
}

Fetchers::Url.new('non_profile_url', config).send(:http_opts)
mynode.default['audit']['reporter'] = 'chef-server'
ChefServer::Fetcher.target_url('non_profile_url', config).read
}
expect { myproc.call }.to raise_error(RuntimeError)
expect { myproc.call }.to raise_error(Errno::ECONNREFUSED)
end
end
end
20 changes: 12 additions & 8 deletions test/cookbooks/test_helper/recipes/force_inspec_core.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
chef_gem 'inspec-core' do
action :nothing
end.run_action(:remove)
compile_time true
action :remove
end

chef_gem 'inspec-core-bin' do
action :nothing
end.run_action(:remove)
compile_time true
action :remove
end

chef_gem 'inspec' do
action :nothing
end.run_action(:remove)
compile_time true
action :remove
end

chef_gem 'inspec-core' do
compile_time true
version '4.3.2'
action :nothing
end.run_action(:install)
action :install
end
20 changes: 12 additions & 8 deletions test/cookbooks/test_helper/recipes/install_inspec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
chef_gem 'inspec-core' do
action :nothing
end.run_action(:remove)
compile_time true
action :remove
end

chef_gem 'inspec-core-bin' do
action :nothing
end.run_action(:remove)
compile_time true
action :remove
end

chef_gem 'inspec' do
action :nothing
end.run_action(:remove)
compile_time true
action :remove
end

chef_gem 'inspec' do
compile_time true
version '1.19.1'
action :nothing
end.run_action(:install)
action :install
end
15 changes: 4 additions & 11 deletions test/cookbooks/test_helper/recipes/setup_waiver_fixture.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@

[
"controls",
"waivers",
].each do |subdir|
directory "#{node["audit"]["profiles"]["waiver-test-profile"]["path"]}/#{subdir}" do
%w(controls waivers).each do |subdir|
directory "#{node['audit']['profiles']['waiver-test-profile']['path']}/#{subdir}" do
recursive true
end
end

[
"inspec.yml",
"controls/waiver-check.rb",
"waivers/waivers.yaml",
].each do |file|
cookbook_file "#{node["audit"]["profiles"]["waiver-test-profile"]["path"]}/#{file}" do
%w(inspec.yml controls/waiver-check.rb waivers/waivers.yaml).each do |file|
cookbook_file "#{node['audit']['profiles']['waiver-test-profile']['path']}/#{file}" do
source "waivers-fixture/#{file}"
end
end
2 changes: 1 addition & 1 deletion test/integration/inspec-attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
results << r
end
end
attribute_control = results.find { |x| x['code_desc'] == 'File /opt/kitchen/cache/attribute-file-exists.test should exist' }
attribute_control = results.find { |x| x['code_desc'] == 'File /opt/kitchen/cache/attribute-file-exists.test is expected to exist' }
attribute_control = {} if attribute_control.nil?

describe 'attribute control' do
Expand Down
8 changes: 4 additions & 4 deletions test/integration/waivers/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# The test fixture has two controls - the first should pass,
# the second should be a skip with a waiver justification

control "the unwaivered control" do
control 'the unwaivered control' do
describe controls[0]['results'][0]['status'] do
it { should cmp "passed" }
it { should cmp 'passed' }
end
end

control "the waivered control" do
control 'the waivered control' do
describe controls[1]['results'][0]['status'] do
it { should cmp "skipped" }
it { should cmp 'skipped' }
end
end
6 changes: 3 additions & 3 deletions test/kitchen-automate/recipes/bootstrap_localhost.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
end

# Ensure the node is in the expected state
raise 'Cannot find /tmp/kitchen/client.pem' unless File.exist?('/tmp/kitchen/client.pem')
raise 'Cannot find /home/ec2-user/.ssh/authorized_keys' unless File.exist?('/home/ec2-user/.ssh/authorized_keys')
raise 'Cannot find /tmp/kitchen/client.pem' unless ::File.exist?('/tmp/kitchen/client.pem')
raise 'Cannot find /home/ec2-user/.ssh/authorized_keys' unless ::File.exist?('/home/ec2-user/.ssh/authorized_keys')

# Add a public key to be used for SSH bootstrapping
execute 'Add SSH public key to be used by self bootstrapping' do
Expand All @@ -49,5 +49,5 @@
EOH
live_stream true
action :run
not_if { File.exist?('/etc/chef/client.pem') }
not_if { ::File.exist?('/etc/chef/client.pem') }
end
2 changes: 1 addition & 1 deletion test/kitchen-automate/recipes/configure_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
touch /etc/opscode/chef-server-reconfigured.txt
EOH
action :run
not_if { File.exist?('/etc/opscode/chef-server-reconfigured.txt') }
not_if { ::File.exist?('/etc/opscode/chef-server-reconfigured.txt') }
end
4 changes: 2 additions & 2 deletions test/kitchen-automate/recipes/converge_localhost.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
EOH
live_stream true
action :run
only_if { File.exist?('/etc/chef/client.pem') }
only_if { ::File.exist?('/etc/chef/client.pem') }
end

# Create the attributes file to test the 'chef-visibility' collector
Expand Down Expand Up @@ -91,5 +91,5 @@
EOH
live_stream true
action :run
only_if { File.exist?('/etc/chef/client.pem') }
only_if { ::File.exist?('/etc/chef/client.pem') }
end

0 comments on commit 2174881

Please sign in to comment.