Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lint #20

Merged
merged 5 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ Metrics/PerceivedComplexity:
Max: 10
Metrics/AbcSize:
Max: 30
# Lint/AmbiguousBlockAssociation is incompatible with RSpec
# https://github.com/rubocop-hq/rubocop/issues/4222
Lint/AmbiguousBlockAssociation:
Enabled: false
3 changes: 1 addition & 2 deletions Rakefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env rake
# encoding: utf-8
# frozen_string_literal: true

require 'rake/testtask'
require 'rubocop/rake_task'
Expand Down
9 changes: 5 additions & 4 deletions controls/patches.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: utf-8
# frozen_string_literal: true

# copyright: 2016, Christoph Hartmann
# license: MPLv2
Expand Down Expand Up @@ -29,11 +30,11 @@
control 'important-patches' do
impact 1.0
title 'All important updates are installed'
win_update.important.each { |update|
win_update.important.each do |update|
describe update do
it { should be_installed }
end
}
end
end

control 'optional-count' do
Expand All @@ -47,9 +48,9 @@
control 'optional-patches' do
impact 0.3
title 'All optional updates are installed'
win_update.optional.each { |update|
win_update.optional.each do |update|
describe update do
it { should be_installed }
end
}
end
end
24 changes: 13 additions & 11 deletions libraries/windows_updates.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# encoding: utf-8
# frozen_string_literal: true

# copyright: 2016, Christoph Hartmann
# license: MPLv2
Expand Down Expand Up @@ -49,8 +50,9 @@ class WindowsUpdateManager < Inspec.resource(1)
desc 'Use the windows_update InSpec audit resource to test available or installed updates on Microsoft Windows.'

def initialize
super()
# verify that this resource is only supported on Windows
return skip_resource 'The `windows_update` resource is not supported on your OS.' if !inspec.os.windows?
return skip_resource 'The `windows_update` resource is not supported on your OS.' unless inspec.os.windows? # rubocop:disable Lint/ReturnInVoidContext

@update_mgmt = select_update_mgmt
end
Expand All @@ -65,27 +67,27 @@ def all
def important
updates = fetch_updates
updates
.select { |update|
.select do |update|
@update_mgmt.important?(update)
}.map { |update| # rubocop:disable Style/MultilineBlockChain
end.map do |update| # rubocop:disable Style/MultilineBlockChain
WindowsUpdate.new(update)
}
end
end

# returns all optional updates
def optional
updates = fetch_updates
updates.select { |update|
updates.select do |update|
@update_mgmt.optional?(update)
}.map { |update| # rubocop:disable Style/MultilineBlockChain
end.map do |update| # rubocop:disable Style/MultilineBlockChain
WindowsUpdate.new(update)
}
end
end

def reboot_required?
return @chache_reboot if defined?(@chache_reboot)
return @reboot_required if defined?(@reboot_required)

@chache_reboot = inspec.registry_key('HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update').has_property?('RebootRequired')
@reboot_required = inspec.registry_key('HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update').has_property?('RebootRequired')
end

def to_s
Expand Down Expand Up @@ -148,7 +150,7 @@ def hotfixes
begin
@cache_hotfix_installed = JSON.parse(cmd.stdout)
rescue JSON::ParserError => _e
return []
[]
end
end

Expand Down Expand Up @@ -247,7 +249,7 @@ def fetch_updates
end

def important?(update)
%w{Important Critical}.include? update['MsrcSeverity']
%w[Important Critical].include? update['MsrcSeverity']
end

def optional?(update)
Expand Down