@@ -4,58 +4,29 @@ module CC::Engine
4
4
describe BundlerAudit do
5
5
describe "#run" do
6
6
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
12
9
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 )
16
12
end
17
13
18
14
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
43
15
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" )
50
17
51
- audit = BundlerAudit . new ( directory : directory , io : io , engine_config : config )
18
+ audit = BundlerAudit . new ( directory : directory , io : io , engine_config : { } )
19
+ audit . run
52
20
53
- allow ( audit ) . to receive ( :` ) . and_return ( bundle_audit_output )
21
+ issues = io . string . split ( " \0 " ) . map { | issue | JSON . load ( issue ) }
54
22
55
- audit . run
56
- end
23
+ expect ( issues ) . to eq ( expected_issues ( "unpatched_versions" ) )
24
+ end
57
25
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 )
59
30
end
60
31
end
61
32
end
0 commit comments