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

Update Audit cookbook to support ChefClient 14 #313

Merged
merged 3 commits into from Apr 19, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .kitchen.yml
@@ -1,7 +1,6 @@
---
driver:
name: dokken
chef_version: 13.8.5
privileged: true # because Docker and SystemD/Upstart

transport:
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

gem 'chef', '>= 12.5.1', '<14.0.0'
gem 'chef', '>= 12.5.1'

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2')
gem 'json', '~> 1.8'
Expand All @@ -25,7 +25,7 @@ end

group :integration do
gem 'test-kitchen', '~> 1.16'
gem 'kitchen-dokken'
gem 'kitchen-dokken', '= 2.6.0'
gem 'kitchen-ec2', '~> 1.2'
gem 'kitchen-inspec', '~> 0.18'
end
Expand Down
2 changes: 1 addition & 1 deletion resources/inspec_gem.rb
Expand Up @@ -28,7 +28,7 @@

if installation_required
converge_by 'install latest InSpec version' do
install_inspec_gem(version: version, source: source)
install_inspec_gem(version: new_resource.version, source: new_resource.source)
end
else
Chef::Log.info("inspec_gem: not installing InSpec. It's already installed or an explicit version was not supplied.")
Expand Down
12 changes: 9 additions & 3 deletions test/integration/chef-node-disabled/default.rb
@@ -1,9 +1,15 @@
# get most recent json-file output
json_file = command('ls -t /opt/kitchen/cache/cookbooks/audit/inspec-*.json').stdout.lines.first.chomp
controls = json(json_file).controls
controls = json(json_file).profiles.first['controls']
results = []
controls.each do |c|
c['results'].each do |r|
results << r
end
end

# the controls that read from chef_node should fail because the chef_node data should not be present
cpu_key_control = controls.find { |x| x['code_desc'] == 'Chef node data - cpu key should exist'}
cpu_key_control = results.find { |x| x['code_desc'] == 'Chef node data - cpu key should exist'}
cpu_key_control = {} if cpu_key_control.nil?

describe 'cpu_key control' do
Expand All @@ -12,7 +18,7 @@
end
end

chef_environment_control = controls.find { |x| x['code_desc'] == 'Chef node data - chef_environment should exist'}
chef_environment_control = results.find { |x| x['code_desc'] == 'Chef node data - chef_environment should exist'}
chef_environment_control = {} if chef_environment_control.nil?

describe 'chef_environment control' do
Expand Down
12 changes: 9 additions & 3 deletions test/integration/chef-node-enabled/default.rb
@@ -1,9 +1,15 @@
# get most recent json-file output
json_file = command('ls -t /opt/kitchen/cache/cookbooks/audit/inspec-*.json').stdout.lines.first.chomp
controls = json(json_file).controls
controls = json(json_file).profiles.first['controls']
results = []
controls.each do |c|
c['results'].each do |r|
results << r
end
end

# Test ability to read in Chef node attributes when the chef_node attribute is enabled
cpu_key_control = controls.find { |x| x['code_desc'] == 'Chef node data - cpu key should exist'}
cpu_key_control = results.find { |x| x['code_desc'] == 'Chef node data - cpu key should exist'}
cpu_key_control = {} if cpu_key_control.nil?

describe 'cpu_key control' do
Expand All @@ -12,7 +18,7 @@
end
end

chef_environment_control = controls.find { |x| x['code_desc'] == 'Chef node data - chef_environment should exist'}
chef_environment_control = results.find { |x| x['code_desc'] == 'Chef node data - chef_environment should exist'}
chef_environment_control = {} if chef_environment_control.nil?

describe 'chef_environment control' do
Expand Down
12 changes: 9 additions & 3 deletions test/integration/inspec-attributes/default.rb
@@ -1,9 +1,15 @@
# get most recent json-file output
json_file = command('ls -t /opt/kitchen/cache/cookbooks/audit/inspec-*.json').stdout.lines.first.chomp

# Ensure the control we expect is present and passed
controls = json(json_file).controls
attribute_control = controls.find { |x| x['code_desc'] == 'File /opt/kitchen/cache/attribute-file-exists.test should exist'}
# ensure the control we expect is present and passed
controls = json(json_file).profiles.first['controls']
results = []
controls.each do |c|
c['results'].each do |r|
results << r
end
end
attribute_control = results.find { |x| x['code_desc'] == 'File /opt/kitchen/cache/attribute-file-exists.test should exist'}
attribute_control = {} if attribute_control.nil?

describe 'attribute control' do
Expand Down