inspec 2.0.45 → 2.1.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: 40edce262924f3f1fe00a6a1e1cbf8cc267da999
4
- data.tar.gz: 2237b160408045985a93f5d94d8a0927a4789d94
3
+ metadata.gz: 184c03135e14f8d3cf287e8fed443c9fda98953a
4
+ data.tar.gz: 5d55d1635cd382e22a0f5114137549b43d63cefb
5
5
  SHA512:
6
- metadata.gz: 9163df9d3744f72ff545af91d1a210072475a28fe9709bf0781a1fab5dbd581309b2ad6d92fb8c633958f2454c93cd202b655ef11550929711a403e0ba459545
7
- data.tar.gz: 664a5975bc23a0241aa33e4d62558bdf6d7975ea1be1f5d5ef72ee1cacc452e0c37ef4ad50af9c8584b942b2530702bc0d96ead203c11fad80844b1862d56792
6
+ metadata.gz: 2996dd2613e5f390a2f1e4faefb61cde1c758222ea11b30f591526aa15412b6ad613b26464065dd114900749c5352f9856e6344fcbab02a4d8c66a938290533e
7
+ data.tar.gz: 7f42ef8a7a61e277c85d6db8302f9ade44f21a2ebbf94ebef118e2bdd39013754e610b89d68c936d524452e4abcb93b2151af76983063feb15d8354a17f78b45
@@ -1,36 +1,50 @@
1
1
  # Change Log
2
2
  <!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ -->
3
- <!-- latest_release 2.0.45 -->
4
- ## [v2.0.45](https://github.com/chef/inspec/tree/v2.0.45) (2018-03-08)
3
+ <!-- latest_release 2.1.0 -->
4
+ ## [v2.1.0](https://github.com/chef/inspec/tree/v2.1.0) (2018-03-15)
5
5
 
6
6
  #### Enhancements
7
- - Refine deprecated methods to be consistent with supported fields in shadow file. [#2801](https://github.com/chef/inspec/pull/2801) ([miah](https://github.com/miah))
7
+ - Pin to new Train version and update InSpec defaults [#2827](https://github.com/chef/inspec/pull/2827) ([jquick](https://github.com/jquick))
8
8
  <!-- latest_release -->
9
9
 
10
- <!-- release_rollup since=2.0.32 -->
11
- ### Changes since 2.0.32 release
10
+ <!-- release_rollup since=2.0.45 -->
11
+ ### Changes since 2.0.45 release
12
+
13
+ #### Bug Fixes
14
+ - Write version_constraints as an array for inspec.lock [#2619](https://github.com/chef/inspec/pull/2619) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 2.0.48 -->
15
+
16
+ #### Enhancements
17
+ - Pin to new Train version and update InSpec defaults [#2827](https://github.com/chef/inspec/pull/2827) ([jquick](https://github.com/jquick)) <!-- 2.1.0 -->
18
+ - quote password when generating mysql command string [#2685](https://github.com/chef/inspec/pull/2685) ([tolland](https://github.com/tolland)) <!-- 2.0.47 -->
12
19
 
13
20
  #### Merged Pull Requests
14
- - Added the missing variable reference [#2794](https://github.com/chef/inspec/pull/2794) ([frezbo](https://github.com/frezbo)) <!-- 2.0.42 -->
15
- - iptables resource: Add support for other bin paths [#2783](https://github.com/chef/inspec/pull/2783) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 2.0.37 -->
16
- - Update name of subnet fixture, fixing 3 failing integration tests [#2765](https://github.com/chef/inspec/pull/2765) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.0.36 -->
21
+ - Sort file list for unit tests [#2812](https://github.com/chef/inspec/pull/2812) ([eramoto](https://github.com/eramoto)) <!-- 2.0.49 -->
22
+ - Docs: Describe support boundary between RSpec and InSpec [#2753](https://github.com/chef/inspec/pull/2753) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.0.46 -->
23
+ <!-- release_rollup -->
24
+
25
+ <!-- latest_stable_release -->
26
+ ## [v2.0.45](https://github.com/chef/inspec/tree/v2.0.45) (2018-03-08)
17
27
 
18
28
  #### Enhancements
19
- - Refine deprecated methods to be consistent with supported fields in shadow file. [#2801](https://github.com/chef/inspec/pull/2801) ([miah](https://github.com/miah)) <!-- 2.0.45 -->
20
- - Remove os checks from initialize [#2797](https://github.com/chef/inspec/pull/2797) ([miah](https://github.com/miah)) <!-- 2.0.44 -->
21
- - Create reporter output directory if it does not exist [#2798](https://github.com/chef/inspec/pull/2798) ([jquick](https://github.com/jquick)) <!-- 2.0.43 -->
22
- - Update shadow resource to use FilterTable [#2642](https://github.com/chef/inspec/pull/2642) ([miah](https://github.com/miah)) <!-- 2.0.39 -->
23
- - Host resource: use bash over netcat in Linux [#2607](https://github.com/chef/inspec/pull/2607) ([jvale](https://github.com/jvale)) <!-- 2.0.38 -->
24
- - AWS API Pagination fixes [#2762](https://github.com/chef/inspec/pull/2762) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.0.35 -->
25
- - Fix aws-iam-users pagination [#2761](https://github.com/chef/inspec/pull/2761) ([trickyearlobe](https://github.com/trickyearlobe)) <!-- 2.0.34 -->
29
+ - Fix aws-iam-users pagination [#2761](https://github.com/chef/inspec/pull/2761) ([trickyearlobe](https://github.com/trickyearlobe))
30
+ - AWS API Pagination fixes [#2762](https://github.com/chef/inspec/pull/2762) ([clintoncwolfe](https://github.com/clintoncwolfe))
31
+ - Host resource: use bash over netcat in Linux [#2607](https://github.com/chef/inspec/pull/2607) ([jvale](https://github.com/jvale))
32
+ - Update shadow resource to use FilterTable [#2642](https://github.com/chef/inspec/pull/2642) ([miah](https://github.com/miah))
33
+ - Create reporter output directory if it does not exist [#2798](https://github.com/chef/inspec/pull/2798) ([jquick](https://github.com/jquick))
34
+ - Remove os checks from initialize [#2797](https://github.com/chef/inspec/pull/2797) ([miah](https://github.com/miah))
35
+ - Refine deprecated methods to be consistent with supported fields in shadow file. [#2801](https://github.com/chef/inspec/pull/2801) ([miah](https://github.com/miah))
26
36
 
27
37
  #### Bug Fixes
28
- - Fix http with connection error [#2770](https://github.com/chef/inspec/pull/2770) ([Wing924](https://github.com/Wing924)) <!-- 2.0.41 -->
29
- - return 1 as exit code for commands that are not available [#2792](https://github.com/chef/inspec/pull/2792) ([chris-rock](https://github.com/chris-rock)) <!-- 2.0.40 -->
30
- - command resource: Add `exist?` for Alpine Linux [#2768](https://github.com/chef/inspec/pull/2768) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 2.0.33 -->
31
- <!-- release_rollup -->
38
+ - command resource: Add `exist?` for Alpine Linux [#2768](https://github.com/chef/inspec/pull/2768) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
39
+ - return 1 as exit code for commands that are not available [#2792](https://github.com/chef/inspec/pull/2792) ([chris-rock](https://github.com/chris-rock))
40
+ - Fix http with connection error [#2770](https://github.com/chef/inspec/pull/2770) ([Wing924](https://github.com/Wing924))
32
41
 
42
+ #### Merged Pull Requests
43
+ - Update name of subnet fixture, fixing 3 failing integration tests [#2765](https://github.com/chef/inspec/pull/2765) ([clintoncwolfe](https://github.com/clintoncwolfe))
44
+ - iptables resource: Add support for other bin paths [#2783](https://github.com/chef/inspec/pull/2783) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
45
+ - Added the missing variable reference [#2794](https://github.com/chef/inspec/pull/2794) ([frezbo](https://github.com/frezbo))
33
46
  <!-- latest_stable_release -->
47
+
34
48
  ## [v2.0.32](https://github.com/chef/inspec/tree/v2.0.32) (2018-03-01)
35
49
 
36
50
  #### Bug Fixes
@@ -51,7 +65,6 @@
51
65
  - virtualization_resource: Fix `NoMethodError` on `nil:NilClass` [#2603](https://github.com/chef/inspec/pull/2603) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
52
66
  - Docs: Clarify Matchers page to speak about Universal matchers [#2754](https://github.com/chef/inspec/pull/2754) ([clintoncwolfe](https://github.com/clintoncwolfe))
53
67
  - mssql_session - Handling cases where the data is nil [#2752](https://github.com/chef/inspec/pull/2752) ([frezbo](https://github.com/frezbo))
54
- <!-- latest_stable_release -->
55
68
 
56
69
  ## [v2.0.17](https://github.com/chef/inspec/tree/v2.0.17) (2018-02-20)
57
70
 
@@ -107,7 +107,7 @@ The following test shows how to audit machines running PostgreSQL to ensure that
107
107
  ```ruby
108
108
  control 'postgres-7' do
109
109
  impact 1.0
110
- title 'Don't allow empty passwords'
110
+ title "Don't allow empty passwords"
111
111
  describe postgres_session('user', 'pass').query("SELECT * FROM pg_shadow WHERE passwd IS NULL;") do
112
112
  its('output') { should eq('') }
113
113
  end
@@ -9,8 +9,8 @@ relate to each other.
9
9
 
10
10
  ## RSpec
11
11
 
12
- RSpec is an awesome framework that is widely used to test Ruby code. It
13
- enables test-driven development (TDD) and helps developers to write
12
+ RSpec is an awesome framework that is widely used by software engineers to test
13
+ Ruby code. It enables test-driven development (TDD) and helps developers to write
14
14
  better code every day.
15
15
 
16
16
  InSpec is built on top of RSpec and uses it as the underlying foundation
@@ -40,6 +40,13 @@ control "sshd-11" do
40
40
  end
41
41
  ```
42
42
 
43
+ That said, InSpec is not RSpec. Some key differences:
44
+
45
+ * In InSpec, `describe` blocks should not be nested; instead use `control` blocks to describe a higher-level grouping of tests.
46
+ * The RSpec `shared_example` construct is not supported. Instead, create a simple custom resource that executes repetitious tasks.
47
+ * InSpec is aimed at compliance practitioners and infrastructure testers, so our focus is providing a few, well-supported, easy-to-use [universal matchers](https://www.inspec.io/docs/reference/matchers/), such as `cmp`. In contrast, RSpec is a tool designed for software engineers. It thus supports a very large range of matchers, to enable testing of software engineering constructs such as exceptions, Object Oriented Programming relationships, and so on.
48
+ * While InSpec uses parts of the RSpec project and codebase, it is a separate project from InSpec. Rspec's release schedule and feature set are beyond the control of the InSpec team. While it is possible to use many of the RSpec core features within InSpec profiles, InSpec can only guarantee that the features described at [docs.inspec.io](https://docs.inspec.io) will function correctly. Some RSpec core functionality may be removed in future versions of InSpec as needed to ensure stability in the InSpec project.
49
+
43
50
  ## Serverspec
44
51
 
45
52
  Serverspec is the first extension of RSpec that enabled
@@ -18,7 +18,7 @@ The following InSpec-supported universal matchers are available:
18
18
  * [`include`](#include) - look for an expected value in a list-valued property
19
19
  * [`match`](#match) - look for patterns in text using regular expressions
20
20
 
21
- <br>
21
+ See [Explore InSpec resources](https://learn.chef.io/modules/explore-inspec-resources#/) on Learn Chef Rally to learn more about InSpec's built-in matchers.
22
22
 
23
23
  ## be
24
24
 
@@ -47,3 +47,4 @@ Use InSpec tests from the local file system:
47
47
  inspec_tests:
48
48
  - test/integration/default
49
49
 
50
+ Check out [Detect and correct with Test Kitchen](https://learn.chef.io/modules/detect-correct-kitchen#/) on Learn Chef Rally for a hands-on look at how to use Test Kitchen to run InSpec profiles.
@@ -29,7 +29,9 @@ where:
29
29
  * `files` is the directory with additional files that a profile can access (optional)
30
30
  * `README.md` should be used to explain the profile, its scope, and usage
31
31
 
32
- See a complete example profile in the InSpec open source repository: https://github.com/chef/inspec/tree/master/examples/profile
32
+ See a complete example profile in the InSpec open source repository: [https://github.com/chef/inspec/tree/master/examples/profile](https://github.com/chef/inspec/tree/master/examples/profile)
33
+
34
+ Also check out [Explore InSpec resources](https://learn.chef.io/modules/explore-inspec-resources#/) on Learn Chef Rally to learn more about how profiles are structured with hands-on examples.
33
35
 
34
36
  ## inspec.yml
35
37
 
@@ -111,6 +113,8 @@ and to target all of these examples in a single `inspec.yml` file:
111
113
 
112
114
  An InSpec profile can bring in the controls and custom resources from another InSpec profile. Additionally, when inheriting the controls of another profile, a profile can skip or even modify those included controls.
113
115
 
116
+ For hands-on examples, check out [Create a custom InSpec profile](https://learn.chef.io/modules/create-a-custom-profile#/) on Learn Chef Rally.
117
+
114
118
  ## Defining the Dependencies
115
119
 
116
120
  Before a profile can use controls from another profile, the to-be-included profile needs to be specified in the including profile’s `inspec.yml` file in the `depends` section. For each profile to be included, a location for the profile from where to be fetched and a name for the profile should be included. For example:
@@ -298,7 +302,7 @@ See the full example in the InSpec open source repository: https://github.com/ch
298
302
 
299
303
  # Profile files
300
304
 
301
- An InSpec profile may contain additional files that can be accessed during tests. This covers use-cases where e.g. a list of ports is provided to be tested.
305
+ An InSpec profile may contain additional files that can be accessed during tests. A profile file enables you to separate the logic of your tests from the data your tests check for, for example, the list of ports you require to be open.
302
306
 
303
307
  To access these files, they must be stored in the `files` directory at the root of a profile. They are accessed by their name relative to this folder with `inspec.profile.file(...)`.
304
308
 
@@ -332,6 +336,8 @@ The tests in `example.rb` can now access this file:
332
336
  end
333
337
  end
334
338
 
339
+ For a more complete example that uses a profile file, see [Explore InSpec resources](https://learn.chef.io/modules/explore-inspec-resources#/) on Learn Chef Rally.
340
+
335
341
  # "should" vs. "expect" syntax
336
342
 
337
343
  Users familiar with the RSpec testing framework may know that there are two ways to write test statements: `should` and `expect`. The RSpec community decided that `expect` is the preferred syntax. However, InSpec recommends the `should` syntax as it tends to read more easily to those users who are not as technical.
@@ -139,7 +139,7 @@ Or execute the profile directly via URL:
139
139
 
140
140
  ### images
141
141
 
142
- `images` returns information about Docker image as returned by [docker images](https://docs.docker.com/engine/reference/commandline/images/).
142
+ `images` returns information about a Docker image as returned by [docker images](https://docs.docker.com/engine/reference/commandline/images/).
143
143
 
144
144
  describe docker.images do
145
145
  its('ids') { should include 'sha:12b5df59...442b' }
@@ -183,9 +183,9 @@ Or execute the profile directly via URL:
183
183
 
184
184
  ### image
185
185
 
186
- describe docker_container(name: 'an-echo-server') do
187
- its('image') { should eq 'busybox:latest' }
188
- end
186
+ describe docker_container(name: 'an-echo-server') do
187
+ its('image') { should eq 'busybox:latest' }
188
+ end
189
189
 
190
190
  ### repo
191
191
 
@@ -5,7 +5,7 @@ platform: linux
5
5
 
6
6
  # docker_container
7
7
 
8
- Use the `docker_container` InSpec audit resource to test a docker container.
8
+ Use the `docker_container` InSpec audit resource to test a Docker container.
9
9
 
10
10
  <br>
11
11
 
@@ -72,7 +72,7 @@ The `tag` property tests the value of the image tag:
72
72
 
73
73
  ### ports
74
74
 
75
- The `ports` property tests the value the docker ports:
75
+ The `ports` property tests the value the Docker ports:
76
76
 
77
77
  its('ports') { should eq '0.0.0.0:1234->1234/tcp' }
78
78
 
@@ -101,4 +101,3 @@ The `command` property tests the value of the container run command:
101
101
  ## Matchers
102
102
 
103
103
  For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
104
-
@@ -5,7 +5,7 @@ platform: linux
5
5
 
6
6
  # docker_image
7
7
 
8
- Use the `docker_image` InSpec audit resource to verify a docker image.
8
+ Use the `docker_image` InSpec audit resource to verify a Docker image.
9
9
 
10
10
  <br>
11
11
 
@@ -70,7 +70,7 @@ The `tag` property tests the value of image tag:
70
70
 
71
71
  its('tag') { should eq 'latest' }
72
72
 
73
- ### Test a docker image
73
+ ### Test a Docker image
74
74
 
75
75
  describe docker_image('alpine:latest') do
76
76
  it { should exist }
@@ -13,7 +13,7 @@ Use the `os` InSpec audit resource to test the platform on which the system is r
13
13
 
14
14
  An `os` resource block declares the platform to be tested. The platform may specified via matcher or control block name. For example, using a matcher:
15
15
 
16
- describe os[:family] do
16
+ describe os.family do
17
17
  it { should eq 'platform_family_name' }
18
18
  end
19
19
 
@@ -33,19 +33,19 @@ The following examples show how to use this InSpec audit resource.
33
33
 
34
34
  ### Test for RedHat
35
35
 
36
- describe os[:family] do
36
+ describe os.family do
37
37
  it { should eq 'redhat' }
38
38
  end
39
39
 
40
40
  ### Test for Ubuntu
41
41
 
42
- describe os[:family] do
42
+ describe os.family do
43
43
  it { should eq 'debian' }
44
44
  end
45
45
 
46
46
  ### Test for Microsoft Windows
47
47
 
48
- describe os[:family] do
48
+ describe os.family do
49
49
  it { should eq 'windows' }
50
50
  end
51
51
 
@@ -103,28 +103,28 @@ Use the following helpers to test for operating system names, releases, and arch
103
103
  it { should eq 'foo' }
104
104
  end
105
105
 
106
- ### os[:family] Symbols
106
+ ### os.family names
107
107
 
108
- Use `os[:family]` to enable more granular testing of platforms, platform names, architectures, and releases. Use any of the following platform-specific symbols to test for specific platforms:
108
+ Use `os.family` to enable more granular testing of platforms, platform names, architectures, and releases. Use any of the following platform-specific names to test for specific platforms:
109
109
 
110
- * `:aix`
111
- * `:bsd` For platforms that are part of the Berkeley OS family: `:darwin`, `:freebsd`, `:netbsd`, and `:openbsd`.
112
- * `:debian`
113
- * `:hpux`
114
- * `:linux`. For platforms that are part of the Linux family: `:alpine`, `:amazon`, `:arch`, `:coreos`, `:exherbo`, `:fedora`, `:gentoo`, and `:slackware`.
115
- * `:redhat`. For platforms that are part of the Redhat family: `:centos`.
116
- * `:solaris`. For platforms that are part of the Solaris family: `:nexentacore`, `:omnios`, `:openindiana`, `:opensolaris`, and `:smartos`.
117
- * `:suse`
118
- * `:unix`
119
- * `:windows`
110
+ * `aix`
111
+ * `bsd` For platforms that are part of the Berkeley OS family `darwin`, `freebsd`, `netbsd`, and `openbsd`.
112
+ * `debian`
113
+ * `hpux`
114
+ * `linux`. For platforms that are part of the Linux family `alpine`, `amazon`, `arch`, `coreos`, `exherbo`, `fedora`, `gentoo`, and `slackware`.
115
+ * `redhat`. For platforms that are part of the Redhat family `centos`.
116
+ * `solaris`. For platforms that are part of the Solaris family `nexentacore`, `omnios`, `openindiana`, `opensolaris`, and `smartos`.
117
+ * `suse`
118
+ * `unix`
119
+ * `windows`
120
120
 
121
121
  For example, both of the following tests should have the same result:
122
122
 
123
- if os[:family] == 'debian'
123
+ if os.family == 'debian'
124
124
  describe port(69) do
125
125
  its('processes') { should include 'in.tftpd' }
126
126
  end
127
- elsif os[:family] == 'redhat'
127
+ elsif os.family == 'redhat'
128
128
  describe port(69) do
129
129
  its('processes') { should include 'xinetd' }
130
130
  end
@@ -6,12 +6,14 @@ title: InSpec Shell
6
6
 
7
7
  The InSpec interactive shell is a pry based REPL that can be used to
8
8
  quickly run InSpec controls and tests without having to write it to a
9
- file. Its functionality is similar to `chef shell` - it provides a way
10
- to exercise the InSpec DSL, its resources, tests and plugins without
9
+ file. Its functionality is similar to [chef-shell](https://docs.chef.io/chef_shell.html) as it provides a way
10
+ to exercise the InSpec DSL, its resources, tests, and plugins without
11
11
  having to create a profile or write a test file. See
12
12
  [http://pryrepl.org/](http://pryrepl.org/) for an introduction to what pry is and what it can
13
13
  do.
14
14
 
15
+ See [Explore InSpec resources](https://learn.chef.io/modules/explore-inspec-resources#/) on Learn Chef Rally for a hands-on example that uses InSpec shell.
16
+
15
17
  ## Launching the shell
16
18
 
17
19
  If you are using InSpec from a platform-specific package (rpm, msi,
@@ -25,10 +27,10 @@ $ inspec help shell # This will describe inspec shell usage
25
27
  ```
26
28
 
27
29
  If you wish to connect to a remote machine (called a target within
28
- InSpec), you can use the `-t` flag. We support connecting using ssh,
29
- WinRm and Docker. If no target is provided, we implicitly support the
30
+ InSpec), you can use the `-t` flag. We support connecting using SSH,
31
+ WinRM and docker. If no target is provided, we implicitly support the
30
32
  "local" target - i.e. tests running on the current machine running
31
- InSpec. For an ssh connection, use `-i` for specifying ssh key files,
33
+ InSpec. For an SSH connection, use `-i` for specifying SSH key files,
32
34
  and the `--sudo*` commands for requesting a privilege escalation after
33
35
  logging in. For a WinRM connection, use `--path` to change the login
34
36
  path, `--ssl` to use SSL for transport layer encryption.
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.required_ruby_version = '>= 2.3'
28
28
 
29
- spec.add_dependency 'train', '~> 1.1'
29
+ spec.add_dependency 'train', '~> 1.2'
30
30
  spec.add_dependency 'thor', '~> 0.19'
31
31
  spec.add_dependency 'json', '>= 1.8', '< 3.0'
32
32
  spec.add_dependency 'method_source', '~> 0.8'
@@ -65,6 +65,7 @@ module Inspec
65
65
  connection.disable_cache(:command)
66
66
  else
67
67
  Inspec::Log.debug 'Option backend_cache is disabled'
68
+ connection.disable_cache(:file)
68
69
  connection.disable_cache(:command)
69
70
  end
70
71
 
@@ -76,7 +76,7 @@ module Inspec
76
76
  option :create_lockfile, type: :boolean,
77
77
  desc: 'Write out a lockfile based on this execution (unless one already exists)'
78
78
  option :backend_cache, type: :boolean,
79
- desc: 'Allow caching for backend command output.'
79
+ desc: 'Allow caching for backend command output. (default: true)'
80
80
  option :show_progress, type: :boolean,
81
81
  desc: 'Show progress while executing tests.'
82
82
  end
@@ -88,7 +88,7 @@ module Inspec
88
88
  'show_progress' => false,
89
89
  'color' => true,
90
90
  'create_lockfile' => true,
91
- 'backend_cache' => false,
91
+ 'backend_cache' => true,
92
92
  },
93
93
  shell: {
94
94
  'reporter' => ['cli'],
@@ -80,7 +80,7 @@ module Inspec
80
80
  h = {
81
81
  'name' => name,
82
82
  'resolved_source' => resolved_source,
83
- 'version_constraints' => version_constraints.to_s,
83
+ 'version_constraints' => version_constraints,
84
84
  }
85
85
 
86
86
  if !dependencies.empty?
@@ -4,5 +4,5 @@
4
4
  # author: Christoph Hartmann
5
5
 
6
6
  module Inspec
7
- VERSION = '2.0.45'
7
+ VERSION = '2.1.0'
8
8
  end
@@ -1,6 +1,8 @@
1
1
  # encoding: utf-8
2
2
  # copyright: 2015, Vulcano Security GmbH
3
3
 
4
+ require 'shellwords'
5
+
4
6
  module Inspec::Resources
5
7
  class MysqlSession < Inspec.resource(1)
6
8
  name 'mysql_session'
@@ -25,21 +27,8 @@ module Inspec::Resources
25
27
  end
26
28
 
27
29
  def query(q, db = '')
28
- # TODO: simple escape, must be handled by a library
29
- # that does this securely
30
- escaped_query = q.gsub(/\\/, '\\\\').gsub(/"/, '\\"').gsub(/\$/, '\\$')
31
-
32
- # run the query
33
- command = "mysql -u#{@user} -p#{@pass}"
34
- if !@socket.nil?
35
- command += " -S #{@socket}"
36
- else
37
- command += " -h #{@host}"
38
- end
39
- command += " --port #{@port}" unless @port.nil?
40
- command += " #{db} -s -e \"#{escaped_query}\""
41
-
42
- cmd = inspec.command(command)
30
+ mysql_cmd = create_mysql_cmd(q, db)
31
+ cmd = inspec.command(mysql_cmd)
43
32
  out = cmd.stdout + "\n" + cmd.stderr
44
33
  if out =~ /Can't connect to .* MySQL server/ || out.downcase =~ /^error/
45
34
  # skip this test if the server can't run the query
@@ -56,6 +45,31 @@ module Inspec::Resources
56
45
 
57
46
  private
58
47
 
48
+ def escape_string(query)
49
+ Shellwords.escape(query)
50
+ end
51
+
52
+ def create_mysql_cmd(q, db = '')
53
+ # TODO: simple escape, must be handled by a library
54
+ # that does this securely
55
+ escaped_query = q.gsub(/\\/, '\\\\').gsub(/"/, '\\"').gsub(/\$/, '\\$')
56
+
57
+ # construct the query
58
+ command = 'mysql'
59
+ command += " -u#{escape_string(@user)}" unless @user.nil?
60
+ command += " -p#{escape_string(@pass)}" unless @pass.nil?
61
+
62
+ if !@socket.nil?
63
+ command += " -S #{@socket}"
64
+ else
65
+ command += " -h #{@host}"
66
+ end
67
+ command += " --port #{@port}" unless @port.nil?
68
+ command += " #{db}" unless db.empty?
69
+ command += %{ -s -e "#{escaped_query}"}
70
+ command
71
+ end
72
+
59
73
  def init_fallback
60
74
  # support debian mysql administration login
61
75
  debian = inspec.command('test -f /etc/mysql/debian.cnf && cat /etc/mysql/debian.cnf').stdout
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.45
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Richter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-08 00:00:00.000000000 Z
11
+ date: 2018-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: train
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.1'
19
+ version: '1.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.1'
26
+ version: '1.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: thor
29
29
  requirement: !ruby/object:Gem::Requirement