@@ -5,22 +5,51 @@ module CC::Engine::BundlerAudit
5
5
describe "#run" do
6
6
it "raises an error when no Gemfile.lock exists" do
7
7
directory = fixture_directory ( "no_gemfile_lock" )
8
- io = StringIO . new
9
8
10
- expect { Analyzer . new ( directory : directory , io : io ) . run } .
9
+ expect { Analyzer . new ( directory : directory ) . run } .
11
10
to raise_error ( Analyzer ::GemfileLockNotFound )
12
11
end
13
12
14
- it "emits issues for Gemfile.lock problems" do
15
- io = StringIO . new
13
+ it "emits issues for unpatched gems in Gemfile.lock" do
16
14
directory = fixture_directory ( "unpatched_versions" )
17
15
18
- audit = Analyzer . new ( directory : directory , io : io )
16
+ issues = analyze_directory ( directory )
17
+
18
+ expect ( issues ) . to eq ( expected_issues ( "unpatched_versions" ) )
19
+ end
20
+
21
+ it "emits issues for insecure sources in Gemfile.lock" do
22
+ directory = fixture_directory ( "insecure_source" )
23
+
24
+ issues = analyze_directory ( directory )
25
+
26
+ expect ( issues ) . to eq ( expected_issues ( "insecure_source" ) )
27
+ end
28
+
29
+ it "logs to stderr when we encounter an unsupported vulnerability" do
30
+ directory = fixture_directory ( "unpatched_versions" )
31
+ stderr = StringIO . new
32
+
33
+ stub_vulnerability ( "UnhandledVulnerability" )
34
+
35
+ analyze_directory ( directory , stderr : stderr )
36
+
37
+ expect ( stderr . string ) . to eq ( "Unsupported vulnerability: UnhandledVulnerability" )
38
+ end
39
+
40
+ def analyze_directory ( directory , stdout : StringIO . new , stderr : StringIO . new )
41
+ audit = Analyzer . new ( directory : directory , stdout : stdout , stderr : stderr )
19
42
audit . run
20
43
21
- issues = io . string . split ( "\0 " ) . map { |issue | JSON . load ( issue ) }
44
+ stdout . string . split ( "\0 " ) . map { |issue | JSON . load ( issue ) }
45
+ end
46
+
47
+ def stub_vulnerability ( name )
48
+ scanner = double ( :scanner )
49
+ vulnerability = double ( :vulnerability , class : double ( name : name ) )
22
50
23
- expect ( issues ) . to eq ( expected_issues ( "unpatched_versions" ) )
51
+ allow ( Bundler ::Audit ::Scanner ) . to receive ( :new ) . and_return ( scanner )
52
+ allow ( scanner ) . to receive ( :scan ) . and_yield ( vulnerability )
24
53
end
25
54
26
55
def expected_issues ( fixture )
0 commit comments