mostly a search and replace for gordon -> example

Signed-off-by: Miah Johnson <miah@chia-pet.org>
This commit is contained in:
Miah Johnson 2019-10-09 00:08:28 -07:00
parent 5e699d2fb3
commit df7efefc9d
31 changed files with 108 additions and 113 deletions

View file

@ -340,10 +340,10 @@ $ inspec shell
Welcome to the interactive InSpec Shell
To find out how to use it, type: help
inspec> command('ls /home/gordon/git/inspec/docs').stdout
=> "ctl_inspec.rst\ndsl_inspec.rst\ndsl_resource.rst\n"
inspec> command('ls').stdout.split("\n")
=> ["ctl_inspec.rst", "dsl_inspec.rst", "dsl_resource.rst"]
inspec> command('ls ~/projects/github/inspec/docs').stdout
=> "README.md\nconfig.md\ndev\ndsl_inspec.md\ndsl_resource.md\nglossary.md\nhabitat.md\ninputs.md\ninspec_and_friends.md\nmatchers.md\nmigration.md\nplatforms.md\nplugin_kitchen_inspec.md\nplugins.md\nprofiles.md\nreporters.md\nresources\nshared\nshell.md\nstyle.md\nwaivers.md\n"
inspec> command('ls ~/projects/github/inspec/docs').stdout.split("\n").first
=> "README.md"
inspec> help command
Name: command

View file

@ -17,7 +17,7 @@ $ tree examples/profile
examples/profile
...
├── libraries
│   └── gordon_config.rb
│   └── example_config.rb
```
## Resource structure
@ -51,8 +51,8 @@ The following example shows a full resource using attributes and methods
to provide simple access to a configuration file:
```ruby
class GordonConfig < Inspec.resource(1)
name 'gordon_config'
class ExampleConfig < Inspec.resource(1)
name 'example_config'
# Restrict to only run on the below platforms (if none were given, all OS's supported)
supports platform_family: 'fedora'
@ -65,14 +65,14 @@ class GordonConfig < Inspec.resource(1)
'
example '
describe gordon_config do
describe example_config do
its("signal") { should eq "on" }
end
'
# Load the configuration file on initialization
def initialize(path = nil)
@path = path || '/etc/gordon.conf'
@path = path || '/etc/example.conf'
@params = SimpleConfig.new( read_content )
end
@ -90,11 +90,11 @@ class GordonConfig < Inspec.resource(1)
# Retrieve the file's contents
f.content
else
# If the file doesn't exist, skip all tests that use gordon_config
# If the file doesn't exist, skip all tests that use example_config
raise Inspec::Exceptions::ResourceSkipped, "Can't read config at #{@path}"
end
end
end
```
For a full example, see our [example resource](https://github.com/chef/inspec/blob/master/examples/profile/libraries/gordon_config.rb).
For a full example, see our [example resource](https://github.com/chef/inspec/blob/master/examples/profile/libraries/example_config.rb).

View file

@ -54,7 +54,7 @@ The following examples show how to use this Chef InSpec audit resource.
end
describe ssh_config do
its('SendEnv') { should include('GORDON_CLIENT') }
its('SendEnv') { should include('CI_ENABLE_COVERAGE') }
end
### Test SSH configuration

View file

@ -42,7 +42,7 @@ The following examples show how to use this Chef InSpec audit resource.
### Test which variables may be sent to the server
describe sshd_config do
its('AcceptEnv') { should include('GORDON_SERVER') }
its('AcceptEnv') { should include('CI_ENABLE_COVERAGE') }
end
### Test for IPv6-only addresses

View file

@ -48,9 +48,9 @@ $ inspec shell -t docker://container_id # Login to a Docker container.
Use resource packs to share custom resources with other Chef InSpec users.
A resource pack is an Chef InSpec profile that contains only custom resources and no other controls or tests.
For example, the profile in [`examples/profile`](https://github.com/chef/inspec/tree/master/examples/profile)in the Chef InSpec git repo defines a [`gordon_config` resource](https://github.com/chef/inspec/blob/master/examples/profile/controls/gordon.rb). To use these resources within the Chef InSpec shell, you will need to download and specify them as a dependency.
For example, the profile in [`examples/profile`](https://github.com/chef/inspec/tree/master/examples/profile)in the Chef InSpec git repo defines a [`example_config` resource](https://github.com/chef/inspec/blob/master/examples/profile/controls/example.rb). To use these resources within the Chef InSpec shell, you will need to download and specify them as a dependency.
Once you have local access to the profile, you can use the `gordon_config` custom resource provided in the `examples/profile` GitHub repo in your local environment :
Once you have local access to the profile, you can use the `example_config` custom resource provided in the `examples/profile` GitHub repo in your local environment :
```bash
inspec shell --depends examples/profile
@ -59,7 +59,7 @@ inspec shell --depends examples/profile
Once inside the shell your resource will be available:
```ruby
inspec> gordon_config
inspec> example_config
```
## Using Ruby in Chef InSpec shell

View file

@ -1,5 +1,4 @@
describe gordon do
its('crime_rate') { should be < 5 }
describe example do
its('crime_rate') { should be < 2 }
it { should have_a_fabulous_mustache }
end

View file

@ -1,20 +1,18 @@
class Gordon < Inspec.resource(1)
name "gordon"
class Example < Inspec.resource(1)
name "example"
example "
describe gordon do
describe example do
its('crime_rate') { should be < 2 }
it { should have_a_fabulous_mustache }
end
"
def crime_rate
# call out ot another custom resource
inspec.batsignal.number_of_sightings
1
end
def has_a_fabulous_mustache?
# always true
true
end
end

View file

@ -30,8 +30,8 @@ Version: 1.0.0
Target: local://
gordon-1.0: Verify the version number of Gordon (1 skipped)
○ Can't find file "/tmp/gordon/config.yaml"
example-1.0: Verify the version number of Example (1 skipped)
○ Can't find file "/tmp/example/config.yaml"
✔ File content should match nil
✔ ssh-1: Allow only SSH Protocol 2
✔ File /bin/sh should be owned by "root"

View file

@ -4,7 +4,7 @@
include_controls 'profile' do
skip_control 'tmp-1.0'
control 'gordon-1.0' do
control 'example-1.0' do
impact 0.0
end
end

View file

@ -1,24 +1,24 @@
# copyright: 2016, Chef Software, Inc.
title 'Gordon Config Checks'
title 'Example Config Checks'
# To pass the test, create the following file
# ```bash
# mkdir -p /tmp/gordon
# cat <<EOF > /tmp/gordon/config.yaml
# mkdir -p /tmp/example
# cat <<EOF > /tmp/example/config.yaml
# version: '1.0'
# EOF
# ```
control 'gordon-1.0' do
control 'example-1.0' do
impact 'critical'
title 'Verify the version number of Gordon'
title 'Verify the version number of Example'
desc 'An optional description...'
tag 'gordon'
ref 'Gordon Requirements 1.0', uri: 'http://...'
tag 'example'
ref 'Example Requirements 1.0', uri: 'http://...'
# Test using the custom gordon_config InSpec resource
# Test using the custom example_config InSpec resource
# Find the resource content here: ../libraries/
describe gordon_config do
describe example_config do
it { should exist }
its('version') { should eq('1.0') }
its('file_size') { should <= 20 }
@ -26,7 +26,7 @@ control 'gordon-1.0' do
end
# Test the version again to showcase variables
g = gordon_config
g = example_config
g_path = g.file_path
g_version = g.version
describe file(g_path) do

View file

@ -1,18 +1,18 @@
require "yaml"
# Custom resource based on the InSpec resource DSL
class GordonConfig < Inspec.resource(1)
name "gordon_config"
class ExampleConfig < Inspec.resource(1)
name "example_config"
supports platform: "unix"
supports platform: "windows"
desc "
Gordon's resource description ...
Example's resource description ...
"
example "
describe gordon_config do
describe example_config do
its('version') { should eq('1.0') }
its('file_size') { should > 1 }
end
@ -21,7 +21,7 @@ class GordonConfig < Inspec.resource(1)
# Load the configuration file on initialization
def initialize
@params = {}
@path = "/tmp/gordon/config.yaml"
@path = "/tmp/example/config.yaml"
@file = inspec.file(@path)
unless @file.file?

View file

@ -152,7 +152,7 @@ $ inspec exec compliance://admin/profile
Pending: (Failures listed here are expected and do not affect your suite's status)
1) gordon_config Can't find file "/tmp/gordon/config.yaml"
1) example_config Can't find file "/tmp/example/config.yaml"
# Not yet implemented
# ./lib/inspec/runner.rb:157

View file

@ -120,9 +120,9 @@ describe "inspec exec with json formatter" do
let(:controls) { profile["controls"] }
let(:ex1) { controls.find { |x| x["id"] == "tmp-1.0" } }
let(:ex2) { controls.find { |x| x["id"] =~ /generated/ } }
let(:ex3) { profile["controls"].find { |x| x["id"] == "gordon-1.0" } }
let(:ex3) { profile["controls"].find { |x| x["id"] == "example-1.0" } }
let(:check_result) do
ex3["results"].find { |x| x["resource"] == "gordon_config" }
ex3["results"].find { |x| x["resource"] == "example_config" }
end
it "has only one profile" do
@ -157,7 +157,7 @@ describe "inspec exec with json formatter" do
_(groups.sort_by { |x| x["id"] }).must_equal([
{ "id" => "controls/example.rb", "title" => "/tmp profile", "controls" => ["tmp-1.0", key] },
{ "id" => "controls/gordon.rb", "title" => "Gordon Config Checks", "controls" => ["gordon-1.0"] },
{ "id" => "controls/example.rb", "title" => "Example Config Checks", "controls" => ["example-1.0"] },
{ "id" => "controls/meta.rb", "title" => "SSH Server Configuration", "controls" => ["ssh-1"] },
])
end

View file

@ -47,7 +47,7 @@ describe "inspec exec" do
let(:controls) { json["controls"] }
let(:ex1) { controls.find { |x| x["id"] == "tmp-1.0" } }
let(:ex2) { controls.find { |x| x["id"] =~ /generated/ } }
let(:ex3) { controls.find { |x| x["id"] == "gordon-1.0" } }
let(:ex3) { controls.find { |x| x["id"] == "example-1.0" } }
it "must have 5 examples" do
_(json["controls"].length).must_equal 5
@ -74,7 +74,7 @@ describe "inspec exec" do
it "has a skip_message" do
_(ex1["skip_message"]).must_be :nil?
_(ex3["skip_message"]).must_equal "Can't find file `/tmp/gordon/config.yaml`"
_(ex3["skip_message"]).must_equal "Can't find file `/tmp/example/config.yaml`"
end
end

View file

@ -59,19 +59,19 @@ describe "inspec exec with junit formatter" do
_(REXML::XPath.match(suite, "//testcase[@name='File /tmp should be directory']").length).must_equal 2
end
describe 'the testcase named "gordon_config Can\'t find file ..."' do
let(:gordon_yml_tests) { REXML::XPath.match(suite, "//testcase[@classname='profile.gordon-1.0' and @name='gordon_config']") }
let(:first_gordon_test) { gordon_yml_tests.first }
describe 'the testcase named "example_config Can\'t find file ..."' do
let(:example_yml_tests) { REXML::XPath.match(suite, "//testcase[@classname='profile.example-1.0' and @name='example_config']") }
let(:first_example_test) { example_yml_tests.first }
it "should be unique" do
_(gordon_yml_tests.length).must_equal 1
_(example_yml_tests.length).must_equal 1
end
it "should be skipped" do
if is_windows?
_(first_gordon_test.elements.to_a("//skipped").length).must_equal 2
_(first_example_test.elements.to_a("//skipped").length).must_equal 2
else
_(first_gordon_test.elements.to_a("//skipped").length).must_equal 1
_(first_example_test.elements.to_a("//skipped").length).must_equal 1
end
end
end

View file

@ -38,8 +38,8 @@ describe "inspec exec" do
_(stdout).must_include "\e[38;5;41m ✔ tmp-1.0: Create /tmp directory\e[0m\n"
_(stdout).must_include "
\e[38;5;247m gordon-1.0: Verify the version number of Gordon (1 skipped)\e[0m
\e[38;5;247m Can't find file `/tmp/gordon/config.yaml`\e[0m
\e[38;5;247m example-1.0: Verify the version number of Example (1 skipped)\e[0m
\e[38;5;247m Can't find file `/tmp/example/config.yaml`\e[0m
"
if is_windows?
_(stdout).must_include "\e[38;5;247m ↺ ssh-1: Allow only SSH Protocol 2\e[0m\n"

View file

@ -19,9 +19,9 @@ describe "inspec shell tests" do
end
it "loads a dependency" do
res = inspec("shell -c 'gordon_config' --depends #{example_profile}")
res = inspec("shell -c 'example_config' --depends #{example_profile}")
_(res.stdout.chop).must_equal "gordon_config"
_(res.stdout.chop).must_equal "example_config"
_(res.stderr).must_equal ""
@ -171,10 +171,10 @@ describe "inspec shell tests" do
end
it "loads a dependency" do
cmd = "echo 'gordon_config' | #{exec_inspec} shell --depends #{example_profile}"
cmd = "echo 'example_config' | #{exec_inspec} shell --depends #{example_profile}"
res = CMD.run_command(cmd)
_(res.stdout).must_include "=> gordon_config"
_(res.stdout).must_include "=> example_config"
assert_exit_code 0, res
end

View file

@ -20,7 +20,7 @@ control 'profilea-1' do # A unique ID for this control
end
control 'profilea-2' do
describe gordon_config do
describe example_config do
its('version') { should eq('1.0') }
end
end

View file

@ -14,7 +14,7 @@ control 'profileb-1' do # A unique ID for this control
end
control 'profileb-2' do
describe gordon_config do
describe example_config do
its('version') { should eq('2.0') }
end
end

View file

@ -1,10 +1,10 @@
class GordonConfig < Inspec.resource(1)
name 'gordon_config'
class ExampleConfig < Inspec.resource(1)
name 'example_config'
desc "Gordon's resource description ..."
desc "Example's resource description ..."
example "
describe gordon_config do
describe example_config do
its('version') { should eq('1.0') }
end
"

View file

@ -1,10 +1,10 @@
class GordonConfig < Inspec.resource(1)
name 'gordon_config'
class ExampleConfig < Inspec.resource(1)
name 'example_config'
desc "Gordon's resource description ..."
desc "Example's resource description ..."
example "
describe gordon_config do
describe example_config do
its('version') { should eq('2.0') }
end
"

View file

@ -1,26 +1,26 @@
# copyright: 2015, The Authors
require_resource(profile: 'profile_c', resource: 'gordon_config', as: 'gordy_config')
require_resource(profile: 'profile_c', resource: 'example_config', as: 'placeholder_config')
describe gordy_config do
describe placeholder_config do
its('version') { should eq('1.0') }
end
control 'whichgordon' do
describe gordy_config do
control 'whichexample' do
describe placeholder_config do
its('version') { should eq('1.0') }
end
describe gordon_config do
describe example_config do
its('version') { should eq('2.0') }
end
describe gordy_config do
its('version') { should eq(gordy_config.version) }
describe placeholder_config do
its('version') { should eq(placeholder_config.version) }
end
describe gordon_config do
its('version') { should eq(gordon_config.version) }
describe example_config do
its('version') { should eq(example_config.version) }
end
end

View file

@ -1,5 +1,5 @@
# copyright: 2015, Chef Software, Inc
describe gordon do
describe example do
it { should be_enabled }
end

View file

@ -1,2 +1,2 @@
module GordonLib
module ExampleLib
end

View file

@ -1,11 +1,11 @@
# Library resource
require 'gordonlib'
require 'examplelib'
require 'hashie'
class Gordon < Inspec.resource(1)
name 'gordon'
include GordonLib
class Example < Inspec.resource(1)
name 'example'
include ExampleLib
def enabled?
true
end

View file

@ -1,5 +1,4 @@
describe gordon do
its('crime_rate') { should be < 5 }
describe example do
its('crime_rate') { should be < 2 }
it { should have_a_fabulous_mustache }
end

View file

@ -1,8 +1,8 @@
class Gordon < Inspec.resource(1)
name 'gordon'
class Example < Inspec.resource(1)
name 'example'
example "
describe gordon do
describe example do
its('crime_rate') { should be < 2 }
it { should have_a_fabulous_mustache }
end
@ -18,4 +18,3 @@ class Gordon < Inspec.resource(1)
true
end
end

View file

@ -30,8 +30,8 @@ Version: 1.0.0
Target: local://
gordon-1.0: Verify the version number of Gordon (1 skipped)
○ Can't find file "/tmp/gordon/config.yaml"
example-1.0: Verify the version number of Example (1 skipped)
○ Can't find file "/tmp/example/config.yaml"
✔ File content should match nil
✔ ssh-1: Allow only SSH Protocol 2
✔ File /bin/sh should be owned by "root"

View file

@ -4,7 +4,7 @@
include_controls 'profile' do
skip_control 'tmp-1.0'
control 'gordon-1.0' do
control 'example-1.0' do
impact 0.0
end
end

View file

@ -1,24 +1,24 @@
# copyright: 2016, Chef Software, Inc.
title 'Gordon Config Checks'
title 'Example Config Checks'
# To pass the test, create the following file
# ```bash
# mkdir -p /tmp/gordon
# cat <<EOF > /tmp/gordon/config.yaml
# mkdir -p /tmp/example
# cat <<EOF > /tmp/example/config.yaml
# version: '1.0'
# EOF
# ```
control 'gordon-1.0' do
control 'example-1.0' do
impact 'critical'
title 'Verify the version number of Gordon'
title 'Verify the version number of Example'
desc 'An optional description...'
tag 'gordon'
ref 'Gordon Requirements 1.0', uri: 'http://...'
tag 'example'
ref 'Example Requirements 1.0', uri: 'http://...'
# Test using the custom gordon_config InSpec resource
# Test using the custom example_config InSpec resource
# Find the resource content here: ../libraries/
describe gordon_config do
describe example_config do
it { should exist }
its('version') { should eq('1.0') }
its('file_size') { should <= 20 }
@ -26,7 +26,7 @@ control 'gordon-1.0' do
end
# Test the version again to showcase variables
g = gordon_config
g = example_config
g_path = g.file_path
g_version = g.version
describe file(g_path) do

View file

@ -1,18 +1,18 @@
require 'yaml'
# Custom resource based on the InSpec resource DSL
class GordonConfig < Inspec.resource(1)
name 'gordon_config'
class ExampleConfig < Inspec.resource(1)
name 'example_config'
supports platform: 'unix'
supports platform: 'windows'
desc "
Gordon's resource description ...
Example's resource description ...
"
example "
describe gordon_config do
describe example_config do
its('version') { should eq('1.0') }
its('file_size') { should > 1 }
end
@ -21,7 +21,7 @@ class GordonConfig < Inspec.resource(1)
# Load the configuration file on initialization
def initialize
@params = {}
@path = '/tmp/gordon/config.yaml'
@path = '/tmp/example/config.yaml'
@file = inspec.file(@path)
unless @file.file?