Skip to content

Commit 389e002

Browse files
authored
Merge pull request #17 from dev-sec/dom/vuln-rubocop
fix vulnerable rubocop version for testing
2 parents e991252 + 7f9c76d commit 389e002

3 files changed

Lines changed: 26 additions & 18 deletions

File tree

.rubocop.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ HashSyntax:
1515
Enabled: true
1616
LineLength:
1717
Enabled: false
18+
Layout/IndentHeredoc:
19+
Enabled: false
1820
EmptyLinesAroundBlockBody:
1921
Enabled: false
22+
Style/FormatStringToken:
23+
Enabled: false
24+
Layout/EmptyLineAfterMagicComment:
25+
Enabled: false
2026
MethodLength:
2127
Max: 40
2228
NumericLiterals:
@@ -58,7 +64,9 @@ Style/Not:
5864
Enabled: false
5965
Style/FileName:
6066
Enabled: false
61-
Style/TrailingCommaInLiteral:
67+
Style/TrailingCommaInHashLiteral:
68+
EnforcedStyleForMultiline: comma
69+
Style/TrailingCommaInArrayLiteral:
6270
EnforcedStyleForMultiline: comma
6371
Style/TrailingCommaInArguments:
6472
EnforcedStyleForMultiline: comma

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ gem 'rake'
44
gem 'rack', '1.6.4'
55
gem 'inspec', '~> 1'
66
gem 'highline', '~> 1.6.0'
7-
gem 'rubocop', '~>0.46.0'
7+
gem 'rubocop', '~>0.54.0'
88

99
group :integration do
1010
gem 'berkshelf'

libraries/linux_updates.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def initialize
3333
when 'suse'
3434
@update_mgmt = SuseUpdateFetcher.new(inspec)
3535
end
36-
return skip_resource 'The `linux_update` resource is not supported on your OS.' if @update_mgmt.nil?
36+
skip_resource 'The `linux_update` resource is not supported on your OS.' if @update_mgmt.nil?
3737
end
3838

3939
def updates
@@ -150,57 +150,57 @@ def extract_xml_updates(updates_el)
150150

151151
class UbuntuUpdateFetcher < UpdateFetcher
152152
def packages
153-
ubuntu_packages = ubuntu_base + <<-EOH
153+
ubuntu_packages = ubuntu_base + <<-PRINT_JSON
154154
echo -n '{"installed":['
155155
dpkg-query -W -f='${Status}\\t${Package}\\t${Version}\\t${Architecture}\\n' |\\
156156
grep '^install ok installed\\s' |\\
157157
awk '{ printf "{\\"name\\":\\""$4"\\",\\"version\\":\\""$5"\\",\\"arch\\":\\""$6"\\"}," }' | rev | cut -c 2- | rev | tr -d '\\n'
158158
echo -n ']}'
159-
EOH
159+
PRINT_JSON
160160
parse_json(ubuntu_packages)
161161
end
162162

163163
def updates
164-
ubuntu_updates = ubuntu_base + <<-EOH
164+
ubuntu_updates = ubuntu_base + <<-PRINT_JSON
165165
echo -n '{"available":['
166166
DEBIAN_FRONTEND=noninteractive apt-get upgrade --dry-run | grep Inst | tr -d '[]()' |\\
167167
awk '{ printf "{\\"name\\":\\""$2"\\",\\"version\\":\\""$4"\\",\\"repo\\":\\""$5"\\",\\"arch\\":\\""$6"\\"}," }' | rev | cut -c 2- | rev | tr -d '\\n'
168168
echo -n ']}'
169-
EOH
169+
PRINT_JSON
170170
parse_json(ubuntu_updates)
171171
end
172172

173173
private
174174

175175
def ubuntu_base
176-
base = <<-EOH
177-
#!/bin/sh
178-
DEBIAN_FRONTEND=noninteractive apt-get update >/dev/null 2>&1
179-
readlock() { cat /proc/locks | awk '{print $5}' | grep -v ^0 | xargs -I {1} find /proc/{1}/fd -maxdepth 1 -exec readlink {} \\; | grep '^/var/lib/dpkg/lock$'; }
180-
while test -n "$(readlock)"; do sleep 1; done
181-
echo " "
182-
EOH
176+
base = <<-PRINT_JSON
177+
#!/bin/sh
178+
DEBIAN_FRONTEND=noninteractive apt-get update >/dev/null 2>&1
179+
readlock() { cat /proc/locks | awk '{print $5}' | grep -v ^0 | xargs -I {1} find /proc/{1}/fd -maxdepth 1 -exec readlink {} \\; | grep '^/var/lib/dpkg/lock$'; }
180+
while test -n "$(readlock)"; do sleep 1; done
181+
echo " "
182+
PRINT_JSON
183183
base
184184
end
185185
end
186186

187187
class RHELUpdateFetcher < UpdateFetcher
188188
def packages
189-
rhel_packages = <<-EOH
189+
rhel_packages = <<-PRINT_JSON
190190
sleep 2 && echo " "
191191
echo -n '{"installed":['
192192
rpm -qa --queryformat '"name":"%{NAME}","version":"%{VERSION}-%{RELEASE}","arch":"%{ARCH}"\\n' |\\
193193
awk '{ printf "{"$1"}," }' | rev | cut -c 2- | rev | tr -d '\\n'
194194
echo -n ']}'
195-
EOH
195+
PRINT_JSON
196196
parse_json(rhel_packages)
197197
end
198198

199199
def updates
200-
rhel_updates = <<-EOH
200+
rhel_updates = <<-PRINT_JSON
201201
#!/bin/sh
202202
python -c 'import sys; sys.path.insert(0, "/usr/share/yum-cli"); import cli; list = cli.YumBaseCli().returnPkgLists(["updates"]);res = ["{\\"name\\":\\""+x.name+"\\", \\"version\\":\\""+x.version+"-"+x.release+"\\",\\"arch\\":\\""+x.arch+"\\",\\"repository\\":\\""+x.repo.id+"\\"}" for x in list.updates]; print "{\\"available\\":["+",".join(res)+"]}"'
203-
EOH
203+
PRINT_JSON
204204
cmd = @inspec.bash(rhel_updates)
205205
unless cmd.exit_status == 0
206206
# essentially we want https://github.com/chef/inspec/issues/1205

0 commit comments

Comments
 (0)