Skip to content

Commit 0f8e0fa

Browse files
committed
Merge pull request #6 from codeclimate/gd-content
Add content for issues
2 parents 5e2fa78 + 770d320 commit 0f8e0fa

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

.rubocop.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Metrics/AbcSize:
2+
Enabled: false
3+
4+
Metrics/LineLength:
5+
Enabled: false
6+
7+
Rails/TimeZone:
8+
Enabled: false
9+
10+
SignalException:
11+
Enabled: false
12+
13+
Style/StringLiterals:
14+
Enabled: false
15+
16+
Style/Documentation:
17+
Enabled: false
18+
19+
Style/TrailingComma:
20+
Enabled: false
21+
22+
Style/ClassAndModuleChildren:
23+
Exclude:
24+
- 'spec/**/*'
25+
26+
Style/IfUnlessModifier:
27+
Enabled: false
28+
29+
Style/DotPosition:
30+
Enabled: false
31+
32+
Style/GuardClause:
33+
Enabled: false
34+
35+
Style/StringLiteralsInInterpolation:
36+
Enabled: false
37+
38+
Style/PercentLiteralDelimiters:
39+
PreferredDelimiters:
40+
'%w': []
41+
'%W': []

lib/cc/engine/bundler_audit.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ def issue_from_raw(raw_issue)
6565
begin: line_number,
6666
end: line_number
6767
}
68+
},
69+
content: {
70+
body: content_body(raw_issue_hash)
6871
}
6972
}
7073
end
@@ -95,6 +98,12 @@ def remediation_points(current_version, raw_solution)
9598
500_000_000 # No upgrade of gem possible
9699
end
97100
end
101+
102+
def content_body(raw_issue_hash)
103+
%w[Advisory Criticality URL Solution].map do |key|
104+
"**#{key}**: #{raw_issue_hash[key]}"
105+
end.join("\n\n")
106+
end
98107
end
99108
end
100109
end

spec/cc/engine/bundler_audit_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,48 @@ module CC::Engine
1515
expect(io.string).to match(%{{"type":"warning","description":"No Gemfile.lock file found"}})
1616
end
1717
end
18+
19+
it "emits issues for Gemfile.lock problems" do
20+
bundle_audit_output = <<-EOF
21+
Name: actionpack
22+
Version: 3.2.10
23+
Advisory: OSVDB-91452
24+
Criticality: Medium
25+
URL: http://www.osvdb.org/show/osvdb/91452
26+
Title: XSS vulnerability in sanitize_css in Action Pack
27+
Solution: upgrade to ~> 2.3.18, ~> 3.1.12, >= 3.2.13
28+
EOF
29+
result = {
30+
type: "Issue",
31+
check_name: "Insecure Dependency",
32+
description: "XSS vulnerability in sanitize_css in Action Pack",
33+
categories: ["Security"],
34+
remediation_points: 500_000,
35+
location: {
36+
path: "Gemfile.lock",
37+
lines: { begin: nil, end: nil }
38+
},
39+
content: {
40+
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"
41+
},
42+
}.to_json
43+
io = StringIO.new
44+
directory = "/c"
45+
config = {}
46+
47+
FakeFS do
48+
FileUtils.mkdir_p(directory)
49+
FileUtils.touch("/c/Gemfile.lock")
50+
51+
audit = BundlerAudit.new(directory: directory, io: io, engine_config: config)
52+
53+
allow(audit).to receive(:`).and_return(bundle_audit_output)
54+
55+
audit.run
56+
end
57+
58+
expect(io.string).to match("#{result}\0")
59+
end
1860
end
1961
end
2062
end

0 commit comments

Comments
 (0)