Skip to content

Commit 88e7362

Browse files
committed
Update specs to use Gemfile.lock files
1 parent f97ba50 commit 88e7362

File tree

8 files changed

+429
-61
lines changed

8 files changed

+429
-61
lines changed

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ gem "rake"
77

88
group :test do
99
gem "rspec", require: false
10-
gem "fakefs", require: false
1110
end

Gemfile.lock

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
blockenspiel (0.4.5)
4+
blockenspiel (0.5.0)
55
bundler-audit (0.4.0)
66
bundler (~> 1.2)
77
thor (~> 0.18)
88
diff-lcs (1.2.5)
9-
fakefs (0.6.7)
109
json (1.8.3)
1110
rake (10.4.2)
1211
rspec (3.3.0)
@@ -23,15 +22,14 @@ GEM
2322
rspec-support (~> 3.3.0)
2423
rspec-support (3.3.0)
2524
thor (0.19.1)
26-
versionomy (0.4.4)
27-
blockenspiel (>= 0.4.5)
25+
versionomy (0.5.0)
26+
blockenspiel (~> 0.5)
2827

2928
PLATFORMS
3029
ruby
3130

3231
DEPENDENCIES
3332
bundler-audit
34-
fakefs
3533
json
3634
rake
3735
rspec

lib/cc/engine/bundler_audit.rb

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@ def initialize(directory: , io: , engine_config: )
1919

2020
def run
2121
if gemfile_lock_exists?
22-
Dir.chdir(@directory)
23-
raw_output = `bundle-audit`
24-
raw_issues = raw_output.split(/\n\n/).select { |chunk|
25-
chunk =~ /^Name: /
26-
}
27-
@gemfile_lock_lines = File.read(
28-
File.join(@directory, 'Gemfile.lock')
29-
).lines
30-
raw_issues.each do |raw_issue|
31-
issue = issue_from_raw(raw_issue)
32-
@io.print("#{issue.to_json}\0")
22+
Dir.chdir(@directory) do
23+
raw_output = `bundle-audit`
24+
raw_issues = raw_output.split(/\n\n/).select { |chunk|
25+
chunk =~ /^Name: /
26+
}
27+
@gemfile_lock_lines = File.read(
28+
File.join(@directory, 'Gemfile.lock')
29+
).lines
30+
raw_issues.each do |raw_issue|
31+
issue = issue_from_raw(raw_issue)
32+
@io.print("#{issue.to_json}\0")
33+
end
3334
end
3435
else
3536
raise GemfileLockNotFound, "No Gemfile.lock found."

spec/cc/engine/bundler_audit_spec.rb

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,29 @@ module CC::Engine
44
describe BundlerAudit do
55
describe "#run" do
66
it "raises an error when no Gemfile.lock exists" do
7-
FakeFS do
8-
directory = "/c"
9-
FileUtils.mkdir_p(directory)
10-
io = StringIO.new
11-
config = {}
7+
directory = File.join(Dir.pwd, "spec", "fixtures", "no_gemfile_lock")
8+
io = StringIO.new
129

13-
expect { BundlerAudit.new(directory: directory, io: io, engine_config: config).run }
14-
.to raise_error(CC::Engine::BundlerAudit::GemfileLockNotFound)
15-
end
10+
expect { BundlerAudit.new(directory: directory, io: io, engine_config: {}).run }
11+
.to raise_error(CC::Engine::BundlerAudit::GemfileLockNotFound)
1612
end
1713

1814
it "emits issues for Gemfile.lock problems" do
19-
bundle_audit_output = <<-EOF
20-
Name: actionpack
21-
Version: 3.2.10
22-
Advisory: OSVDB-91452
23-
Criticality: Medium
24-
URL: http://www.osvdb.org/show/osvdb/91452
25-
Title: XSS vulnerability in sanitize_css in Action Pack
26-
Solution: upgrade to ~> 2.3.18, ~> 3.1.12, >= 3.2.13
27-
EOF
28-
result = {
29-
categories: ["Security"],
30-
check_name: "Insecure Dependency",
31-
content: {
32-
body: "**Advisory**: OSVDB-91452\n\n**Criticality**: Medium\n\n**URL**: http://www.osvdb.org/show/osvdb/91452\n\n**Solution**: upgrade to ~> 2.3.18, ~> 3.1.12, >= 3.2.13"
33-
},
34-
description: "XSS vulnerability in sanitize_css in Action Pack",
35-
location: {
36-
path: "Gemfile.lock",
37-
lines: { begin: nil, end: nil }
38-
},
39-
remediation_points: 500_000,
40-
severity: "normal",
41-
type: "Issue",
42-
}.to_json
4315
io = StringIO.new
44-
directory = "/c"
45-
config = {}
46-
47-
FakeFS do
48-
FileUtils.mkdir_p(directory)
49-
FileUtils.touch("/c/Gemfile.lock")
16+
directory = File.join(Dir.pwd, "spec", "fixtures", "unpatched_versions")
5017

51-
audit = BundlerAudit.new(directory: directory, io: io, engine_config: config)
18+
audit = BundlerAudit.new(directory: directory, io: io, engine_config: {})
19+
audit.run
5220

53-
allow(audit).to receive(:`).and_return(bundle_audit_output)
21+
issues = io.string.split("\0").map { |issue| JSON.load(issue) }
5422

55-
audit.run
56-
end
23+
expect(issues).to eq(expected_issues("unpatched_versions"))
24+
end
5725

58-
expect(io.string).to eq("#{result}\0")
26+
def expected_issues(fixture)
27+
path = File.join(Dir.pwd, "spec", "fixtures", fixture, "issues.json")
28+
body = File.read(path)
29+
JSON.load(body)
5930
end
6031
end
6132
end

spec/fixtures/no_gemfile_lock/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)