2016-03-25 00:31:19 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# author: Dominik Richter
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
|
|
|
|
require 'functional/helper'
|
|
|
|
|
|
|
|
describe 'command tests' do
|
|
|
|
include FunctionalHelper
|
|
|
|
|
2016-05-06 15:16:28 +00:00
|
|
|
describe 'detect with json' do
|
2016-03-25 00:31:19 +00:00
|
|
|
it 'runs well on all nodes' do
|
2016-05-06 15:16:28 +00:00
|
|
|
out = inspec('detect --format json')
|
2016-03-25 00:31:19 +00:00
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
j = JSON.load(out.stdout)
|
|
|
|
j.keys.must_include 'name'
|
|
|
|
j.keys.must_include 'family'
|
|
|
|
j.keys.must_include 'arch'
|
2016-04-26 18:00:00 +00:00
|
|
|
j.keys.must_include 'release'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-06 15:16:28 +00:00
|
|
|
describe 'detect without json' do
|
|
|
|
it 'runs well on all nodes' do
|
|
|
|
out = inspec('detect')
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
std = out.stdout
|
|
|
|
std.must_include 'Name:'
|
|
|
|
std.must_include 'Family:'
|
|
|
|
std.must_include 'Arch:'
|
|
|
|
std.must_include 'Release:'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-26 18:00:00 +00:00
|
|
|
describe 'cmd' do
|
|
|
|
it 'can run arbitrary ruby' do
|
|
|
|
x = rand
|
|
|
|
y = rand
|
|
|
|
out = inspec("shell -c '#{x} + #{y}'")
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
j = JSON.load(out.stdout)
|
|
|
|
j.must_equal x+y
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'retrieves resources in JSON' do
|
|
|
|
out = inspec("shell -c 'os.params'")
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
j = JSON.load(out.stdout)
|
|
|
|
j.keys.must_include 'name'
|
|
|
|
j.keys.must_include 'family'
|
|
|
|
j.keys.must_include 'arch'
|
2016-03-25 00:31:19 +00:00
|
|
|
j.keys.must_include 'release'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'version' do
|
|
|
|
it 'provides the version number on stdout' do
|
|
|
|
out = inspec('version')
|
|
|
|
out.stderr.must_equal ''
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
out.stdout.must_equal Inspec::VERSION+"\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'shell' do
|
|
|
|
it 'provides a help command' do
|
|
|
|
out = CMD.run_command("echo \"help\nexit\" | #{exec_inspec} shell")
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
out.stdout.must_include 'Available commands:'
|
|
|
|
out.stdout.must_include 'You are currently running on:'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes all resources' do
|
|
|
|
out = CMD.run_command("echo \"os\nexit\" | #{exec_inspec} shell")
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
out.stdout.must_match /^=> .*Operating.* .*System.* .*Detection.*$/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'check' do
|
|
|
|
it 'verifies that a profile is ok' do
|
|
|
|
out = inspec('check ' + example_profile)
|
|
|
|
out.stdout.must_match /Valid.*true/
|
|
|
|
out.exit_status.must_equal 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|