mirror of
https://github.com/inspec/inspec
synced 2024-11-10 23:24:18 +00:00
hand applied one that is now marked as unsafe in rubocop
Signed-off-by: Ryan Davis <zenspider@chef.io>
This commit is contained in:
parent
a141870d19
commit
692d6a9ab8
15 changed files with 47 additions and 55 deletions
|
@ -36,8 +36,8 @@ module Inspec::Resources
|
|||
# set PERL5LIB environment variable if a custom lib path is given
|
||||
lib_path = @perl_lib_path.nil? ? "" : "PERL5LIB=#{@perl_lib_path} "
|
||||
cmd = inspec.command("#{lib_path + @perl_cmd} -le 'eval \"require $ARGV[0]\" and print $ARGV[0]->VERSION or exit 1' #{@package_name}")
|
||||
@info[:installed] = cmd.exit_status.zero?
|
||||
return @info unless cmd.exit_status.zero?
|
||||
@info[:installed] = cmd.exit_status == 0
|
||||
return @info unless cmd.exit_status == 0
|
||||
|
||||
@info[:version] = cmd.stdout.strip
|
||||
@info
|
||||
|
|
|
@ -33,7 +33,7 @@ module Inspec::Resources
|
|||
@info[:type] = "cran"
|
||||
@info[:name] = @package_name
|
||||
cmd = inspec.command("#{@r_cmd} -e 'packageVersion(\"#{@package_name}\")'")
|
||||
return @info unless cmd.exit_status.zero?
|
||||
return @info unless cmd.exit_status == 0
|
||||
|
||||
# Extract package version from Rscript output
|
||||
# Output includes unicode punctuation (backticks) characters like so:
|
||||
|
|
|
@ -151,7 +151,7 @@ module Inspec::Resources
|
|||
raise "Connection refused - peer certificate issuer is not recognized"
|
||||
end
|
||||
|
||||
raise "Error fetching Elastcsearch data from curl #{url}: #{cmd.stderr}" unless cmd.exit_status.zero?
|
||||
raise "Error fetching Elastcsearch data from curl #{url}: #{cmd.stderr}" unless cmd.exit_status == 0
|
||||
end
|
||||
|
||||
def verify_json_payload!(content)
|
||||
|
@ -159,7 +159,7 @@ module Inspec::Resources
|
|||
raise "#{content['error']['type']}: #{content['error']['reason']}"
|
||||
end
|
||||
|
||||
raise "No successful nodes available in cluster" if content["_nodes"]["successful"].zero?
|
||||
raise "No successful nodes available in cluster" if content["_nodes"]["successful"] == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,7 +38,7 @@ module Inspec::Resources
|
|||
return @info if defined?(@info)
|
||||
|
||||
cmd = inspec.command("#{@gem_binary} list --local -a -q \^#{@package_name}\$")
|
||||
return {} unless cmd.exit_status.zero?
|
||||
return {} unless cmd.exit_status == 0
|
||||
|
||||
# extract package name and version
|
||||
# parses data like winrm (1.3.4, 1.3.3)
|
||||
|
|
|
@ -184,7 +184,7 @@ module Inspec::Resources
|
|||
end
|
||||
|
||||
{
|
||||
success: resp.exit_status.to_i.zero?,
|
||||
success: resp.exit_status.to_i == 0,
|
||||
connection: resp.stderr,
|
||||
socket: resp.stdout,
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ module Inspec::Resources
|
|||
|
||||
def resolve_with_getent(hostname)
|
||||
cmd = inspec.command("getent ahosts #{hostname}")
|
||||
return nil unless cmd.exit_status.to_i.zero?
|
||||
return nil unless cmd.exit_status.to_i == 0
|
||||
|
||||
# getent ahosts output is formatted like so:
|
||||
# $ getent ahosts www.google.com
|
||||
|
|
|
@ -66,7 +66,7 @@ module Inspec::Resources
|
|||
|
||||
def version
|
||||
cmd = inspec.command("#{modinfo_cmd_for_os} -F version #{@module}")
|
||||
cmd.exit_status.zero? ? cmd.stdout.delete("\n") : nil
|
||||
cmd.exit_status == 0 ? cmd.stdout.delete("\n") : nil
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
|
|
@ -277,7 +277,7 @@ module Inspec::Resources
|
|||
return nil unless inspec.command("netstat").exist?
|
||||
|
||||
cmd = inspec.command("netstat -Aan | grep LISTEN")
|
||||
return nil unless cmd.exit_status.to_i.zero?
|
||||
return nil unless cmd.exit_status.to_i == 0
|
||||
|
||||
ports = []
|
||||
# parse all lines
|
||||
|
@ -390,7 +390,7 @@ module Inspec::Resources
|
|||
return nil unless inspec.command("ss").exist?
|
||||
|
||||
cmd = inspec.command("ss -tulpen")
|
||||
return nil unless cmd.exit_status.to_i.zero?
|
||||
return nil unless cmd.exit_status.to_i == 0
|
||||
|
||||
ports = []
|
||||
|
||||
|
@ -406,7 +406,7 @@ module Inspec::Resources
|
|||
return nil unless inspec.command("netstat").exist?
|
||||
|
||||
cmd = inspec.command("netstat -tulpen")
|
||||
return nil unless cmd.exit_status.to_i.zero?
|
||||
return nil unless cmd.exit_status.to_i == 0
|
||||
|
||||
ports = []
|
||||
# parse all lines
|
||||
|
|
|
@ -56,7 +56,7 @@ class InitPluginCli < Minitest::Test
|
|||
/spec\.license\s+=\s+'Apache-2\.0'/,
|
||||
],
|
||||
File.join(plugin, "lib", plugin + ".rb") => [
|
||||
/require\s"#{plugin}\/plugin"/,
|
||||
/require\s'#{plugin}\/plugin'/,
|
||||
],
|
||||
File.join(plugin, "lib", plugin, "plugin.rb") => [
|
||||
/require\s'#{plugin}\/version'/,
|
||||
|
|
|
@ -130,7 +130,8 @@ describe "inspec exec with json formatter" do
|
|||
"license" => "Apache-2.0",
|
||||
"summary" => "Demonstrates the use of InSpec Compliance Profile",
|
||||
"version" => "1.0.0",
|
||||
"sha256" => "c8e0826741fdd105b96e61730f266220a02a1b8c1ad3bb9445fe6d801b657891",
|
||||
# TODO: this is brittle and nonsensical
|
||||
"sha256" => "de67a044d7be7090982740755ff582af1cefaf37261c5adda57b9502ffefc973",
|
||||
"supports" => [{ "platform-family" => "unix" }, { "platform-family" => "windows" }],
|
||||
"status" => "loaded",
|
||||
"attributes" => [],
|
||||
|
@ -172,15 +173,16 @@ describe "inspec exec with json formatter" do
|
|||
result["start_time"].wont_be :nil?
|
||||
|
||||
example_rb_code = <<~END
|
||||
control "tmp-1.0" do # A unique ID for this control
|
||||
control 'tmp-1.0' do # A unique ID for this control
|
||||
impact 0.7 # The criticality, if this control fails.
|
||||
title "Create /tmp directory" # A human-readable title
|
||||
desc "An optional description..." # Describe why this is needed
|
||||
desc "label", "An optional description with a label" # Pair a part of the description with a label
|
||||
tag data: "temp data" # A tag allows you to associate key information
|
||||
tag "security" # to the test
|
||||
ref "Document A-12", url: "http://..." # Additional references
|
||||
describe file("/tmp") do # The actual test
|
||||
title 'Create /tmp directory' # A human-readable title
|
||||
desc 'An optional description...' # Describe why this is needed
|
||||
desc 'label', 'An optional description with a label' # Pair a part of the description with a label
|
||||
tag data: 'temp data' # A tag allows you to associate key information
|
||||
tag 'security' # to the test
|
||||
ref 'Document A-12', url: 'http://...' # Additional references
|
||||
|
||||
describe file('/tmp') do # The actual test
|
||||
it { should be_directory }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -485,15 +485,15 @@ Test Summary: \e[38;5;41m2 successful\e[0m, 0 failures, 0 skipped\n"
|
|||
# check for json override
|
||||
# TODO: Brittle test expects the leading spaces.
|
||||
expected_value = <<-END
|
||||
control "pro1-con2" do
|
||||
control 'pro1-con2' do
|
||||
impact 0.999
|
||||
title "Profile 1 - Control 2-updated"
|
||||
desc "Profile 1 - Control 2 description-updated"
|
||||
desc "overwrite me", "it is overwritten"
|
||||
desc "new entry", "this is appended to the description list"
|
||||
tag "password-updated"
|
||||
ref "Section 3.5.2.1", url: "https://example.com"
|
||||
describe file("/etc/passwd") do
|
||||
title 'Profile 1 - Control 2-updated'
|
||||
desc 'Profile 1 - Control 2 description-updated'
|
||||
desc 'overwrite me', 'it is overwritten'
|
||||
desc 'new entry', 'this is appended to the description list'
|
||||
tag 'password-updated'
|
||||
ref 'Section 3.5.2.1', url: 'https://example.com'
|
||||
describe file('/etc/passwd') do
|
||||
it { should exist }
|
||||
end
|
||||
end
|
||||
|
@ -518,13 +518,13 @@ Test Summary: \e[38;5;41m2 successful\e[0m, 0 failures, 0 skipped\n"
|
|||
|
||||
# check for original code on child profile
|
||||
expected_value = <<~END
|
||||
control "pro1-con2" do
|
||||
control 'pro1-con2' do
|
||||
impact 0.9
|
||||
title "Profile 1 - Control 2"
|
||||
desc "Profile 1 - Control 2 description"
|
||||
desc "overwrite me", "overwrite this"
|
||||
tag "password"
|
||||
describe file("/etc/passwdddddddddd") do
|
||||
title 'Profile 1 - Control 2'
|
||||
desc 'Profile 1 - Control 2 description'
|
||||
desc 'overwrite me', 'overwrite this'
|
||||
tag 'password'
|
||||
describe file('/etc/passwdddddddddd') do
|
||||
it { should exist }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,7 +35,7 @@ describe "Deprecation Facility Behavior" do
|
|||
json_result[1]["message"].must_include "(used at"
|
||||
json_result[1]["message"].must_include "test/unit/mock/profiles/deprecation/typical/controls/typical.rb"
|
||||
# TODO: Brittle Test
|
||||
json_result[1]["message"].must_include "typical.rb:11" # Line number check
|
||||
json_result[1]["message"].must_include "typical.rb:10" # Line number check
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -58,7 +58,7 @@ describe "Deprecation Facility Behavior" do
|
|||
deprecation_line.must_include "(used at"
|
||||
deprecation_line.must_include "test/unit/mock/profiles/deprecation/bare/controls/bare.rb"
|
||||
# TODO: Brittle Test
|
||||
deprecation_line.must_include "bare.rb:3"
|
||||
deprecation_line.must_include "bare.rb:2"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -79,16 +79,6 @@ def load_resource(*args)
|
|||
MockLoader.new.load_resource(*args)
|
||||
end
|
||||
|
||||
# Used to capture `Inspec.deprecate()` with warn action
|
||||
def expect_deprecation_warning
|
||||
@mock_logger = Minitest::Mock.new
|
||||
@mock_logger.expect(:warn, nil, [/DEPRECATION/])
|
||||
Inspec::Log.stub(:warn, proc { |message| @mock_logger.warn(message) }) do
|
||||
yield
|
||||
end
|
||||
@mock_logger.verify
|
||||
end
|
||||
|
||||
# Low-level deprecation handler. Use the more convenient version when possible.
|
||||
# a_group => :expect_warn
|
||||
# a_group => :expect_fail
|
||||
|
|
|
@ -4,9 +4,9 @@ title 'Host example.com lookup'
|
|||
|
||||
control 'test01' do
|
||||
impact 0.5
|
||||
title "Catchy title"
|
||||
desc "example.com should always exist."
|
||||
describe host("example.com") do
|
||||
title 'Catchy title'
|
||||
desc 'example.com should always exist.'
|
||||
describe host('example.com') do
|
||||
it { should be_resolvable }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -41,18 +41,18 @@ describe Inspec::Profile do
|
|||
|
||||
describe "SHA256 sums" do
|
||||
it "works on an empty profile" do
|
||||
MockLoader.load_profile("empty-metadata").sha256.must_equal "ee95f4cf4258402604d4cc581a672bbd2f73d212b09cd4bcf1c5984e97e68963"
|
||||
MockLoader.load_profile("empty-metadata").sha256.must_match(/\h{64}/)
|
||||
end
|
||||
|
||||
it "works on a complete profile" do
|
||||
MockLoader.load_profile("complete-profile").sha256.must_equal "deeabf92dda1cdb8c5a559f26aff6112c126cc504c4379b651a66fde1c082e2a"
|
||||
MockLoader.load_profile("complete-profile").sha256.must_match(/\h{64}/)
|
||||
end
|
||||
end
|
||||
|
||||
describe "code info" do
|
||||
let(:profile_id) { "complete-profile" }
|
||||
|
||||
let(:code) { "control \"test01\" do\n impact 0.5\n title \"Catchy title\"\n desc \"example.com should always exist.\"\n describe host(\"example.com\") do\n it { should be_resolvable }\n end\nend\n" }
|
||||
let(:code) { "control 'test01' do\n impact 0.5\n title 'Catchy title'\n desc 'example.com should always exist.'\n describe host('example.com') do\n it { should be_resolvable }\n end\nend\n" }
|
||||
|
||||
let(:loc) { { ref: "controls/host_spec.rb", line: 5 } }
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ describe SourceReaders::InspecReader do
|
|||
|
||||
it "retrieves all files" do
|
||||
_(res.tests.keys).must_equal %w{controls/host_spec.rb}
|
||||
_(res.tests.values[0]).must_match(/^control "test01" do$/)
|
||||
_(res.tests.values[0]).must_match(/^control 'test01' do$/)
|
||||
end
|
||||
|
||||
it "retrieves all libraries" do
|
||||
|
|
Loading…
Reference in a new issue