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

Serverspec to InSpec migration #460

Merged
merged 8 commits into from
Feb 12, 2017
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
3 changes: 3 additions & 0 deletions .kitchen.cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ provisioner:
name: chef_zero
require_chef_omnibus: 11.12.8

verifier:
name: inspec

platforms:
- name: centos-5.8
driver_plugin: digitalocean
Expand Down
7 changes: 5 additions & 2 deletions .kitchen.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ driver:
privileged: true
use_sudo: false

provisioner:
data_path: test/fixtures
verifier:
name: inspec

platforms:
- name: centos-7.2
Expand Down Expand Up @@ -82,6 +82,9 @@ suites:
# - recipe[apache2_test::mod_proxy_ajp]
- recipe[apache2_test::mod_python]
- recipe[apache2_test::mod_ssl]
verifier:
inspec_tests:
- test/integration/default/inspec/localhost
- name: worker
includes: [
'centos-7.2'
Expand Down
7 changes: 6 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ driver:

provisioner:
name: chef_zero
data_path: test/fixtures

verifier:
name: inspec

platforms:
- name: centos-7.2
Expand Down Expand Up @@ -80,6 +82,9 @@ suites:
# - recipe[apache2_test::mod_proxy_ajp]
- recipe[apache2_test::mod_python]
- recipe[apache2_test::mod_ssl]
verifier:
inspec_tests:
- test/integration/default/inspec/localhost
- name: worker
includes: [
'centos-7.2',
Expand Down
2 changes: 1 addition & 1 deletion Berksfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ group :integration do
cookbook 'zypper', '~> 0.3.0'
end

cookbook 'apache2_test', :path => 'test/fixtures/cookbooks/apache2_test'
cookbook 'apache2_test', :path => 'test/cookbooks/apache2_test'
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ group :integration do
gem 'kitchen-ec2', :require => false
gem 'kitchen-vagrant', '~> 0.20', :require => false
gem 'test-kitchen', '~> 1.13.2'
gem 'kitchen-inspec'
end
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace :style do
FoodCritic::Rake::LintTask.new(:chef) do |t|
t.options = {
fail_tags: ['any'],
progress: true
progress: true,
}
end
rescue LoadError => e
Expand Down
2 changes: 1 addition & 1 deletion attributes/mod_auth_openid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
when 'freebsd'
[
'CPPFLAGS=-I/usr/local/include',
'LDFLAGS=-I/usr/local/lib -lsqlite3'
'LDFLAGS=-I/usr/local/lib -lsqlite3',
]
else
[]
Expand Down
2 changes: 1 addition & 1 deletion spec/support/platform_properties.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'json'

def load_platform_properties(args)
JSON.parse(IO.read(File.join(File.dirname(__FILE__), "/../../test/fixtures/platforms/#{args[:platform]}/#{args[:platform_version]}.json")), :symbolize_names => true)
JSON.parse(IO.read(File.join(File.dirname(__FILE__), "/../../test/integration/default/inspec/localhost/files/platforms/#{args[:platform]}/#{args[:platform_version]}.json")), :symbolize_names => true)
end
2 changes: 1 addition & 1 deletion spec/support/supported_platforms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def supported_platforms
'redhat' => ['7.2'],
'centos' => ['7.2.1511'],
'freebsd' => ['10.3'],
'opensuse' => ['13.2']
'opensuse' => ['13.2'],
}
end
67 changes: 0 additions & 67 deletions test/fixtures/serverspec_helper.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
require "#{ENV['BUSSER_ROOT']}/../kitchen/data/serverspec_helper"

# read platform information, see https://github.com/chef/inspec/issues/1396
property = apache_info(File.dirname(__FILE__))

describe 'apache2::default' do

Expand All @@ -28,34 +30,34 @@

it "directory #{property[:apache][:dir]} exists and is mode 755" do
expect(file(property[:apache][:dir])).to be_directory
expect(file(property[:apache][:dir])).to be_mode 755
expect(file(property[:apache][:dir])).to be_mode 0755
end

%w(sites-enabled sites-available mods-enabled mods-available conf-available conf-enabled).each do |dir|
it "directory #{property[:apache][:dir]}/#{dir} exists and is mode 755" do
expect(file("#{property[:apache][:dir]}/#{dir}")).to be_directory
expect(file("#{property[:apache][:dir]}/#{dir}")).to be_mode 755
expect(file("#{property[:apache][:dir]}/#{dir}")).to be_mode 0755
end
end

it "log dir #{property[:apache][:log_dir]} exists and is mode 755" do
expect(file(property[:apache][:log_dir])).to be_directory
expect(file(property[:apache][:log_dir])).to be_mode 755
expect(file(property[:apache][:log_dir])).to be_mode 0755
end

it "lib dir #{property[:apache][:lib_dir]} exists and is mode 755" do
expect(file(property[:apache][:lib_dir])).to be_directory
expect(file(property[:apache][:lib_dir])).to be_mode 755
expect(file(property[:apache][:lib_dir])).to be_mode 0755
end

it "docroot dir #{property[:apache][:docroot_dir]} exists and is mode 755" do
expect(file(property[:apache][:docroot_dir])).to be_directory
expect(file(property[:apache][:docroot_dir])).to be_mode 755
expect(file(property[:apache][:docroot_dir])).to be_mode 0755
end

it "cgi-bin dir #{property[:apache][:cgibin_dir]} exists and is mode 755" do
expect(file(property[:apache][:cgibin_dir])).to be_directory
expect(file(property[:apache][:cgibin_dir])).to be_mode 755
expect(file(property[:apache][:cgibin_dir])).to be_mode 0755
end

it "default site #{property[:apache][:dir]}/sites-available/default is a file" do
Expand All @@ -66,7 +68,7 @@
end
end

it file("#{property[:apache][:dir]}/sites-enabled/000-default.conf") do
it "#{property[:apache][:dir]}/sites-enabled/000-default.conf" do
if property[:apache][:default_site_enabled]
expect(file("#{property[:apache][:dir]}/sites-enabled/000-default.conf")).to be_linked_to "#{property[:apache][:dir]}/sites-available/default.conf"
else
Expand All @@ -86,7 +88,7 @@
end

it "listening on port 80 is defined in #{property[:apache][:dir]}/ports.conf" do
expect(file("#{property[:apache][:dir]}/ports.conf")).to contain(/^Listen .*[: ]80$/)
expect(file("#{property[:apache][:dir]}/ports.conf").content).to match(/^Listen .*[: ]80$/)
end

# it 'only listens on port 443 when SSL is enabled' do
Expand All @@ -109,15 +111,18 @@
subject(:config) { file(property[:apache][:conf]) }
it "#{property[:apache][:conf]} is the config file dropped by the cookbook" do
expect(config).to be_file
expect(config).to contain '# Generated by Chef'
expect(config).to contain %Q(ServerRoot "#{property[:apache][:dir]}")
expect(config.content).to include '# Generated by Chef'
expect(config.content).to include %Q(ServerRoot "#{property[:apache][:dir]}")
expect(config.content).to include 'AccessFileName .htaccess'
expect(config.content).to include 'Files ~ "^\.ht"'
expect(config.content).to include 'LogLevel warn'
if property[:apache][:version] == '2.4'
expect(config).to contain "IncludeOptional #{property[:apache][:dir]}/conf-enabled/*.conf"
expect(config).to_not contain "Include #{property[:apache][:dir]}/conf.d/*.conf"
expect(config.content).to include "IncludeOptional #{property[:apache][:dir]}/conf-enabled/*.conf"
expect(config.content).to_not include "Include #{property[:apache][:dir]}/conf.d/*.conf"
else
expect(config).to contain "Include #{property[:apache][:dir]}/conf-enabled/*.conf"
expect(config).to_not contain "Include #{property[:apache][:dir]}/conf.d/*.conf"
expect(config).to_not contain "IncludeOptional #{property[:apache][:dir]}/conf-enabled/*.conf"
expect(config.content).to include "Include #{property[:apache][:dir]}/conf-enabled/*.conf"
expect(config.content).to_not include "Include #{property[:apache][:dir]}/conf.d/*.conf"
expect(config.content).to_not include "IncludeOptional #{property[:apache][:dir]}/conf-enabled/*.conf"
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
require "#{ENV['BUSSER_ROOT']}/../kitchen/data/serverspec_helper"

describe 'apache2::mod_cgi', :if => property[:apache][:mpm] == 'prefork' do
# read platform information, see https://github.com/chef/inspec/issues/1396
property = apache_info(File.dirname(__FILE__))

describe 'apache2::mod_cgi' do
expected_module = 'cgi'
subject(:available) { file("#{property[:apache][:dir]}/mods-available/#{expected_module}.load") }
it "mods-available/#{expected_module}.load is accurate" do
expect(available).to be_file
expect(available).to be_mode 644
expect(available).to be_mode 0644
expect(available.content).to match "LoadModule #{expected_module}_module #{property[:apache][:libexec_dir]}/mod_#{expected_module}.so\n"
end

subject(:enabled) { file("#{property[:apache][:dir]}/mods-enabled/#{expected_module}.load") }
it "mods-enabled/#{expected_module}.load is a symlink to mods-available/#{expected_module}.load" do
expect(enabled).to be_linked_to("../mods-available/#{expected_module}.load")
expect(enabled).to be_linked_to("#{property[:apache][:dir]}/mods-available/#{expected_module}.load")
end

subject(:loaded_modules) { command("APACHE_LOG_DIR=#{property[:apache][:log_dir]} #{property[:apache][:binary]} -M") }
it "#{expected_module} is loaded" do
expect(loaded_modules.exit_status).to eq 0
expect(loaded_modules.stdout).to match(/#{expected_module}_module/)
end
end
end if property[:apache][:mpm] == 'prefork'
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
require "#{ENV['BUSSER_ROOT']}/../kitchen/data/serverspec_helper"

describe 'apache2::mod_cgid', :unless => property[:apache][:mpm] == 'prefork' do
# read platform information, see https://github.com/chef/inspec/issues/1396
property = apache_info(File.dirname(__FILE__))

describe 'apache2::mod_cgid' do
expected_module = 'cgid'
subject(:available) { file("#{property[:apache][:dir]}/mods-available/#{expected_module}.load") }
it "mods-available/#{expected_module}.load is accurate" do
expect(available).to be_file
expect(available).to be_mode 644
expect(available).to be_mode 0644
expect(available.content).to match "LoadModule #{expected_module}_module #{property[:apache][:libexec_dir]}/mod_#{expected_module}.so\n"
end

subject(:enabled) { file("#{property[:apache][:dir]}/mods-enabled/#{expected_module}.load") }
it "mods-enabled/#{expected_module}.load is a symlink to mods-available/#{expected_module}.load" do
expect(enabled).to be_linked_to("../mods-available/#{expected_module}.load")
expect(enabled).to be_linked_to("#{property[:apache][:dir]}/mods-available/#{expected_module}.load")
end

subject(:loaded_modules) { command("APACHE_LOG_DIR=#{property[:apache][:log_dir]} #{property[:apache][:binary]} -M") }
it "#{expected_module} is loaded" do
expect(loaded_modules.exit_status).to eq 0
expect(loaded_modules.stdout).to match(/#{expected_module}_module/)
end
end
end unless property[:apache][:mpm] == 'prefork'
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
require "#{ENV['BUSSER_ROOT']}/../kitchen/data/serverspec_helper"

# read platform information, see https://github.com/chef/inspec/issues/1396
property = apache_info(File.dirname(__FILE__))

describe 'apache2::mod_fastcgi' do
expected_module = 'fastcgi'
subject(:available) { file("#{property[:apache][:dir]}/mods-available/#{expected_module}.load") }
xit "mods-available/#{expected_module}.load is accurate" do
expect(available).to be_file
expect(available).to be_mode 644
expect(available).to be_mode 0644
expect(available.content).to match "LoadModule #{expected_module}_module #{property[:apache][:libexec_dir]}/mod_#{expected_module}.so\n"
end

subject(:enabled) { file("#{property[:apache][:dir]}/mods-enabled/#{expected_module}.load") }
xit "mods-enabled/#{expected_module}.load is a symlink to mods-available/#{expected_module}.load" do
expect(enabled).to be_linked_to("../mods-available/#{expected_module}.load")
expect(enabled).to be_linked_to("#{property[:apache][:dir]}/mods-available/#{expected_module}.load")
end

subject(:loaded_modules) { command("APACHE_LOG_DIR=#{property[:apache][:log_dir]} #{property[:apache][:binary]} -M") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
require "#{ENV['BUSSER_ROOT']}/../kitchen/data/serverspec_helper"

# read platform information, see https://github.com/chef/inspec/issues/1396
property = apache_info(File.dirname(__FILE__))

describe 'apache2::mod_include' do
expected_module = 'include'
subject(:available) { file("#{property[:apache][:dir]}/mods-available/#{expected_module}.load") }
it "mods-available/#{expected_module}.load is accurate" do
expect(available).to be_file
expect(available).to be_mode 644
expect(available).to be_mode 0644
expect(available.content).to match "LoadModule #{expected_module}_module #{property[:apache][:libexec_dir]}/mod_#{expected_module}.so\n"
end

subject(:enabled) { file("#{property[:apache][:dir]}/mods-enabled/#{expected_module}.load") }
it "mods-enabled/#{expected_module}.load is a symlink to mods-available/#{expected_module}.load" do
expect(enabled).to be_linked_to("../mods-available/#{expected_module}.load")
expect(enabled).to be_linked_to("#{property[:apache][:dir]}/mods-available/#{expected_module}.load")
end

subject(:loaded_modules) { command("APACHE_LOG_DIR=#{property[:apache][:log_dir]} #{property[:apache][:binary]} -M") }
Expand All @@ -38,7 +40,7 @@
subject(:configfile) { file("#{property[:apache][:dir]}/mods-enabled/#{expected_module}.conf") }
it "mods-enabled/#{expected_module}.conf adds .shtml handlers" do
expect(configfile).to be_file
expect(configfile).to contain(/AddType text\/html .shtml/)
expect(configfile).to contain(/AddOutputFilter INCLUDES .shtml/)
expect(configfile.content).to match(/AddType text\/html .shtml/)
expect(configfile.content).to match(/AddOutputFilter INCLUDES .shtml/)
end
end
Loading