Switched chefstyle back to Layout/AlignArguments=with_first_argument.

Fixed the flags mostly with `chefstyle -a` but also refactored/cleaned
some stuff by hand.

Signed-off-by: Ryan Davis <zenspider@chef.io>
This commit is contained in:
Ryan Davis 2019-11-07 15:17:22 -08:00
parent 8f1e607d55
commit bb49d58cd9
38 changed files with 136 additions and 108 deletions

View file

@ -7,3 +7,5 @@ AllCops:
- 'lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/**/*'
- 'examples/**/controls/*.rb'
- 'vendor/bundle/**/*'
Layout/AlignArguments:
EnforcedStyle: with_first_argument

View file

@ -122,8 +122,8 @@ class Inspec::InspecCLI < Inspec::BaseCLI
else
%w{location profile controls timestamp valid}.each do |item|
prepared_string = format("%-12s %s",
"#{item.to_s.capitalize} :",
result[:summary][item.to_sym])
"#{item.to_s.capitalize} :",
result[:summary][item.to_sym])
ui.plain_line(prepared_string)
end
puts

View file

@ -21,16 +21,20 @@ module Inspec
}
new(dep[:name],
dep[:version],
config,
opts.merge(dep))
dep[:version],
config,
opts.merge(dep))
end
def self.from_lock_entry(entry, config, opts = {})
resolved_source = entry[:resolved_source]
.merge(backend: config[:backend])
.merge(opts)
req = new(entry[:name],
entry[:version_constraints],
config,
entry[:resolved_source].merge(backend: config[:backend]).merge(opts))
entry[:version_constraints],
config,
resolved_source)
locked_deps = []
Array(entry[:dependencies]).each do |dep_entry|

View file

@ -208,8 +208,8 @@ module Inspec
data = Inspec::SecretsBackend.resolve(path)
if data.nil?
raise Inspec::Exceptions::SecretsBackendNotFound,
"Cannot find parser for inputs file '#{path}'. " \
"Check to make sure file has the appropriate extension."
"Cannot find parser for inputs file '#{path}'. " \
"Check to make sure file has the appropriate extension."
end
next if data.inputs.nil?
@ -230,14 +230,14 @@ module Inspec
def validate_inputs_file_readability!(path)
unless File.exist?(path)
raise Inspec::Exceptions::InputsFileDoesNotExist,
"Cannot find input file '#{path}'. " \
"Check to make sure file exists."
"Cannot find input file '#{path}'. " \
"Check to make sure file exists."
end
unless File.readable?(path)
raise Inspec::Exceptions::InputsFileNotReadable,
"Cannot read input file '#{path}'. " \
"Check to make sure file is readable."
"Cannot read input file '#{path}'. " \
"Check to make sure file is readable."
end
true

View file

@ -156,9 +156,12 @@ module Inspec
nil
when nil then nil
else
Inspec.deprecate(:supports_syntax,
Inspec.deprecate(
:supports_syntax,
"Do not use deprecated `supports: #{x}` syntax. Instead use:\n"\
"supports:\n - os-family: #{x}\n\n")
"supports:\n - os-family: #{x}\n\n"
)
{ :'os-family' => x } # rubocop:disable Style/HashSyntax
end
end

View file

@ -14,7 +14,7 @@ module Inspec
::MethodSource.expression_at(src.lines, location[:line]).force_encoding("utf-8")
rescue SyntaxError => e
raise ::MethodSource::SourceNotFoundError,
"Could not parse source at #{location[:ref]}:#{location[:line]}: #{e.message}"
"Could not parse source at #{location[:ref]}:#{location[:line]}: #{e.message}"
end
end
end

View file

@ -75,7 +75,7 @@ module Inspec
" " + expectation.inspect
end
format("%s%sdescribe %s do\n %s { should%s %s%s }\nend",
only_if_clause, vars, res, itsy, naughty, matcher, xpect)
only_if_clause, vars, res, itsy, naughty, matcher, xpect)
end
def rb_skip

View file

@ -267,12 +267,17 @@ module Inspec::Plugin::V2
# Make Set that encompasses just the gemfile that was provided
plugin_local_source = Gem::Source::SpecificFile.new(opts[:gem_file])
plugin_dependency = Gem::Dependency.new(requested_plugin_name,
plugin_local_source.spec.version)
plugin_dependency = Gem::Dependency.new(
requested_plugin_name,
plugin_local_source.spec.version
)
requested_local_gem_set = Gem::Resolver::InstallerSet.new(:both)
requested_local_gem_set.add_local(plugin_dependency.name,
plugin_local_source.spec, plugin_local_source)
requested_local_gem_set.add_local(
plugin_dependency.name,
plugin_local_source.spec,
plugin_local_source
)
install_gem_to_plugins_dir(plugin_dependency, [requested_local_gem_set])
end

View file

@ -30,7 +30,7 @@ module Inspec::Resources
def initialize
unless inspec.command("/sbin/auditctl").exist?
raise Inspec::Exceptions::ResourceFailed,
"Command `/sbin/auditctl` does not exist"
"Command `/sbin/auditctl` does not exist"
end
auditctl_cmd = "/sbin/auditctl -l"
@ -38,7 +38,7 @@ module Inspec::Resources
if result.exit_status != 0
raise Inspec::Exceptions::ResourceFailed,
"Command `#{auditctl_cmd}` failed with error: #{result.stderr}"
"Command `#{auditctl_cmd}` failed with error: #{result.stderr}"
end
@content = result.stdout
@ -46,8 +46,8 @@ module Inspec::Resources
if @content =~ /^LIST_RULES:/
raise Inspec::Exceptions::ResourceFailed,
"The version of audit is outdated." \
"The `auditd` resource supports versions of audit >= 2.3."
"The version of audit is outdated." \
"The `auditd` resource supports versions of audit >= 2.3."
end
parse_content
end

View file

@ -37,7 +37,7 @@ module Inspec::Resources
# Make sure command is replaced so sensitive output isn't shown
@command = "ERROR"
raise Inspec::Exceptions::ResourceFailed,
"The `redact_regex` option must be a regular expression"
"The `redact_regex` option must be a regular expression"
end
@redact_regex = options[:redact_regex]
end

View file

@ -98,7 +98,7 @@ module Inspec::Resources
cmd = inspec.command("df #{partition} -PT")
if cmd.stdout.nil? || cmd.stdout.empty? || cmd.exit_status != 0
raise Inspec::Exceptions::ResourceFailed,
"Unable to get available space for partition #{partition}"
"Unable to get available space for partition #{partition}"
end
value = cmd.stdout.split(/\n/)[1].strip.split(" ")
{
@ -125,8 +125,8 @@ module Inspec::Resources
fs = JSON.parse(cmd.stdout)
rescue JSON::ParserError => e
raise Inspec::Exceptions::ResourceFailed,
"Failed to parse JSON from Powershell. " \
"Error: #{e}"
"Failed to parse JSON from Powershell. " \
"Error: #{e}"
end
{
name: fs["DeviceID"],

View file

@ -35,8 +35,8 @@ module Inspec::Resources
# profiles.
if opts.key?(:enable_remote_worker) && !inspec.local_transport?
warn "Ignoring `enable_remote_worker` option, the `http` resource ",
"remote worker is enabled by default for remote targets and ",
"cannot be disabled"
"remote worker is enabled by default for remote targets and ",
"cannot be disabled"
end
# Run locally if InSpec is ran locally and remotely if ran remotely
@ -164,7 +164,7 @@ module Inspec::Resources
def initialize(inspec, http_method, url, opts)
unless inspec.command("curl").exist?
raise Inspec::Exceptions::ResourceSkipped,
"curl is not available on the target machine"
"curl is not available on the target machine"
end
@ran_curl = false

View file

@ -21,9 +21,6 @@ module Inspec::Resources
end
EXAMPLE
# rubocop:disable Layout/AlignArguments
# going to switch this back off in a separate commit
attr_reader :bin, :db_role, :host, :password, :port, :service,
:su_user, :user

View file

@ -217,8 +217,7 @@ module Inspec::Resources
}
rescue JSON::ParserError => e
raise Inspec::Exceptions::ResourceFailed,
"Failed to parse JSON from `brew` command. " \
"Error: #{e}"
"Failed to parse JSON from `brew` command. Error: #{e}"
end
end
@ -307,8 +306,7 @@ module Inspec::Resources
package = JSON.parse(cmd.stdout)
rescue JSON::ParserError => e
raise Inspec::Exceptions::ResourceFailed,
"Failed to parse JSON from PowerShell. " \
"Error: #{e}"
"Failed to parse JSON from PowerShell. Error: #{e}"
end
# What if we match multiple packages? just pick the first one for now.

View file

@ -204,7 +204,11 @@ module Inspec
def self.set_skip_rule(rule, value, message = nil, type = :only_if)
rule.instance_variable_set(:@__skip_rule,
{ result: value, message: message, type: type })
{
result: value,
message: message,
type: type,
})
end
def self.merge_count(rule)

View file

@ -190,10 +190,10 @@ module Inspec
#
def add_target(target, _opts = [])
profile = Inspec::Profile.for_target(target,
vendor_cache: @cache,
backend: @backend,
controls: @controls,
runner_conf: @conf)
vendor_cache: @cache,
backend: @backend,
controls: @controls,
runner_conf: @conf)
raise "Could not resolve #{target} to valid input." if profile.nil?
@target_profiles << profile if supports_profile?(profile)

View file

@ -116,8 +116,8 @@ class InspecPlugins::Habitat::ProfileTest < Minitest::Test
def test_duplicate_profile
current_profile = @test_profile
duplicated_profile = @hab_profile.send(:duplicate_profile,
@test_profile_path,
@tmpdir)
@test_profile_path,
@tmpdir)
assert duplicated_profile.is_a?(Inspec::Profile)
assert duplicated_profile.sha256 == current_profile.sha256.to_s
refute_same duplicated_profile.root_path, current_profile.root_path
@ -130,8 +130,8 @@ class InspecPlugins::Habitat::ProfileTest < Minitest::Test
def test_copy_profile_to_working_dir
duplicated_profile = @hab_profile.send(:duplicate_profile,
@test_profile_path,
@tmpdir)
@test_profile_path,
@tmpdir)
dst = File.join(@tmpdir, "working_dir")
FileUtils.mkdir_p(dst)
@ -176,7 +176,7 @@ class InspecPlugins::Habitat::ProfileTest < Minitest::Test
Inspec::ProfileVendor.stub :new, mock do
new_profile = @hab_profile.send(:vendor_profile_dependencies!,
@test_profile)
@test_profile)
assert new_profile.is_a?(Inspec::Profile)
end
end
@ -192,7 +192,7 @@ class InspecPlugins::Habitat::ProfileTest < Minitest::Test
Inspec::ProfileVendor.stub :new, mock do
new_profile = @hab_profile.send(:vendor_profile_dependencies!,
@test_profile)
@test_profile)
assert new_profile.is_a?(Inspec::Profile)
end
mock.verify

View file

@ -1,7 +1,7 @@
module AwsResourceMixin
def initialize(resource_params = {})
Inspec.deprecate(:aws_resources_in_resource_pack,
"Resource '#{@__resource_name__ ||= self.class.to_s}'")
"Resource '#{@__resource_name__ ||= self.class.to_s}'")
validate_params(resource_params).each do |param, value|
instance_variable_set(:"@#{param}", value)
end

View file

@ -23,7 +23,7 @@ class AwsBillingReport < Inspec.resource(1)
include AwsSingularResourceMixin
attr_reader :report_name, :time_unit, :format, :compression, :s3_bucket,
:s3_prefix, :s3_region
:s3_prefix, :s3_region
def to_s
"AWS Billing Report #{report_name}"

View file

@ -15,7 +15,7 @@ class AwsCloudTrailTrail < Inspec.resource(1)
include AwsSingularResourceMixin
attr_reader :cloud_watch_logs_log_group_arn, :cloud_watch_logs_role_arn, :home_region,
:kms_key_id, :s3_bucket_name, :trail_arn
:kms_key_id, :s3_bucket_name, :trail_arn
def to_s
"CloudTrail #{@trail_name}"

View file

@ -16,7 +16,7 @@ class AwsConfigDeliveryChannel < Inspec.resource(1)
include AwsSingularResourceMixin
attr_reader :channel_name, :s3_bucket_name, :s3_key_prefix, :sns_topic_arn,
:delivery_frequency_in_hours
:delivery_frequency_in_hours
def to_s
"Config_Delivery_Channel: #{@channel_name}"

View file

@ -15,8 +15,8 @@ class AwsEcsCluster < Inspec.resource(1)
include AwsSingularResourceMixin
attr_reader :cluster_arn, :cluster_name, :status,
:registered_container_instances_count, :running_tasks_count,
:pending_tasks_count, :active_services_count, :statistics
:registered_container_instances_count, :running_tasks_count,
:pending_tasks_count, :active_services_count, :statistics
def to_s
"AWS ECS cluster #{cluster_name}"

View file

@ -15,9 +15,9 @@ class AwsEksCluster < Inspec.resource(1)
include AwsSingularResourceMixin
attr_reader :version, :arn, :cluster_name, :certificate_authority, :name,
:status, :endpoint, :subnets_count, :subnet_ids, :security_group_ids,
:created_at, :role_arn, :vpc_id, :security_groups_count, :creating,
:active, :failed, :deleting
:status, :endpoint, :subnets_count, :subnet_ids, :security_group_ids,
:created_at, :role_arn, :vpc_id, :security_groups_count, :creating,
:active, :failed, :deleting
# Use aliases for matchers
alias active? active
alias failed? failed

View file

@ -14,8 +14,8 @@ class AwsElb < Inspec.resource(1)
include AwsSingularResourceMixin
attr_reader :availability_zones, :dns_name, :elb_name, :external_ports,
:instance_ids, :internal_ports, :security_group_ids,
:subnet_ids, :vpc_id
:instance_ids, :internal_ports, :security_group_ids,
:subnet_ids, :vpc_id
def to_s
"AWS ELB #{elb_name}"

View file

@ -55,7 +55,7 @@ class AwsFlowLog < Inspec.resource(1)
if validated_params.empty?
raise ArgumentError,
"aws_flow_log requires a parameter: flow_log_id, subnet_id, or vpc_id"
"aws_flow_log requires a parameter: flow_log_id, subnet_id, or vpc_id"
end
validated_params

View file

@ -17,7 +17,7 @@ class AwsIamUser < Inspec.resource(1)
include AwsSingularResourceMixin
attr_reader :access_keys, :attached_policy_names, :attached_policy_arns, \
:has_console_password, :has_mfa_enabled, :inline_policy_names, :username
:has_console_password, :has_mfa_enabled, :inline_policy_names, :username
alias has_mfa_enabled? has_mfa_enabled
alias has_console_password? has_console_password

View file

@ -15,8 +15,8 @@ class AwsKmsKey < Inspec.resource(1)
include AwsSingularResourceMixin
attr_reader :key_id, :arn, :creation_date, :key_usage, :key_state, :description,
:deletion_date, :valid_to, :external, :has_key_expiration, :managed_by_aws,
:has_rotation_enabled, :enabled
:deletion_date, :valid_to, :external, :has_key_expiration, :managed_by_aws,
:has_rotation_enabled, :enabled
# Use aliases for matchers
alias deletion_time deletion_date
alias invalidation_time valid_to

View file

@ -33,8 +33,8 @@ class AwsRouteTable < Inspec.resource(1)
if validated_params.key?(:route_table_id) &&
validated_params[:route_table_id] !~ /^rtb\-([0-9a-f]{17})|(^rtb\-[0-9a-f]{8})$/
raise ArgumentError,
"aws_route_table Route Table ID must be in the" \
' format "rtb-" followed by 8 or 17 hexadecimal characters.'
"aws_route_table Route Table ID must be in the" \
' format "rtb-" followed by 8 or 17 hexadecimal characters.'
end
validated_params

View file

@ -20,7 +20,7 @@ class AwsSnsSubscription < Inspec.resource(1)
include AwsSingularResourceMixin
attr_reader :arn, :owner, :raw_message_delivery, :topic_arn, :endpoint, :protocol,
:confirmation_was_authenticated, :aws_response
:confirmation_was_authenticated, :aws_response
alias confirmation_authenticated? confirmation_was_authenticated
alias raw_message_delivery? raw_message_delivery

View file

@ -15,8 +15,8 @@ class AwsSubnet < Inspec.resource(1)
include AwsSingularResourceMixin
attr_reader :assigning_ipv_6_address_on_creation, :availability_zone, :available_ip_address_count,
:available, :cidr_block, :default_for_az, :ipv_6_cidr_block_association_set,
:mapping_public_ip_on_launch, :subnet_id, :vpc_id
:available, :cidr_block, :default_for_az, :ipv_6_cidr_block_association_set,
:mapping_public_ip_on_launch, :subnet_id, :vpc_id
alias available? available
alias default_for_az? default_for_az
alias mapping_public_ip_on_launch? mapping_public_ip_on_launch

View file

@ -19,8 +19,8 @@ class AwsVpc < Inspec.resource(1)
"VPC #{vpc_id}"
end
attr_reader :cidr_block, :dhcp_options_id, :instance_tenancy, :is_default,\
:state, :vpc_id
attr_reader :cidr_block, :dhcp_options_id, :instance_tenancy, :is_default,
:state, :vpc_id
alias default? is_default

View file

@ -210,11 +210,11 @@ describe "example inheritance profile" do
local_depends_path = File.join(profile_path, "local-depends")
dir_profile_path = File.join(profile_path, "complete-profile")
tar_profile_path = File.join(profile_path,
"archived-profiles",
"tar_profile-1.0.0.tar.gz")
"archived-profiles",
"tar_profile-1.0.0.tar.gz")
zip_profile_path = File.join(profile_path,
"archived-profiles",
"zip_profile-1.0.0.zip")
"archived-profiles",
"zip_profile-1.0.0.zip")
Dir.mktmpdir do |tmpdir|
[dir_profile_path, tar_profile_path, zip_profile_path].each do |profile|

View file

@ -28,11 +28,12 @@ describe Inspec::Input do
describe "marshalling" do
it "should be able to represent an Input as a Hash" do
input = Inspec::Input.new("test_input",
value: 12,
title: "Best input ever",
description: "important",
type: "Numeric",
required: true)
value: 12,
title: "Best input ever",
description: "important",
type: "Numeric",
required: true)
_(input.to_hash).must_equal({
name: "test_input",
options: {

View file

@ -104,21 +104,25 @@ EOF
_(res.params[:name]).must_be_nil
end
def from_yaml(str)
Inspec::Metadata.from_yaml("mock", "---\nsupports:\n - #{str}", nil)
end
it "loads the support field from metadata" do
res = Inspec::Metadata.from_yaml("mock",
"---\nsupports:\n - os: ubuntu", nil)
res = from_yaml("os: ubuntu")
_(res.params[:supports]).must_equal([{ os: "ubuntu" }])
end
it "makes sure the supports release field is a string" do
res = Inspec::Metadata.from_yaml("mock",
"---\nsupports:\n - release: 12.02", nil)
res = from_yaml("release: 12.02")
_(res.params[:supports]).must_equal([{ release: "12.02" }])
end
it "makes sure the supports release field is nil if not configured" do
res = Inspec::Metadata.from_yaml("mock",
"---\nsupports:\n - release: ", nil)
res = from_yaml("release: ")
_(res.params[:supports]).must_equal([{ release: nil }])
end

View file

@ -266,8 +266,10 @@ describe Inspec::ProfileContext do
describe "adds a check via describe" do
let(:check) do
profile.load(format(context_format,
"describe(os[:family]) { it { must_equal 'debian' } }"))
profile.load(
format(context_format,
"describe(os[:family]) { it { must_equal 'debian' } }")
)
get_checks[0]
end
@ -286,8 +288,10 @@ describe Inspec::ProfileContext do
describe "adds a check via expect" do
let(:check) do
profile.load(format(context_format,
"expect(os[:family]).to eq('debian')"))
profile.load(
format(context_format,
"expect(os[:family]).to eq('debian')")
)
get_checks[0]
end
@ -306,10 +310,12 @@ describe Inspec::ProfileContext do
describe "adds a check via describe + expect" do
let(:check) do
profile.load(format(context_format,
"describe 'the actual test' do
profile.load(
format(context_format,
"describe 'the actual test' do
expect(os[:family]).to eq('debian')
end"))
end")
)
get_checks[0]
end

View file

@ -34,11 +34,11 @@ class BasicAwsFlowLog < Minitest::Test
def test_to_s
assert_equal "AWS Flow Log fl-abcd1234",
AwsFlowLog.new(flow_log_id: "fl-abcd1234").to_s
AwsFlowLog.new(flow_log_id: "fl-abcd1234").to_s
assert_equal "AWS Flow Log fl-abcd3333",
AwsFlowLog.new(subnet_id: "subnet-abcd3333").to_s
AwsFlowLog.new(subnet_id: "subnet-abcd3333").to_s
assert_equal "AWS Flow Log fl-abcd1111",
AwsFlowLog.new(vpc_id: "vpc-abcd1111").to_s
AwsFlowLog.new(vpc_id: "vpc-abcd1111").to_s
end
def test_flow_log_id

View file

@ -5,12 +5,16 @@ require "inspec/resources/mysql_session"
describe "Inspec::Resources::MysqlSession" do
it "verify mysql_session escaped login details with single quotes correctly" do
resource = load_resource("mysql_session",
"root",
%q{'%"'"&^*&()'*%})
_(resource.send(:create_mysql_cmd, "SELECT 1 FROM DUAL;")).must_equal(%q{mysql -uroot -p\'\%\"\'\"\&\^\*\&\(\)\'\*\% -h localhost -s -e "SELECT 1 FROM DUAL;"})
"root",
%q{'%"'"&^*&()'*%})
_(resource.send(:create_mysql_cmd, "SELECT 1 FROM DUAL;"))
.must_equal(%q{mysql -uroot -p\'\%\"\'\"\&\^\*\&\(\)\'\*\% -h localhost -s -e "SELECT 1 FROM DUAL;"})
end
it "verify mysql_session omits optional username and password" do
resource = load_resource("mysql_session")
_(resource.send(:create_mysql_cmd, "SELECT 1 FROM DUAL;")).must_equal('mysql -h localhost -s -e "SELECT 1 FROM DUAL;"')
_(resource.send(:create_mysql_cmd, "SELECT 1 FROM DUAL;"))
.must_equal('mysql -h localhost -s -e "SELECT 1 FROM DUAL;"')
end
end

View file

@ -16,7 +16,7 @@ class TestLinuxPorts < Minitest::Test
"protocol" => "tcp",
"process" => "sshd",
"pid" => 1222 }),
@linuxports.parse_ss_line(ss_line)
@linuxports.parse_ss_line(ss_line)
end
def test_parse_ss_line_ipv4
@ -27,7 +27,7 @@ class TestLinuxPorts < Minitest::Test
"protocol" => "tcp",
"process" => "sshd",
"pid" => 1222 }),
@linuxports.parse_ss_line(ss_line)
@linuxports.parse_ss_line(ss_line)
end
def test_parse_ss_line_ipv6
@ -37,7 +37,7 @@ class TestLinuxPorts < Minitest::Test
"protocol" => "tcp6",
"process" => "java",
"pid" => 1722 }),
@linuxports.parse_ss_line(ss_line)
@linuxports.parse_ss_line(ss_line)
end
def test_parse_ss_line_ipv6_wildcard
@ -47,7 +47,7 @@ class TestLinuxPorts < Minitest::Test
"protocol" => "tcp6",
"process" => "sshd",
"pid" => 1222 }),
@linuxports.parse_ss_line(ss_line)
@linuxports.parse_ss_line(ss_line)
end
def test_parse_ss_line_ipv6_wildcard_brackets
@ -57,7 +57,7 @@ class TestLinuxPorts < Minitest::Test
"protocol" => "tcp6",
"process" => "sshd",
"pid" => 1222 }),
@linuxports.parse_ss_line(ss_line)
@linuxports.parse_ss_line(ss_line)
end
def test_parse_ss_line_ipv6_address_brackets
@ -67,6 +67,6 @@ class TestLinuxPorts < Minitest::Test
"protocol" => "tcp6",
"process" => "java",
"pid" => 1722 }),
@linuxports.parse_ss_line(ss_line)
@linuxports.parse_ss_line(ss_line)
end
end