Skip to content

Commit 7a91d82

Browse files
committed
Merge pull request #38 from dev-sec/chris-rock/inspec-profile
inspec profile
2 parents 758fbef + 8ff2ada commit 7a91d82

File tree

12 files changed

+94
-350
lines changed

12 files changed

+94
-350
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
sudo: false
2+
language: ruby
23
cache: bundler
34

45
rvm:
56
- 1.9.3
67
- 2.0.0
78
- 2.2.0
8-
language: ruby
9+
10+
bundler_args: --without integration
11+
script: bundle exec rake

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ gem 'rake'
1010
gem 'inspec', '~> 0.9'
1111
gem 'rubocop', '~> 0.23'
1212
gem 'highline', '~> 1.6.0'
13+
14+
# pin dependency for Ruby 1.9.3 since bundler is not
15+
# detecting that net-ssh 3 does not work with 1.9.3
16+
if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('1.9.3')
17+
gem 'net-ssh', '~> 2.9'
18+
end

README.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
11
tests-os-hardening
22
==================
33

4-
This are the integration tests for the projects
4+
This Compliance Profile ensures, that all hardening projects keep the same quality.
55

66
- https://github.com/hardening-io/puppet-os-hardening
77
- https://github.com/hardening-io/chef-os-hardening
88
- https://github.com/hardening-io/ansible-os-hardening
9-
10-
They start at `integration` level.
11-
12-
you can use the gem `kitchen-sharedtests`
13-
14-
- https://github.com/ehaselwanter/kitchen-sharedtests/
15-
16-
to make them available to your project. Use `thor kitchen:fetch-remote-tests` to put the repo into `test/integration`.
179

1810
## Standalone Usage
1911

20-
You can target the integration tests to any host where you have ssh access.
21-
22-
`rake -T` gives you a list of suites you can run (we'll ignore directories which are obviously not suites for now)
12+
This Compliance Profile requires [InSpec](https://github.com/chef/inspec) for execution:
2313

2414
```
25-
± rake -T
26-
rake serverspec:data_bags # Run serverspec suite data_bags
27-
rake serverspec:default # Run serverspec suite default
15+
$ git clone https://github.com/hardening-io/tests-os-hardening
16+
$ inspec exec tests-os-hardening
2817
```
2918

30-
Run it with:
19+
You can also execute the profile directly from Github:
3120

3221
```
33-
bundle install
22+
$ inspec exec https://github.com/hardening-io/tests-os-hardening
23+
```
3424

35-
# default user and ssh-key
25+
## License and Author
3626

37-
bundle exec rake serverspec:default target_host=<name-or-ip-of-target-server>
27+
* Author:: Patrick Muench <patrick.meier111@googlemail.com>
28+
* Author:: Dominik Richter <dominik.richter@googlemail.com>
29+
* Author:: Christoph Hartmann <chris@lollyrock.com>
30+
* Author:: Edmund Haselwanter <me@ehaselwanter.com>
3831

39-
# or with user, host, password
32+
* Copyright 2014-2016, The Hardening Framework Team
4033

41-
ASK_LOGIN_PASSWORD=true bundle exec rake serverspec:default target_host=192.168.1.222 user=stack
42-
```
34+
Licensed under the Apache License, Version 2.0 (the "License");
35+
you may not use this file except in compliance with the License.
36+
You may obtain a copy of the License at
4337

44-
Add `format=html|json` to get a report.html or report.json document.
38+
http://www.apache.org/licenses/LICENSE-2.0
4539

40+
Unless required by applicable law or agreed to in writing, software
41+
distributed under the License is distributed on an "AS IS" BASIS,
42+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43+
See the License for the specific language governing permissions and
44+
limitations under the License.

Rakefile

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
#!/usr/bin/env rake
12
# encoding: utf-8
23

3-
require 'rake'
4-
require 'rspec/core/rake_task'
4+
require 'rake/testtask'
55
require 'rubocop/rake_task'
66

77
# Rubocop
@@ -10,37 +10,17 @@ task :rubocop do
1010
RuboCop::RakeTask.new
1111
end
1212

13-
# Lint the cookbook
14-
desc 'Run linters'
15-
task :run_all_linters => [:rubocop] # rubocop:disable Style/HashSyntax
16-
task :default => :run_all_linters # rubocop:disable Style/HashSyntax
13+
# lint the project
14+
desc 'Run robocop linter'
15+
task lint: [:rubocop]
1716

18-
# Serverspec tests
19-
suites = Dir.glob('*').select { |entry| File.directory?(entry) }
17+
# run tests
18+
task default: [:lint, 'test:check']
2019

21-
class ServerspecTask < RSpec::Core::RakeTask
22-
attr_accessor :target
23-
24-
def spec_command
25-
if target.nil?
26-
puts 'specify either env TARGET_HOST or target_host='
27-
exit 1
28-
end
29-
30-
cmd = super
31-
"env TARGET_HOST=#{target} STANDALONE_SPEC=true #{cmd} --format documentation --no-profile"
32-
end
33-
end
34-
35-
namespace :serverspec do
36-
suites.each do |suite|
37-
desc "Run serverspec suite #{suite}"
38-
ServerspecTask.new(suite.to_sym) do |t|
39-
t.rspec_opts = '--no-color --format html --out report.html' if ENV['format'] == 'html'
40-
t.rspec_opts = '--no-color --format json --out report.json' if ENV['format'] == 'json'
41-
t.target = ENV['TARGET_HOST'] || ENV['target_host']
42-
t.ruby_opts = "-I #{suite}/serverspec"
43-
t.pattern = "#{suite}/serverspec/*_spec.rb"
44-
end
20+
namespace :test do
21+
# run inspec check to verify that the profile is properly configured
22+
task :check do
23+
dir = File.join(File.dirname(__FILE__))
24+
sh("bundle exec inspec check #{dir}")
4525
end
4626
end

0 commit comments

Comments
 (0)