@@ -5,22 +5,51 @@ module CC::Engine::BundlerAudit
55 describe "#run" do
66 it "raises an error when no Gemfile.lock exists" do
77 directory = fixture_directory ( "no_gemfile_lock" )
8- io = StringIO . new
98
10- expect { Analyzer . new ( directory : directory , io : io ) . run } .
9+ expect { Analyzer . new ( directory : directory ) . run } .
1110 to raise_error ( Analyzer ::GemfileLockNotFound )
1211 end
1312
14- it "emits issues for Gemfile.lock problems" do
15- io = StringIO . new
13+ it "emits issues for unpatched gems in Gemfile.lock" do
1614 directory = fixture_directory ( "unpatched_versions" )
1715
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 )
1942 audit . run
2043
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 ) )
2250
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 )
2453 end
2554
2655 def expected_issues ( fixture )
0 commit comments