inspec 0.32.0 → 0.33.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d4137116907e9d6bee7f88e2a1ec7c16372ee1c
4
- data.tar.gz: 0c88924d165b05a9765a940197c3b3e779ba09f1
3
+ metadata.gz: 42f6886e62266384a0c80c87121f10fd132465b7
4
+ data.tar.gz: 438402a4b269d0cd6a686eac3dc1a1b549d0333a
5
5
  SHA512:
6
- metadata.gz: e1016672adc6e043a2896ff1e78304f244d8f9ca7af64f8d85164e19c938916e0792df984f6c26d63d364ee03da385078d045235d42d4900704c19bec465bd25
7
- data.tar.gz: 894d6fd605277f8608296b3ff0afc2f9510e8e4a6b57dde9ed5cf740d4adaf3114e89a2efd54c734792382036b1a32417bb5bb496c126fe61a47a3e88d87ea18
6
+ metadata.gz: 0008350a540830d34d52e9ab650b82db771936613204b6c885a615b5398d5ce2f74ca7bf4500084d3b824ab71b8eb6d6b24a3e9d13f7e45daa933b6d84c55d6c
7
+ data.tar.gz: b333ca0a11b1ab87b357ac3e1294141f779cf1bc02e18a695d6002b52c1437e8b497cb3ccaa23e78600542d378b952ea01f4375c7122afc7f6e29d67bc2c1162
data/CHANGELOG.md CHANGED
@@ -1,7 +1,51 @@
1
1
  # Change Log
2
2
 
3
- ## [0.32.0](https://github.com/chef/inspec/tree/0.32.0) (2016-08-26)
4
- [Full Changelog](https://github.com/chef/inspec/compare/v0.31.0...0.32.0)
3
+ ## [0.33.0](https://github.com/chef/inspec/tree/0.33.0) (2016-09-05)
4
+ [Full Changelog](https://github.com/chef/inspec/compare/v0.32.0...0.33.0)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - Introduce scoping to the ProfileContext which has a view of all of its dependencies [\#958](https://github.com/chef/inspec/issues/958)
9
+ - Create Help for Subcommands [\#305](https://github.com/chef/inspec/issues/305)
10
+ - Allow service resource to accept Windows service name with spaces [\#1003](https://github.com/chef/inspec/pull/1003) ([martinheg](https://github.com/martinheg))
11
+
12
+ **Fixed bugs:**
13
+
14
+ - Error output not informative [\#1016](https://github.com/chef/inspec/issues/1016)
15
+ - Suse Linux Enterprise Server 11 SPX is failing for describe service resource. [\#997](https://github.com/chef/inspec/issues/997)
16
+ - Inspec Docker directory test fails [\#996](https://github.com/chef/inspec/issues/996)
17
+ - package\(\) 'version' {should match\(pattern\)} does not return failed control, but shows as failed test [\#898](https://github.com/chef/inspec/issues/898)
18
+ - Raise error when an invalid URI is received [\#1019](https://github.com/chef/inspec/pull/1019) ([alexpop](https://github.com/alexpop))
19
+ - Fix os exception in mysql resource [\#1012](https://github.com/chef/inspec/pull/1012) ([alexpop](https://github.com/alexpop))
20
+ - cmp not treating 0 as integer only as string [\#991](https://github.com/chef/inspec/pull/991) ([jeremymv2](https://github.com/jeremymv2))
21
+
22
+ **Closed issues:**
23
+
24
+ - apache\_conf resource seems to be using incorrect paths to amalgamate apache config \(only Centos/RHEL?\) [\#1013](https://github.com/chef/inspec/issues/1013)
25
+ - More options link in Readme.md doesn't work \(404\) - need updating? [\#1001](https://github.com/chef/inspec/issues/1001)
26
+ - Chef compliance breaks after updating inspec gem 0.32 [\#992](https://github.com/chef/inspec/issues/992)
27
+ - Improve CLI report [\#984](https://github.com/chef/inspec/issues/984)
28
+ - record inspec + in-browser playback for online demo [\#956](https://github.com/chef/inspec/issues/956)
29
+ - UX & UI design for the interactive HTML demo [\#953](https://github.com/chef/inspec/issues/953)
30
+
31
+ **Merged pull requests:**
32
+
33
+ - use winrm v2 [\#1018](https://github.com/chef/inspec/pull/1018) ([chris-rock](https://github.com/chris-rock))
34
+ - always display error message [\#1017](https://github.com/chef/inspec/pull/1017) ([chris-rock](https://github.com/chris-rock))
35
+ - Fix apache conf [\#1014](https://github.com/chef/inspec/pull/1014) ([jeremymv2](https://github.com/jeremymv2))
36
+ - fix cli inherited profiles [\#1008](https://github.com/chef/inspec/pull/1008) ([vjeffrey](https://github.com/vjeffrey))
37
+ - improve suse 11 support for service resource [\#1007](https://github.com/chef/inspec/pull/1007) ([chris-rock](https://github.com/chris-rock))
38
+ - Extend Inspec DSL docs [\#1006](https://github.com/chef/inspec/pull/1006) ([nvtkaszpir](https://github.com/nvtkaszpir))
39
+ - vj/fix cli report [\#1004](https://github.com/chef/inspec/pull/1004) ([vjeffrey](https://github.com/vjeffrey))
40
+ - fix cli link to docs [\#1002](https://github.com/chef/inspec/pull/1002) ([chris-rock](https://github.com/chris-rock))
41
+ - Promote cmp usage as it provides results with octal mode [\#999](https://github.com/chef/inspec/pull/999) ([alexpop](https://github.com/alexpop))
42
+ - Initial attempt at isolating resources between dependencies [\#994](https://github.com/chef/inspec/pull/994) ([stevendanna](https://github.com/stevendanna))
43
+ - inspec demo [\#989](https://github.com/chef/inspec/pull/989) ([vjeffrey](https://github.com/vjeffrey))
44
+ - Allow functional tests to pass on OSX [\#988](https://github.com/chef/inspec/pull/988) ([stevendanna](https://github.com/stevendanna))
45
+ - Minor refactor and explanatory comments [\#987](https://github.com/chef/inspec/pull/987) ([stevendanna](https://github.com/stevendanna))
46
+
47
+ ## [v0.32.0](https://github.com/chef/inspec/tree/v0.32.0) (2016-08-26)
48
+ [Full Changelog](https://github.com/chef/inspec/compare/v0.31.0...v0.32.0)
5
49
 
6
50
  **Implemented enhancements:**
7
51
 
data/Gemfile CHANGED
@@ -29,7 +29,8 @@ group :integration do
29
29
  gem 'berkshelf', '~> 4.3'
30
30
  gem 'test-kitchen', '~> 1.6'
31
31
  gem 'kitchen-vagrant'
32
- gem 'kitchen-inspec', '0.12.5'
32
+ # we need winrm v2 support >= 0.15.1
33
+ gem 'kitchen-inspec', '>= 0.15.1'
33
34
  gem 'kitchen-ec2'
34
35
  gem 'kitchen-dokken'
35
36
  end
data/README.md CHANGED
@@ -18,7 +18,7 @@ describe inetd_conf do
18
18
  end
19
19
  ```
20
20
 
21
- InSpec makes it easy to run your tests wherever you need. More options listed here: https://github.com/chef/inspec/blob/master/docs/ctl_inspec.rst
21
+ InSpec makes it easy to run your tests wherever you need. More options listed here: https://github.com/chef/inspec/blob/master/docs/cli.rst
22
22
 
23
23
  ```bash
24
24
  # run test locally
data/docs/dsl_inspec.rst CHANGED
@@ -192,7 +192,28 @@ The following test shows how to audit machines to ensure Safe DLL Seach Mode is
192
192
  end
193
193
  end
194
194
 
195
+ Exclude specific test
196
+ -----------------------------------------------------
197
+ This shows how to allow skipping certain tests if conditions are not met, by using ``only_if``.
198
+ In this example the test will not be performed if ``redis-cli`` command does not exist, because for example package on remote host was not installed.
199
+
200
+ .. code-block:: ruby
201
+
202
+ control 'nutcracker-connect-redis-001' do
203
+ impact 1.0
204
+ title 'Check if nutcracker can pass commands to redis'
205
+ desc 'execute redis-cli set key command, to check connectivity of the service'
206
+
207
+ only_if do
208
+ command('redis-cli').exist?
209
+ end
210
+
211
+ describe command('redis-cli SET test_inspec "HELLO"') do
212
+ its(:stdout) { should match(/OK/) }
213
+ end
214
+ end
195
215
 
216
+ Mixing this with other conditionals (like checking existence of the files etc.) can help to test different test paths using inspec. This way you can skip certain tests which would 100% fail due to the way servers are prepared, but you know that the same test suites are reused later in different circumstances by different teams.
196
217
 
197
218
  Additional metadata for controls
198
219
  -----------------------------------------------------
data/docs/resources.rst CHANGED
@@ -1308,7 +1308,7 @@ The ``mode`` matcher tests if the mode assigned to the file matches the specifie
1308
1308
 
1309
1309
  .. code-block:: ruby
1310
1310
 
1311
- its('mode') { should eq 0644 }
1311
+ its('mode') { should cmp '0644' }
1312
1312
 
1313
1313
  mtime
1314
1314
  +++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -1491,7 +1491,7 @@ The following examples show how to use this InSpec audit resource.
1491
1491
  .. code-block:: bash
1492
1492
 
1493
1493
  describe file('/dev') do
1494
- its('mode') { should eq 00755 }
1494
+ its('mode') { should cmp '00755' }
1495
1495
  end
1496
1496
 
1497
1497
  **Test the owner of a file**
@@ -4331,7 +4331,7 @@ The following examples show how to use this InSpec audit resource.
4331
4331
 
4332
4332
  describe ssh_config do
4333
4333
  its('owner') { should eq 'root' }
4334
- its('mode') { should eq 644 }
4334
+ its('mode') { should cmp '0644' }
4335
4335
  end
4336
4336
 
4337
4337
  **Test SSH configuration**
data/docs/ruby_usage.rst CHANGED
@@ -38,7 +38,7 @@ The following example shows how you can use pure |ruby| code(variables, loops, c
38
38
  # check key file owners and permissions
39
39
  describe file(intern['key']) do
40
40
  it { should be_owned_by username }
41
- its('mode') { should eq 0600 }
41
+ its('mode') { should cmp '0600' }
42
42
  end
43
43
  end
44
44
  end
data/inspec.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
25
  spec.require_paths = ['lib']
26
26
 
27
- spec.add_dependency 'train', '>=0.16.0', '<1.0'
27
+ spec.add_dependency 'train', '>=0.19.0', '<1.0'
28
28
  spec.add_dependency 'thor', '~> 0.19'
29
29
  spec.add_dependency 'json', '>= 1.8', '< 3.0'
30
30
  spec.add_dependency 'rainbow', '~> 2'
@@ -41,6 +41,7 @@ module Compliance
41
41
  # post a file
42
42
  def self.post_file(url, token, file_path, insecure, basic_auth = false)
43
43
  uri = URI.parse(url)
44
+ fail "Unable to parse URL: #{url}" if uri.nil? || uri.host.nil?
44
45
  http = Net::HTTP.new(uri.host, uri.port)
45
46
 
46
47
  # set connection flags
@@ -71,6 +72,7 @@ module Compliance
71
72
  }
72
73
  opts[:verify_mode] = OpenSSL::SSL::VERIFY_NONE if insecure
73
74
 
75
+ fail "Unable to parse URI: #{uri}" if uri.nil? || uri.host.nil?
74
76
  res = Net::HTTP.start(uri.host, uri.port, opts) {|http|
75
77
  http.request(req)
76
78
  }
@@ -70,7 +70,7 @@ module Inspec
70
70
  o[:logger].level = get_log_level(o.log_level)
71
71
 
72
72
  runner = Inspec::Runner.new(o)
73
- targets.each { |target| runner.add_target(target, opts) }
73
+ targets.each { |target| runner.add_target(target) }
74
74
  exit runner.run
75
75
  rescue RuntimeError, Train::UserError => e
76
76
  $stderr.puts e.message
@@ -0,0 +1,145 @@
1
+ # encoding: utf-8
2
+ # author: Dominik Richter
3
+ # author: Christoph Hartmann
4
+ require 'inspec/dsl'
5
+ require 'inspec/dsl_shared'
6
+
7
+ module Inspec
8
+ #
9
+ # ControlEvalContext constructs an anonymous class that control
10
+ # files will be instance_exec'd against.
11
+ #
12
+ # The anonymous class includes the given passed resource_dsl as well
13
+ # as the basic DSL of the control files (describe, control, title,
14
+ # etc).
15
+ #
16
+ class ControlEvalContext
17
+ # Create the context for controls. This includes all components of the DSL,
18
+ # including matchers and resources.
19
+ #
20
+ # @param [ResourcesDSL] resources_dsl which has all resources to attach
21
+ # @return [RuleContext] the inner context of rules
22
+ def self.rule_context(resources_dsl)
23
+ require 'rspec/core/dsl'
24
+ Class.new(Inspec::Rule) do
25
+ include RSpec::Core::DSL
26
+ include resources_dsl
27
+ end
28
+ end
29
+
30
+ # Creates the heart of the control eval context:
31
+ #
32
+ # An instantiated object which has all resources registered to it
33
+ # and exposes them to the a test file.
34
+ #
35
+ # @param profile_context [Inspec::ProfileContext]
36
+ # @param outer_dsl [OuterDSLClass]
37
+ # @return [ProfileContextClass]
38
+ #
39
+ # rubocop:disable Lint/NestedMethodDefinition
40
+ def self.create(profile_context, resources_dsl) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
41
+ rule_class = rule_context(resources_dsl)
42
+ profile_context_owner = profile_context
43
+ profile_id = profile_context.profile_id
44
+
45
+ Class.new do
46
+ include Inspec::DSL
47
+ include Inspec::DSL::RequireOverride
48
+ include resources_dsl
49
+
50
+ def initialize(backend, conf, dependencies, require_loader)
51
+ @backend = backend
52
+ @conf = conf
53
+ @dependencies = dependencies
54
+ @require_loader = require_loader
55
+ @skip_profile = false
56
+ end
57
+
58
+ define_method :title do |arg|
59
+ profile_context_owner.set_header(:title, arg)
60
+ end
61
+
62
+ def to_s
63
+ "Control Evaluation Context (#{profile_name})"
64
+ end
65
+
66
+ define_method :profile_name do
67
+ profile_id
68
+ end
69
+
70
+ define_method :control do |*args, &block|
71
+ id = args[0]
72
+ opts = args[1] || {}
73
+ register_control(rule_class.new(id, profile_id, opts, &block))
74
+ end
75
+
76
+ #
77
+ # Describe allows users to write rspec-like bare describe
78
+ # blocks without declaring an inclosing control. Here, we
79
+ # generate a control for them automatically and then execute
80
+ # the describe block in the context of that control.
81
+ #
82
+ define_method :describe do |*args, &block|
83
+ loc = block_location(block, caller[0])
84
+ id = "(generated from #{loc} #{SecureRandom.hex})"
85
+
86
+ res = nil
87
+ rule = rule_class.new(id, profile_id, {}) do
88
+ res = describe(*args, &block)
89
+ end
90
+ register_control(rule, &block)
91
+
92
+ res
93
+ end
94
+
95
+ define_method :add_resources do |context|
96
+ self.class.class_eval do
97
+ include context.to_resources_dsl
98
+ end
99
+
100
+ rule_class.class_eval do
101
+ include context.to_resources_dsl
102
+ end
103
+ end
104
+
105
+ define_method :add_subcontext do |context|
106
+ profile_context_owner.add_subcontext(context)
107
+ end
108
+
109
+ define_method :register_control do |control, &block|
110
+ ::Inspec::Rule.set_skip_rule(control, true) if @skip_profile
111
+
112
+ profile_context_owner.register_rule(control, &block) unless control.nil?
113
+ end
114
+
115
+ # method for attributes; import attribute handling
116
+ define_method :attribute do |name, options|
117
+ profile_context_owner.register_attribute(name, options)
118
+ end
119
+
120
+ define_method :skip_control do |id|
121
+ profile_context_owner.unregister_rule(id)
122
+ end
123
+
124
+ def only_if
125
+ return unless block_given?
126
+ @skip_profile ||= !yield
127
+ end
128
+
129
+ alias_method :rule, :control
130
+ alias_method :skip_rule, :skip_control
131
+
132
+ private
133
+
134
+ def block_location(block, alternate_caller)
135
+ if block.nil?
136
+ alternate_caller[/^(.+:\d+):in .+$/, 1] || 'unknown'
137
+ else
138
+ path, line = block.source_location
139
+ "#{File.basename(path)}:#{line}"
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
@@ -18,14 +18,22 @@ module Inspec
18
18
  # @param cwd [String] Current working directory for relative path includes
19
19
  # @param vendor_path [String] Path to the vendor directory
20
20
  #
21
- def self.from_lockfile(lockfile, cwd, vendor_path)
21
+ def self.from_lockfile(lockfile, cwd, vendor_path, backend)
22
22
  vendor_index = VendorIndex.new(vendor_path)
23
23
  dep_tree = lockfile.deps.map do |dep|
24
- Inspec::Requirement.from_lock_entry(dep, cwd, vendor_index)
24
+ Inspec::Requirement.from_lock_entry(dep, cwd, vendor_index, backend)
25
25
  end
26
26
 
27
27
  dep_list = flatten_dep_tree(dep_tree)
28
- new(cwd, vendor_path, dep_list)
28
+ new(cwd, vendor_path, dep_list, backend)
29
+ end
30
+
31
+ def self.from_array(dependencies, cwd, vendor_path, backend)
32
+ dep_list = {}
33
+ dependencies.each do |d|
34
+ dep_list[d.name] = d
35
+ end
36
+ new(cwd, vendor_path, dep_list, backend)
29
37
  end
30
38
 
31
39
  # This is experimental code to test the working of the
@@ -50,14 +58,21 @@ module Inspec
50
58
  # @param cwd [String] current working directory for relative path includes
51
59
  # @param vendor_path [String] path which contains vendored dependencies
52
60
  # @return [dependencies] this
53
- def initialize(cwd, vendor_path, dep_list = nil)
61
+ def initialize(cwd, vendor_path, dep_list, backend)
54
62
  @cwd = cwd
55
63
  @vendor_path = vendor_path
56
64
  @dep_list = dep_list
65
+ @backend = backend
66
+ end
67
+
68
+ def each
69
+ @dep_list.each do |_k, v|
70
+ yield v.profile
71
+ end
57
72
  end
58
73
 
59
74
  def list
60
- @dep_list
75
+ @dep_list || {}
61
76
  end
62
77
 
63
78
  def to_array
@@ -77,7 +92,7 @@ module Inspec
77
92
  def vendor(dependencies)
78
93
  return nil if dependencies.nil? || dependencies.empty?
79
94
  @vendor_index ||= VendorIndex.new(@vendor_path)
80
- @dep_list = Resolver.resolve(dependencies, @vendor_index, @cwd)
95
+ @dep_list = Resolver.resolve(dependencies, @vendor_index, @cwd, @backend)
81
96
  end
82
97
  end
83
98
  end
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require 'inspec/fetcher'
3
+ require 'inspec/dependencies/dependency_set'
3
4
  require 'digest'
4
5
 
5
6
  module Inspec
@@ -18,17 +19,18 @@ module Inspec
18
19
  new(name, version, vendor_index, opts[:cwd], opts.merge(dep))
19
20
  end
20
21
 
21
- def self.from_lock_entry(entry, cwd, vendor_index)
22
+ def self.from_lock_entry(entry, cwd, vendor_index, backend)
22
23
  req = new(entry['name'],
23
24
  entry['version_constraints'],
24
25
  vendor_index,
25
- cwd, { url: entry['resolved_source'] })
26
+ cwd,
27
+ { url: entry['resolved_source'],
28
+ backend: backend })
26
29
 
27
30
  locked_deps = []
28
31
  Array(entry['dependencies']).each do |dep_entry|
29
- locked_deps << Inspec::Requirement.from_lock_entry(dep_entry, cwd, vendor_index)
32
+ locked_deps << Inspec::Requirement.from_lock_entry(dep_entry, cwd, vendor_index, backend)
30
33
  end
31
-
32
34
  req.lock_deps(locked_deps)
33
35
  req
34
36
  end
@@ -38,6 +40,7 @@ module Inspec
38
40
  @version_requirement = Gem::Requirement.new(Array(version_constraints))
39
41
  @dep = Gem::Dependency.new(name, @version_requirement, :runtime)
40
42
  @vendor_index = vendor_index
43
+ @backend = opts[:backend]
41
44
  @opts = opts
42
45
  @cwd = cwd
43
46
  end
@@ -123,7 +126,7 @@ module Inspec
123
126
 
124
127
  def dependencies
125
128
  @dependencies ||= profile.metadata.dependencies.map do |r|
126
- Inspec::Requirement.from_metadata(r, @vendor_index, cwd: @cwd)
129
+ Inspec::Requirement.from_metadata(r, @vendor_index, cwd: @cwd, backend: @backend)
127
130
  end
128
131
  end
129
132
 
@@ -137,7 +140,11 @@ module Inspec
137
140
 
138
141
  def profile
139
142
  return nil if path.nil?
140
- @profile ||= Inspec::Profile.for_target(path, {})
143
+ opts = { backend: @backend }
144
+ if !@dependencies.nil?
145
+ opts[:dependencies] = Inspec::DependencySet.from_array(@dependencies, @cwd, @vendor_index, @backend)
146
+ end
147
+ @profile ||= Inspec::Profile.for_target(path, opts)
141
148
  end
142
149
  end
143
150
  end