Merge branch 'master' into release-2.0

This commit is contained in:
Jared Quick 2018-02-13 15:11:53 -05:00
commit fde895f74a
38 changed files with 367 additions and 159 deletions

View file

@ -1,29 +1,56 @@
# Change Log
<!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ -->
<!-- latest_release 1.51.6 -->
<!-- latest_release 1.51.20 -->
## [v1.51.20](https://github.com/chef/inspec/tree/v1.51.20) (2018-02-13)
#### Merged Pull Requests
- package resource: Fix Windows package detection [#2624](https://github.com/chef/inspec/pull/2624) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
<!-- latest_release -->
<!-- release_rollup since=1.51.18 -->
### Changes since 1.51.18 release
#### Merged Pull Requests
- package resource: Fix Windows package detection [#2624](https://github.com/chef/inspec/pull/2624) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 1.51.20 -->
- Fix the /private/var osx issue causing functional tests to fail [#2616](https://github.com/chef/inspec/pull/2616) ([jquick](https://github.com/jquick)) <!-- 1.51.19 -->
<!-- release_rollup -->
<!-- latest_stable_release -->
## [v1.51.18](https://github.com/chef/inspec/tree/v1.51.18) (2018-02-12)
#### Merged Pull Requests
- Force a default reporter for ad-hoc runners [#2610](https://github.com/chef/inspec/pull/2610) ([jquick](https://github.com/jquick))
- Allow ad-hoc runners to use rspec formats. [#2621](https://github.com/chef/inspec/pull/2621) ([jquick](https://github.com/jquick))
- Add json fields to schema and add tests. [#2618](https://github.com/chef/inspec/pull/2618) ([jquick](https://github.com/jquick))
<!-- latest_stable_release -->
## [v1.51.15](https://github.com/chef/inspec/tree/v1.51.15) (2018-02-09)
#### Merged Pull Requests
- Refactors http doc [#2540](https://github.com/chef/inspec/pull/2540) ([kagarmoe](https://github.com/kagarmoe))
- Refactors iis_app docs [#2541](https://github.com/chef/inspec/pull/2541) ([kagarmoe](https://github.com/kagarmoe))
- Refactors iis_site doc [#2542](https://github.com/chef/inspec/pull/2542) ([kagarmoe](https://github.com/kagarmoe))
- Refactors inetd_conf doc [#2543](https://github.com/chef/inspec/pull/2543) ([kagarmoe](https://github.com/kagarmoe))
- Refactors ini docs [#2544](https://github.com/chef/inspec/pull/2544) ([kagarmoe](https://github.com/kagarmoe))
- Kg/interface [#2550](https://github.com/chef/inspec/pull/2550) ([kagarmoe](https://github.com/kagarmoe))
- Refactors grub_conf doc sligtly; adds os metadata [#2537](https://github.com/chef/inspec/pull/2537) ([kagarmoe](https://github.com/kagarmoe))
- Use the version of LicenseScout that comes with the Omnibus gem. [#2554](https://github.com/chef/inspec/pull/2554) ([tduffield](https://github.com/tduffield))
- Fix runner report and json newline [#2601](https://github.com/chef/inspec/pull/2601) ([jquick](https://github.com/jquick))
## [v1.51.6](https://github.com/chef/inspec/tree/v1.51.6) (2018-02-08)
#### New Features
- Add new &quot;reporter&quot; system (replacement for &quot;formatters&quot;), support multiple reporters per run [#2464](https://github.com/chef/inspec/pull/2464) ([jquick](https://github.com/jquick))
<!-- latest_release -->
<!-- release_rollup since=1.51.0 -->
### Changes since 1.51.0 release
#### New Features
- Add new &quot;reporter&quot; system (replacement for &quot;formatters&quot;), support multiple reporters per run [#2464](https://github.com/chef/inspec/pull/2464) ([jquick](https://github.com/jquick)) <!-- 1.51.6 -->
#### Merged Pull Requests
- Fix travis-ci bundler issue [#2533](https://github.com/chef/inspec/pull/2533) ([jquick](https://github.com/jquick)) <!-- 1.51.5 -->
- Improve links to Learn Chef Rally [#2476](https://github.com/chef/inspec/pull/2476) ([tpetchel](https://github.com/tpetchel)) <!-- 1.51.4 -->
- apache resource: document and deprecate [#2494](https://github.com/chef/inspec/pull/2494) ([adamleff](https://github.com/adamleff)) <!-- 1.51.3 -->
- add Inspec::Describe for abstract describe state [#2010](https://github.com/chef/inspec/pull/2010) ([arlimus](https://github.com/arlimus)) <!-- 1.51.2 -->
#### Enhancements
- packages resource: Add `architectures` support [#2469](https://github.com/chef/inspec/pull/2469) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 1.51.1 -->
<!-- release_rollup -->
- packages resource: Add `architectures` support [#2469](https://github.com/chef/inspec/pull/2469) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
#### Merged Pull Requests
- add Inspec::Describe for abstract describe state [#2010](https://github.com/chef/inspec/pull/2010) ([arlimus](https://github.com/arlimus))
- apache resource: document and deprecate [#2494](https://github.com/chef/inspec/pull/2494) ([adamleff](https://github.com/adamleff))
- Improve links to Learn Chef Rally [#2476](https://github.com/chef/inspec/pull/2476) ([tpetchel](https://github.com/tpetchel))
- Fix travis-ci bundler issue [#2533](https://github.com/chef/inspec/pull/2533) ([jquick](https://github.com/jquick))
<!-- latest_stable_release -->
## [v1.51.0](https://github.com/chef/inspec/tree/v1.51.0) (2018-01-25)
#### New Resources
@ -39,7 +66,6 @@
#### Merged Pull Requests
- Sort library files before loading them so load order is predictable [#2475](https://github.com/chef/inspec/pull/2475) ([clintoncwolfe](https://github.com/clintoncwolfe))
<!-- latest_stable_release -->
## [v1.50.1](https://github.com/chef/inspec/tree/v1.50.1) (2018-01-17)

View file

@ -1,7 +1,7 @@
FROM ruby:alpine
MAINTAINER Chef Software, Inc. <docker@chef.io>
ARG VERSION=1.51.0
ARG VERSION=1.51.18
ARG GEM_SOURCE=https://rubygems.org
RUN mkdir -p /share

View file

@ -1 +1 @@
1.51.6
1.51.20

View file

@ -1,5 +1,6 @@
---
title: About the grub_conf Resource
os: "Unix/Linux"
---
# grub_conf
@ -42,7 +43,7 @@ A Grub configuration file located at `/etc/grub.conf` is similar to the followin
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# Note: You do not need to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)

View file

@ -32,7 +32,13 @@ where
<br>
## Examples
<br>
## Supported Resource Properties
body, headers, http_method, status,
<br>
## Property Examples
The following examples show how to use this InSpec audit resource.

View file

@ -42,7 +42,11 @@ For example:
<br>
## Examples
## Supported Resource Properties
application\_pool, path, physical\_path, protocols, site\_name
<br>
## Resource Examples
The following examples show how to use this InSpec audit resource.
@ -109,7 +113,7 @@ Testing a web application with https enabled and http enabled:
it { should have_protocol('https') }
it { should have_protocol('http') }
### have_physical_path
### have\_physical\_path
The `have_physical_path` matcher tests if the named path is defined for the web application:

View file

@ -40,7 +40,11 @@ For example:
<br>
## Examples
## Supported Resource Properties
app\_pool, bindings, path, state
## Property Examples
The following examples show how to use this InSpec audit resource.

View file

@ -24,10 +24,36 @@ where
<br>
## Supported Resource Properties
This resource supports any of the properties listed as services in the `inetd.conf` file. You may want to ensure that specific services do not listen via `inetd.conf`.
<br>
## Examples
The following examples show how to use this InSpec audit resource.
### Basic tests for inetd_conf services:
its('shell') { should eq nil }
or:
its('netstat') { should eq nil }
or:
its('systat') { should eq nil }
For example:
describe inetd_conf do
its('shell') { should eq nil }
its('login') { should eq nil }
its('exec') { should eq nil }
end
### Verify that FTP is disabled
The contents if the `inetd.conf` file contain the following:
@ -63,22 +89,7 @@ then the same test will return `false` for `ftp` and the entire test will fail.
## Matchers
This resource matches any service that is listed in the `inetd.conf` file. You may want to ensure that specific services do not listen via `inetd.conf`. For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
its('shell') { should eq nil }
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
or:
its('netstat') { should eq nil }
or:
its('systat') { should eq nil }
For example:
describe inetd_conf do
its('shell') { should eq nil }
its('login') { should eq nil }
its('exec') { should eq nil }
end

View file

@ -43,6 +43,9 @@ In the event a section or setting name has a period in it, the alternate syntax
its(['section.with.a.dot.in.it', 'setting.name.with.dots']) { should cmp 'lotsadots' }
<br>
## Supported Properties
This resource supports any of the settings listed in an INI file as properties.
## Examples

View file

@ -22,16 +22,12 @@ An `interface` resource block declares network interface properties to be tested
end
<br>
## Resource Properties
## Matchers
`name`, `speed`
<br>
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
### be_up
The `be_up` matcher tests if the network interface is available:
it { should be_up }
## Resource Property Examples
### name
@ -44,3 +40,16 @@ The `name` matcher tests if the named network interface exists:
The `speed` matcher tests the speed of the network interface, in MB/sec:
its('speed') { should eq 1000 }
<br>
## Matchers
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
### be_up
The `be_up` matcher tests if the network interface is available:
it { should be_up }

View file

@ -1,11 +1,12 @@
---
title: About the kernel_parameter Resource
os: Linux
---
# kernel_parameter
Use the `kernel_parameter` InSpec audit resource to test kernel parameters on Linux platforms.
These parameters are located under `/proc/cmdline`.
<br>
## Syntax
@ -42,7 +43,7 @@ The following examples show how to use this InSpec audit resource.
### Test if an IPv6 address accepts redirects
describe kernel_parameter('net.ipv6.conf.interface.accept_redirects') do
its('value') { should eq 'true' }
its('value') { should cmp 'true' }
end
<br>
@ -50,9 +51,3 @@ The following examples show how to use this InSpec audit resource.
## Matchers
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
### value
The `value` matcher tests the value assigned to the named IP address versus the value declared in the test:
its('value') { should eq 0 }

View file

@ -1,5 +1,6 @@
---
title: The key_rsa Resource
os: Linux
---
# key_rsa
@ -31,13 +32,11 @@ You can use an optional passphrase with `key_rsa`
## Supported Properties
### public?
* `public_key`, `private_key`, `key_length`
To verify if a key is public use the following:
<br>
describe key_rsa('/etc/pki/www.mywebsite.com.key') do
it { should be_public }
end
## Property Examples
### public_key (String)
@ -47,15 +46,6 @@ The `public_key` property returns the public part of the RSA key pair
its('public_key') { should match "-----BEGIN PUBLIC KEY-----\n3597459df9f3982......" }
end
### private?
This property verifies that the key includes a private key:
describe key_rsa('/etc/pki/www.mywebsite.com.key') do
it { should be_private }
end
### private_key (String)
The `private_key` property returns the private key or the RSA key pair.
@ -71,3 +61,23 @@ The `key_length` property allows testing the number of bits in the key pair.
describe key_rsa('/etc/pki/www.mywebsite.com.key') do
its('key_length') { should eq 2048 }
end
## Matchers
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
### public?
To verify if a key is public use the following:
describe key_rsa('/etc/pki/www.mywebsite.com.key') do
it { should be_public }
end
### private?
This property verifies that the key includes a private key:
describe key_rsa('/etc/pki/www.mywebsite.com.key') do
it { should be_private }
end

View file

@ -1,10 +1,11 @@
---
title: About the limits_conf Resource
os: Linux
---
# limits_conf
Use the `limits_conf` InSpec audit resource to test configuration settings in the `/etc/security/limits.conf` file. The `limits.conf` defines limits for processes (by user and/or group names) and helps ensure that the system on which those processes are running remains stable. Each process may be assigned a hard or soft limit.
Use the `limits_conf` InSpec audit resource to test configuration settings in the `/etc/security/limits.conf` file. The `limits.conf` defines limits for processes (by user and/or group names) and helps ensure that the system running those processes remains stable. Each process may be assigned a hard or soft limit.
* Soft limits are maintained by the shell and defines the number of file handles (or open files) available to the user or group after login
* Hard limits are maintained by the kernel and defines the maximum number of allowed file handles
@ -38,10 +39,24 @@ where
<br>
## Supported Properties
* `domain`
## Examples
The following examples show how to use this InSpec audit resource.
### domain
The `domain` property tests the domain in the `limits.conf` file, along with associated type, item, and value:
its('domain') { should include ['type', 'item', 'value'] }
`
For example:
its('grantmc') { should include ['hard', 'nofile', '63536'] }
### Test limits
describe limits_conf('path') do
@ -55,12 +70,4 @@ The following examples show how to use this InSpec audit resource.
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
### domain
The `domain` matcher tests the domain in the `limits.conf` file, along with associated type, item, and value:
its('domain') { should include ['type', 'item', 'value'] }
`
For example:
its('grantmc') { should include ['hard', 'nofile', '63536'] }

View file

@ -1,5 +1,6 @@
---
title: About the login_defs Resource
os: Linux
---
# login_defs
@ -23,10 +24,22 @@ where
<br>
## Supported Properties
This resource supports the properties found in the `login.defs` configuration settings.
<br>
## Examples
The following examples show how to use this InSpec audit resource.
### name
The `name` matcher tests the value of `name` as read from `login.defs` versus the value declared in the test:
its('name') { should eq 'foo' }
### Test password expiration settings
describe login_defs do
@ -55,8 +68,4 @@ The following examples show how to use this InSpec audit resource.
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
### name
The `name` matcher tests the value of `name` as read from `login.defs` versus the value declared in the test:
its('name') { should eq 'foo' }

View file

@ -40,7 +40,6 @@ The following examples show how to use this InSpec audit resource.
describe user('root') do
it { should exist }
it { should belong_to_group 'root' }
its('uid') { should eq 0 }
its('groups') { should eq ['root'] }
end
@ -64,7 +63,7 @@ The `nginx` user is typically `www-data`, but on CentOS it's `nginx`. The follow
## Matchers
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
### exist
@ -76,7 +75,7 @@ The `exist` matcher tests if the named user exists:
The `gid` matcher tests the group identifier:
its('gid') { should eq 1234 } }
its('gid') { should eq 1234 }
where `1234` represents the user identifier.
@ -92,7 +91,7 @@ where `root` represents the group.
The `groups` matcher tests two (or more) groups to which the user belongs:
its('groups') { should eq ['root', 'other']}
its('groups') { should eq ['root', 'other'] }
### home
@ -126,7 +125,7 @@ The `shell` matcher tests the path to the default shell for the user:
The `uid` matcher tests the user identifier:
its('uid') { should eq 1234 } }
its('uid') { should eq 1234 }
where `1234` represents the user identifier.

View file

@ -91,7 +91,7 @@ module Inspec
}
end
def self.parse_reporters(opts)
def self.parse_reporters(opts) # rubocop:disable Metrics/AbcSize
# merge in any legacy formats as reporter
# this method will only be used for ad-hoc runners
if !opts['format'].nil? && opts['reporter'].nil?
@ -100,6 +100,9 @@ module Inspec
opts.delete('format')
end
# default to cli report for ad-hoc runners
opts['reporter'] = ['cli'] if opts['reporter'].nil?
# parse out cli to proper report format
if opts['reporter'].is_a?(Array)
reports = {}
@ -208,10 +211,12 @@ module Inspec
opts = BaseCLI.default_options[type] unless type.nil? || BaseCLI.default_options[type].nil?
# merge in any options from json-config
opts.merge!(options_json)
json_config = options_json
opts.merge!(json_config)
# remove the default reporter if we are setting a legacy format on the cli
opts.delete('reporter') if options['format']
# or via json-config
opts.delete('reporter') if options['format'] || json_config['format']
# merge in any options defined via thor
opts.merge!(options)
@ -297,7 +302,7 @@ module Inspec
Inspec::Log.init(loc)
Inspec::Log.level = get_log_level(o.log_level)
o[:logger] = Logger.new(STDOUT)
o[:logger] = Logger.new(loc)
# output json if we have activated the json formatter
if o['log-format'] == 'json'
o[:logger].formatter = Logger::JSONFormatter.new

View file

@ -6,7 +6,7 @@ require 'inspec/reporters/junit'
module Inspec::Reporters
def self.render(reporter, run_data)
name, config = reporter
name, config = reporter.dup
config[:run_data] = run_data
case name
when 'cli'
@ -27,7 +27,24 @@ module Inspec::Reporters
if config['file']
File.write(config['file'], output)
elsif config['stdout'] == true
puts output
print output
STDOUT.flush
end
end
def self.report(reporter, run_data)
name, config = reporter.dup
config[:run_data] = run_data
case name
when 'json'
reporter = Inspec::Reporters::Json.new(config)
when 'json-min'
reporter = Inspec::Reporters::JsonMin.new(config)
else
# use base run_data hash for any other report
return run_data
end
reporter.report
end
end

View file

@ -7,8 +7,9 @@ module Inspec::Reporters
@output = ''
end
def output(str)
@output << "#{str}\n"
def output(str, newline = true)
@output << str
@output << "\n" if newline
end
def rendered_output

View file

@ -5,7 +5,11 @@ require 'json'
module Inspec::Reporters
class Json < Base
def render
report = {
output(report.to_json, false)
end
def report
{
platform: platform,
profiles: profiles,
statistics: { duration: run_data[:statistics][:duration] },
@ -13,8 +17,6 @@ module Inspec::Reporters
controls: controls,
other_checks: run_data[:other_checks],
}
output(report.to_json)
end
private
@ -39,6 +41,7 @@ module Inspec::Reporters
}
control[:resource] = c[:resource] if c[:resource]
control[:skip_message] = c[:skip_message] if c[:skip_message]
control[:message] = c[:message] if c[:message]
control[:exception] = c[:exception] if c[:exception]
control[:backtrace] = c[:backtrace] if c[:backtrace]
@ -60,6 +63,9 @@ module Inspec::Reporters
}
result[:resource] = r[:resource] if r[:resource]
result[:skip_message] = r[:skip_message] if r[:skip_message]
result[:message] = r[:message] if r[:message]
result[:exception] = r[:exception] if r[:exception]
result[:backtrace] = r[:backtrace] if r[:backtrace]
results << result
end

View file

@ -4,7 +4,11 @@ require 'json'
module Inspec::Reporters
class JsonMin < Base
def render # rubocop:disable Metrics/AbcSize
def render
output(report.to_json, false)
end
def report # rubocop:disable Metrics/AbcSize
report = {
controls: [],
statistics: { duration: run_data[:statistics][:duration] },
@ -38,7 +42,7 @@ module Inspec::Reporters
end
end
output(report.to_json)
report
end
end
end

View file

@ -31,8 +31,6 @@ module Inspec
class Runner
extend Forwardable
def_delegator :@test_collector, :report
attr_reader :backend, :rules, :attributes
def initialize(conf = {})
@rules = []
@ -44,14 +42,16 @@ module Inspec
@ignore_supports = @conf[:ignore_supports]
@create_lockfile = @conf[:create_lockfile]
@cache = Inspec::Cache.new(@conf[:vendor_cache])
# parse any ad-hoc runners reporter formats
# this has to happen before we load the test_collector
@conf = Inspec::BaseCLI.parse_reporters(@conf) if @conf[:type].nil?
@test_collector = @conf.delete(:test_collector) || begin
require 'inspec/runner_rspec'
RunnerRspec.new(@conf)
end
# parse any ad-hoc runners reporter formats
@conf = Inspec::BaseCLI.parse_reporters(@conf) if @conf[:type].nil?
# list of profile attributes
@attributes = []
@ -112,6 +112,10 @@ module Inspec
end
end
def report
Inspec::Reporters.report(@conf['reporter'].first, @run_data)
end
def write_lockfile(profile)
return false if !profile.writable?
@ -125,8 +129,9 @@ module Inspec
end
def run_tests(with = nil)
status, run_data = @test_collector.run(with)
render_output(run_data)
status, @run_data = @test_collector.run(with)
# dont output anything if we want a report
render_output(@run_data) unless @conf['report']
status
end

View file

@ -78,15 +78,6 @@ module Inspec
[status, @formatter.run_data]
end
# Provide an output hash of the run's report
#
# @return [Hash] a run's output hash
def report
reporter = @formatter || RSpec.configuration.formatters[0]
return nil if reporter.nil? || !reporter.respond_to?(:output_hash)
reporter.output_hash
end
# Empty the list of registered tests.
#
# @return [nil]
@ -103,18 +94,18 @@ module Inspec
#
#
def set_optional_formatters
return if @conf[:reporter].nil?
if @conf[:reporter].key?('json-rspec')
return if @conf['reporter'].nil?
if @conf['reporter'].key?('json-rspec')
# We cannot pass in a nil output path. Rspec only accepts a valid string or a IO object.
if @conf[:reporter]['json-rspec']&.[]('file').nil?
if @conf['reporter']['json-rspec']&.[]('file').nil?
RSpec.configuration.add_formatter(Inspec::Formatters::RspecJson)
else
RSpec.configuration.add_formatter(Inspec::Formatters::RspecJson, @conf[:reporter]['json-rspec']['file'])
end
@conf[:reporter].delete('json-rspec')
@conf['reporter'].delete('json-rspec')
end
formats = @conf[:reporter].select { |k, _v| %w{documentation progress html}.include?(k) }
formats = @conf['reporter'].select { |k, _v| %w{documentation progress html}.include?(k) }
formats.each do |k, v|
# We cannot pass in a nil output path. Rspec only accepts a valid string or a IO object.
if v&.[]('file').nil?
@ -122,7 +113,7 @@ module Inspec
else
RSpec.configuration.add_formatter(k.to_sym, v['file'])
end
@conf[:reporter].delete(k)
@conf['reporter'].delete(k)
end
end
@ -140,11 +131,6 @@ module Inspec
RSpec.configuration.add_formatter(Inspec::Formatters::ShowProgress, $stderr) if @conf[:show_progress]
set_optional_formatters
RSpec.configuration.color = @conf['color']
setup_reporting if @conf['report']
end
def setup_reporting
RSpec.configuration.add_formatter(Inspec::RSpecReporter)
end
# Make sure that all RSpec example groups use the provided ID.
@ -174,12 +160,4 @@ module Inspec
metadata[:source_location] = rule.instance_variable_get(:@__source_location)
end
end
class RSpecReporter < RSpec::Core::Formatters::JsonFormatter
RSpec::Core::Formatters.register Inspec::RSpecReporter
def initialize(*)
super(StringIO.new)
end
end
end

View file

@ -33,6 +33,9 @@ module Inspec
'start_time' => { 'type' => 'string' },
'skip_message' => { 'type' => 'string', 'optional' => true },
'resource' => { 'type' => 'string', 'optional' => true },
'message' => { 'type' => 'string', 'optional' => true },
'exception' => { 'type' => 'string', 'optional' => true },
'backtrace' => { 'type' => 'object', 'optional' => true },
},
}.freeze
@ -152,6 +155,9 @@ module Inspec
'code_desc' => { 'type' => 'string' },
'skip_message' => { 'type' => 'string', 'optional' => true },
'resource' => { 'type' => 'string', 'optional' => true },
'message' => { 'type' => 'string', 'optional' => true },
'exception' => { 'type' => 'string', 'optional' => true },
'backtrace' => { 'type' => 'object', 'optional' => true },
},
}.freeze

View file

@ -4,5 +4,5 @@
# author: Christoph Hartmann
module Inspec
VERSION = '1.51.6'
VERSION = '1.51.20'
end

View file

@ -267,6 +267,12 @@ module Inspec::Resources
Select-Object -Property DisplayName,DisplayVersion | ConvertTo-Json
EOF
# We cannot rely on `exit_status` since PowerShell always exits 0 from the
# above command. Instead, if no package is found the output of the command
# will be `''` so we can use that to return `{}` to match the behavior of
# other package managers.
return {} if cmd.stdout == ''
begin
package = JSON.parse(cmd.stdout)
rescue JSON::ParserError => e

View file

@ -11,7 +11,6 @@ source 'https://rubygems.org'
# gem 'omnibus-software', github: 'chef/omnibus-software', branch: 'ksubrama/ruby23'
# Use entries from chef's Gemfile
gem 'license_scout', github: 'chef/license_scout'
gem 'omnibus', github: 'chef/omnibus'
gem 'omnibus-software', github: 'chef/omnibus-software'

View file

@ -25,6 +25,8 @@ describe 'example inheritance profile' do
out = inspec('vendor --overwrite', "cd #{dir} &&")
out.stderr.must_equal ''
out.exit_status.must_equal 0
# this fixes the osx /var symlink to /private/var causing this test to fail
out.stdout.gsub!('/private/var', '/var')
out.stdout.must_include "Dependencies for profile #{dir} successfully vendored to #{dir}/vendor"
File.exist?(File.join(dir, 'vendor')).must_equal true

View file

@ -8,29 +8,30 @@ describe 'BaseCLI' do
let(:cli) { Inspec::BaseCLI.new }
describe 'merge_options' do
let(:default_options) do
{ exec: { 'reporter' => ['json'], 'backend_cache' => false }}
end
it 'cli defaults populate correctly' do
default_options = { exec: { format: 'json', backend_cache: false }}
Inspec::BaseCLI.stubs(:default_options).returns(default_options)
opts = cli.send(:merged_opts, :exec)
expected = { 'format' => 'json', 'backend_cache' => false }
expected = {"backend_cache"=>false, "reporter"=>{"json"=>{"stdout"=>true}}}
opts.must_equal expected
end
it 'json-config options override cli defaults' do
default_options = { exec: { format: 'json', backend_cache: false }}
Inspec::BaseCLI.stubs(:default_options).returns(default_options)
parsed_json = { 'backend_cache' => true }
cli.expects(:options_json).returns(parsed_json)
opts = cli.send(:merged_opts, :exec)
expected = { 'format' => 'json', 'backend_cache' => true }
expected = {"backend_cache"=>true, "reporter"=>{"json"=>{"stdout"=>true}}}
opts.must_equal expected
end
it 'cli options override json-config and default' do
default_options = { exec: { format: 'json', backend_cache: false }}
Inspec::BaseCLI.stubs(:default_options).returns(default_options)
parsed_json = { 'backend_cache' => false }
@ -40,18 +41,68 @@ describe 'BaseCLI' do
cli.instance_variable_set(:@options, cli_options)
opts = cli.send(:merged_opts, :exec)
expected = { 'format' => 'json', 'backend_cache' => true }
expected = {"backend_cache"=>true, "reporter"=>{"json"=>{"stdout"=>true}}}
opts.must_equal expected
end
it 'make sure shell does not get exec defaults' do
default_options = { exec: { format: 'json', backend_cache: false }}
Inspec::BaseCLI.stubs(:default_options).returns(default_options)
opts = cli.send(:merged_opts)
expected = {}
opts.must_equal expected
end
it 'make sure default reporter is overriden by json-config format' do
default_options['reporter'] = ['cli']
Inspec::BaseCLI.stubs(:default_options).returns(default_options)
parsed_json = { 'format' => 'json' }
cli.expects(:options_json).returns(parsed_json)
opts = cli.send(:merged_opts, :exec)
expected = {"backend_cache"=>false, "reporter"=>{"json"=>{"stdout"=>true}}}
opts.must_equal expected
end
end
describe 'configure_logger' do
let(:options) do
o = {
'log_location' => STDERR,
'log_level' => 'debug',
'reporter' => {
'json' => {
'stdout' => true,
},
},
}
Thor::CoreExt::HashWithIndifferentAccess.new(o)
end
let(:format) do
device = options[:logger].instance_variable_get(:"@logdev")
device.instance_variable_get(:"@dev")
end
it 'sets to stderr for log_location' do
cli.send(:configure_logger, options)
format.must_equal STDERR
end
it 'sets to stderr for json' do
options.delete('log_location')
options.delete('log_level')
cli.send(:configure_logger, options)
format.must_equal STDERR
end
it 'sets defaults to stdout for everything else' do
options.delete('log_location')
options.delete('log_level')
options.delete('reporter')
cli.send(:configure_logger, options)
format.must_equal STDOUT
end
end
describe 'parse_reporters' do

View file

@ -9,7 +9,8 @@ Target: local://
File /tmp
 ✔ should be directory
gem package rubocop
 ∅ should be installed
 ∅ should be installed
rubocop is not installed
stdout
 ✔ stdout should eq "jquick\n"

View file

@ -9,7 +9,8 @@ Target: local://
File /tmp
 [PASS] should be directory
gem package rubocop
 [MAJR] should be installed
 [MAJR] should be installed
rubocop is not installed
stdout
 [PASS] stdout should eq "jquick\n"

View file

@ -1 +1 @@
{"controls":[{"id":"(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)","profile_id":"long_commands","profile_sha256":"4f816f8cf18f165f05f1cf20936aaad06a15287de3f578891197647ca05c7df4","status":"passed","code_desc":"File /tmp should be directory"},{"id":"tmp-1.0","profile_id":"long_commands","profile_sha256":"4f816f8cf18f165f05f1cf20936aaad06a15287de3f578891197647ca05c7df4","status":"passed","code_desc":"File /tmp should be directory"},{"id":"(generated from example.rb:21 2ff474c5357e7070f4c3efa932032dcb)","profile_id":"long_commands","profile_sha256":"4f816f8cf18f165f05f1cf20936aaad06a15287de3f578891197647ca05c7df4","status":"failed","code_desc":"gem package rubocop should be installed"},{"id":"(generated from run_command.rb:5 a411d4ded1530b2f48170840e1127584)","profile_id":"long_commands","profile_sha256":"4f816f8cf18f165f05f1cf20936aaad06a15287de3f578891197647ca05c7df4","status":"passed","code_desc":"Command whoami stdout should eq \"jquick\\n\""}],"statistics":{"duration":0.039182},"version":"1.49.2"}
{"controls":[{"id":"(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)","profile_id":"long_commands","profile_sha256":"4f816f8cf18f165f05f1cf20936aaad06a15287de3f578891197647ca05c7df4","status":"passed","code_desc":"File /tmp should be directory"},{"id":"tmp-1.0","profile_id":"long_commands","profile_sha256":"4f816f8cf18f165f05f1cf20936aaad06a15287de3f578891197647ca05c7df4","status":"passed","code_desc":"File /tmp should be directory"},{"id":"(generated from example.rb:21 2ff474c5357e7070f4c3efa932032dcb)","profile_id":"long_commands","profile_sha256":"4f816f8cf18f165f05f1cf20936aaad06a15287de3f578891197647ca05c7df4","status":"failed","code_desc":"gem package rubocop should be installed","message":"rubocop is not installed"},{"id":"(generated from run_command.rb:5 a411d4ded1530b2f48170840e1127584)","profile_id":"long_commands","profile_sha256":"4f816f8cf18f165f05f1cf20936aaad06a15287de3f578891197647ca05c7df4","status":"passed","code_desc":"Command whoami stdout should eq \"jquick\\n\""}],"statistics":{"duration":0.039182},"version":"1.49.2"}

View file

@ -1 +1 @@
{"platform":{"name":"mac_os_x","release":"17.2.0"},"profiles":[{"name":"long_commands","version":"0.1.0","sha256":"4f816f8cf18f165f05f1cf20936aaad06a15287de3f578891197647ca05c7df4","title":"InSpec Profile","maintainer":"The Authors","summary":"An InSpec Compliance Profile","license":"Apache-2.0","copyright":"The Authors","copyright_email":"you@example.com","supports":[{"os-family":"bds"},{"os-name":"mac_os_x","release":"17.*"}],"attributes":[],"groups":[{"id":"controls/example.rb","controls":["(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)","tmp-1.0","(generated from example.rb:21 2ff474c5357e7070f4c3efa932032dcb)"],"title":"sample section"},{"id":"controls/run_command.rb","controls":["(generated from run_command.rb:5 a411d4ded1530b2f48170840e1127584)"]}],"controls":[{"id":"(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)","title":null,"desc":null,"impact":0.5,"refs":[],"tags":{},"code":"","source_location":{"line":89,"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb"},"results":[{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.002058,"start_time":"2018-01-05 11:43:04 -0500"}]},{"id":"tmp-1.0","title":"Create /tmp directory","desc":"An optional description...","impact":0.7,"refs":[],"tags":{},"code":"control 'tmp-1.0' do # A unique ID for this control\n impact 0.7 # The criticality, if this control fails.\n title 'Create /tmp directory' # A human-readable title\n desc 'An optional description...'\n describe file('/tmp') do # The actual test\n it { should be_directory }\n end\nend\n","source_location":{"line":12,"ref":"../inspec-demo/_test/long_commands/controls/example.rb"},"results":[{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.000102,"start_time":"2018-01-05 11:43:04 -0500"}]},{"id":"(generated from example.rb:21 2ff474c5357e7070f4c3efa932032dcb)","title":null,"desc":null,"impact":0.5,"refs":[],"tags":{},"code":"","source_location":{"line":89,"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb"},"results":[{"status":"failed","code_desc":"gem package rubocop should be installed","run_time":0.000168,"start_time":"2018-01-05 11:43:04 -0500"}]},{"id":"(generated from run_command.rb:5 a411d4ded1530b2f48170840e1127584)","title":null,"desc":null,"impact":0.5,"refs":[],"tags":{},"code":"","source_location":{"line":89,"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb"},"results":[{"status":"passed","code_desc":"Command whoami stdout should eq \"jquick\\n\"","run_time":0.034938,"start_time":"2018-01-05 11:43:04 -0500"}]}]}],"statistics":{"duration":0.039182},"version":"1.49.2","controls":[{"status":"passed","start_time":"2018-01-05 11:43:04 -0500","run_time":0.002058,"code_desc":"File /tmp should be directory"},{"status":"passed","start_time":"2018-01-05 11:43:04 -0500","run_time":0.000102,"code_desc":"File /tmp should be directory"},{"status":"passed","start_time":"2018-01-05 11:43:04 -0500","run_time":0.000168,"code_desc":"gem package rubocop should be installed"},{"status":"passed","start_time":"2018-01-05 11:43:04 -0500","run_time":0.034938,"code_desc":"Command whoami stdout should eq \"jquick\\n\""}],"other_checks":[]}
{"platform":{"name":"mac_os_x","release":"17.2.0"},"profiles":[{"name":"long_commands","version":"0.1.0","sha256":"4f816f8cf18f165f05f1cf20936aaad06a15287de3f578891197647ca05c7df4","title":"InSpec Profile","maintainer":"The Authors","summary":"An InSpec Compliance Profile","license":"Apache-2.0","copyright":"The Authors","copyright_email":"you@example.com","supports":[{"os-family":"bds"},{"os-name":"mac_os_x","release":"17.*"}],"attributes":[],"groups":[{"id":"controls/example.rb","controls":["(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)","tmp-1.0","(generated from example.rb:21 2ff474c5357e7070f4c3efa932032dcb)"],"title":"sample section"},{"id":"controls/run_command.rb","controls":["(generated from run_command.rb:5 a411d4ded1530b2f48170840e1127584)"]}],"controls":[{"id":"(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)","title":null,"desc":null,"impact":0.5,"refs":[],"tags":{},"code":"","source_location":{"line":89,"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb"},"results":[{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.002058,"start_time":"2018-01-05 11:43:04 -0500"}]},{"id":"tmp-1.0","title":"Create /tmp directory","desc":"An optional description...","impact":0.7,"refs":[],"tags":{},"code":"control 'tmp-1.0' do # A unique ID for this control\n impact 0.7 # The criticality, if this control fails.\n title 'Create /tmp directory' # A human-readable title\n desc 'An optional description...'\n describe file('/tmp') do # The actual test\n it { should be_directory }\n end\nend\n","source_location":{"line":12,"ref":"../inspec-demo/_test/long_commands/controls/example.rb"},"results":[{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.000102,"start_time":"2018-01-05 11:43:04 -0500"}]},{"id":"(generated from example.rb:21 2ff474c5357e7070f4c3efa932032dcb)","title":null,"desc":null,"impact":0.5,"refs":[],"tags":{},"code":"","source_location":{"line":89,"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb"},"results":[{"status":"failed","code_desc":"gem package rubocop should be installed","run_time":0.000168,"start_time":"2018-01-05 11:43:04 -0500","message":"rubocop is not installed"}]},{"id":"(generated from run_command.rb:5 a411d4ded1530b2f48170840e1127584)","title":null,"desc":null,"impact":0.5,"refs":[],"tags":{},"code":"","source_location":{"line":89,"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb"},"results":[{"status":"passed","code_desc":"Command whoami stdout should eq \"jquick\\n\"","run_time":0.034938,"start_time":"2018-01-05 11:43:04 -0500"}]}]}],"statistics":{"duration":0.039182},"version":"1.49.2","controls":[{"status":"passed","start_time":"2018-01-05 11:43:04 -0500","run_time":0.002058,"code_desc":"File /tmp should be directory"},{"status":"passed","start_time":"2018-01-05 11:43:04 -0500","run_time":0.000102,"code_desc":"File /tmp should be directory"},{"status":"passed","start_time":"2018-01-05 11:43:04 -0500","run_time":0.000168,"code_desc":"gem package rubocop should be installed"},{"status":"passed","start_time":"2018-01-05 11:43:04 -0500","run_time":0.034938,"code_desc":"Command whoami stdout should eq \"jquick\\n\""}],"other_checks":[]}

View file

@ -4,7 +4,7 @@
<testcase name='File /tmp should be directory' classname='long_commands.Anonymous' time='0.002058'/>
<testcase name='File /tmp should be directory' classname='long_commands.tmp-1.0' time='0.000102'/>
<testcase name='gem package rubocop should be installed' classname='long_commands.Anonymous' time='0.000168'>
<failure/>
<failure message='rubocop is not installed'/>
</testcase>
<testcase name='Command whoami stdout should eq &quot;jquick\n&quot;' classname='long_commands.Anonymous' time='0.034938'/>
</testsuite>

View file

@ -1 +1 @@
{"controls":[{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.002058,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"File /tmp","expectation_message":"should be directory"},{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.000102,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"File /tmp","expectation_message":"should be directory"},{"status":"passed","code_desc":"gem package rubocop should be installed","run_time":0.000168,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"gem package rubocop","expectation_message":"should be installed"},{"status":"passed","code_desc":"Command whoami stdout should eq \"jquick\\n\"","run_time":0.034938,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"stdout","expectation_message":"stdout should eq \"jquick\\n\""}],"other_checks":[],"profiles":[{"name":"long_commands","title":"InSpec Profile","maintainer":"The Authors","copyright":"The Authors","copyright_email":"you@example.com","license":"Apache-2.0","summary":"An InSpec Compliance Profile","version":"0.1.0","supports":[{"os-family":"bds"},{"os-name":"mac_os_x","release":"17.*"}],"controls":[{"title":null,"desc":null,"impact":0.5,"refs":[],"tags":{},"code":"","source_location":{"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb","line":89},"id":"(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)","results":[{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.002058,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"File /tmp","expectation_message":"should be directory"}]},{"title":"Create /tmp directory","desc":"An optional description...","impact":0.7,"refs":[],"tags":{},"code":"control 'tmp-1.0' do # A unique ID for this control\n impact 0.7 # The criticality, if this control fails.\n title 'Create /tmp directory' # A human-readable title\n desc 'An optional description...'\n describe file('/tmp') do # The actual test\n it { should be_directory }\n end\nend\n","source_location":{"ref":"../inspec-demo/_test/long_commands/controls/example.rb","line":12},"id":"tmp-1.0","results":[{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.000102,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"File /tmp","expectation_message":"should be directory"}]},{"title":null,"desc":null,"impact":0.5,"refs":[],"tags":{},"code":"","source_location":{"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb","line":89},"id":"(generated from example.rb:21 2ff474c5357e7070f4c3efa932032dcb)","results":[{"status":"failed","code_desc":"gem package rubocop should be installed","run_time":0.000168,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"gem package rubocop","expectation_message":"should be installed"}]},{"title":null,"desc":null,"impact":0.5,"refs":[],"tags":{},"code":"","source_location":{"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb","line":89},"id":"(generated from run_command.rb:5 a411d4ded1530b2f48170840e1127584)","results":[{"status":"passed","code_desc":"Command whoami stdout should eq \"jquick\\n\"","run_time":0.034938,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"stdout","expectation_message":"stdout should eq \"jquick\\n\""}]}],"groups":[{"title":"sample section","controls":["(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)","tmp-1.0","(generated from example.rb:21 2ff474c5357e7070f4c3efa932032dcb)"],"id":"controls/example.rb"},{"title":null,"controls":["(generated from run_command.rb:5 a411d4ded1530b2f48170840e1127584)"],"id":"controls/run_command.rb"}],"attributes":[],"sha256":"4f816f8cf18f165f05f1cf20936aaad06a15287de3f578891197647ca05c7df4"}],"platform":{"name":"mac_os_x","release":"17.2.0","target":"local://"},"version":"1.49.2","statistics":{"duration":0.039182}}
{"controls":[{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.002058,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"File /tmp","expectation_message":"should be directory"},{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.000102,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"File /tmp","expectation_message":"should be directory"},{"status":"passed","code_desc":"gem package rubocop should be installed","run_time":0.000168,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"gem package rubocop","expectation_message":"should be installed"},{"status":"passed","code_desc":"Command whoami stdout should eq \"jquick\\n\"","run_time":0.034938,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"stdout","expectation_message":"stdout should eq \"jquick\\n\""}],"other_checks":[],"profiles":[{"name":"long_commands","title":"InSpec Profile","maintainer":"The Authors","copyright":"The Authors","copyright_email":"you@example.com","license":"Apache-2.0","summary":"An InSpec Compliance Profile","version":"0.1.0","supports":[{"os-family":"bds"},{"os-name":"mac_os_x","release":"17.*"}],"controls":[{"title":null,"desc":null,"impact":0.5,"refs":[],"tags":{},"code":"","source_location":{"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb","line":89},"id":"(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)","results":[{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.002058,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"File /tmp","expectation_message":"should be directory"}]},{"title":"Create /tmp directory","desc":"An optional description...","impact":0.7,"refs":[],"tags":{},"code":"control 'tmp-1.0' do # A unique ID for this control\n impact 0.7 # The criticality, if this control fails.\n title 'Create /tmp directory' # A human-readable title\n desc 'An optional description...'\n describe file('/tmp') do # The actual test\n it { should be_directory }\n end\nend\n","source_location":{"ref":"../inspec-demo/_test/long_commands/controls/example.rb","line":12},"id":"tmp-1.0","results":[{"status":"passed","code_desc":"File /tmp should be directory","run_time":0.000102,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"File /tmp","expectation_message":"should be directory"}]},{"title":null,"desc":null,"impact":0.5,"refs":[],"tags":{},"code":"","source_location":{"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb","line":89},"id":"(generated from example.rb:21 2ff474c5357e7070f4c3efa932032dcb)","results":[{"status":"failed","message":"rubocop is not installed","code_desc":"gem package rubocop should be installed","run_time":0.000168,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"gem package rubocop","expectation_message":"should be installed"}]},{"title":null,"desc":null,"impact":0.5,"refs":[],"tags":{},"code":"","source_location":{"ref":"/Users/jquick/Chef/inspec/lib/inspec/control_eval_context.rb","line":89},"id":"(generated from run_command.rb:5 a411d4ded1530b2f48170840e1127584)","results":[{"status":"passed","code_desc":"Command whoami stdout should eq \"jquick\\n\"","run_time":0.034938,"start_time":"2018-01-05 11:43:04 -0500","resource_title":"stdout","expectation_message":"stdout should eq \"jquick\\n\""}]}],"groups":[{"title":"sample section","controls":["(generated from example.rb:7 871cd54043069c5c4f6e382fd5627830)","tmp-1.0","(generated from example.rb:21 2ff474c5357e7070f4c3efa932032dcb)"],"id":"controls/example.rb"},{"title":null,"controls":["(generated from run_command.rb:5 a411d4ded1530b2f48170840e1127584)"],"id":"controls/run_command.rb"}],"attributes":[],"sha256":"4f816f8cf18f165f05f1cf20936aaad06a15287de3f578891197647ca05c7df4"}],"platform":{"name":"mac_os_x","release":"17.2.0","target":"local://"},"version":"1.49.2","statistics":{"duration":0.039182}}

View file

@ -76,7 +76,8 @@ describe Inspec::Reporters::CLI do
File /tmp
\e[38;5;41m should be directory\e[0m
gem package rubocop
\e[38;5;208m should be installed\e[0m
\e[38;5;208m should be installed
rubocop is not installed\e[0m
stdout
\e[38;5;41m stdout should eq \"jquick\\n\"\e[0m
EOF

View file

@ -4,16 +4,24 @@ require 'helper'
describe Inspec::Reporters::JsonMin do
let(:path) { File.expand_path(File.dirname(__FILE__)) }
let(:report) do
let(:report) do
data = JSON.parse(File.read(path + '/../mock/reporters/run_data.json'), symbolize_names: true)
Inspec::Reporters::JsonMin.new({ run_data: data })
end
describe '#render' do
it 'confirm render output' do
cli_output = File.read(path + '/../mock/reporters/json_min_output')
output = File.read(path + '/../mock/reporters/json_min_output')
report.render
report.rendered_output.must_equal cli_output
report.rendered_output.must_equal output
end
end
describe '#report' do
it 'confirm report output' do
output = File.read(path + '/../mock/reporters/json_min_output')
output = JSON.parse(output, symbolize_names: true)
report.report.must_equal output
end
end
end

View file

@ -13,9 +13,17 @@ describe Inspec::Reporters::Json do
describe '#render' do
it 'confirm render output' do
cli_output = File.read(path + '/../mock/reporters/json_output')
output = File.read(path + '/../mock/reporters/json_output')
report.render
report.rendered_output.must_equal cli_output
report.rendered_output.must_equal output
end
end
describe '#report' do
it 'confirm report output' do
output = File.read(path + '/../mock/reporters/json_output')
output = JSON.parse(output, symbolize_names: true)
report.report.must_equal output
end
end

View file

@ -11,6 +11,31 @@ describe Inspec::Runner do
Inspec::Runner.any_instance.stubs(:validate_attributes_file_readability!)
end
describe 'confirm reporter defaults to cli' do
it 'defaults to cli when format and reporter not set' do
opts = { command_runner: :generic, backend_cache: true }
runner = Inspec::Runner.new(opts)
config = runner.instance_variable_get(:"@conf")
expected = { 'cli' => { 'stdout' => true } }
config['reporter'].must_equal expected
end
it 'does not default when format is set' do
opts = { command_runner: :generic, backend_cache: true, 'format' => 'json' }
runner = Inspec::Runner.new(opts)
config = runner.instance_variable_get(:"@conf")
expected = { 'json' => { 'stdout' => true } }
config['reporter'].must_equal expected
end
it 'delets format if set to a rspec format' do
opts = { command_runner: :generic, backend_cache: true, 'format' => 'progress' }
runner = Inspec::Runner.new(opts)
config = runner.instance_variable_get(:"@conf")
config['reporter'].must_equal Hash.new
end
end
describe 'when backend caching is enabled' do
it 'returns a backend with caching' do
opts = { command_runner: :generic, backend_cache: true }