Merge pull request #475 from biancajiang/master

Fix test to skip the proper test case when bundle-audit is not available
This commit is contained in:
Jeremy Long
2016-03-25 19:34:34 -04:00

View File

@@ -57,15 +57,9 @@ public class RubyBundleAuditAnalyzerTest extends BaseTest {
*/ */
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
try {
Settings.initialize(); Settings.initialize();
analyzer = new RubyBundleAuditAnalyzer(); analyzer = new RubyBundleAuditAnalyzer();
analyzer.setFilesMatched(true); analyzer.setFilesMatched(true);
analyzer.initialize();
} catch (Exception e) {
//LOGGER.warn("Exception setting up RubyBundleAuditAnalyzer. Tests will be incomplete", e);
Assume.assumeNoException("Exception setting up RubyBundleAuditAnalyzer; bundle audit may not be installed. Tests will be incomplete", e);
}
} }
/** /**
@@ -103,6 +97,9 @@ public class RubyBundleAuditAnalyzerTest extends BaseTest {
*/ */
@Test @Test
public void testAnalysis() throws AnalysisException, DatabaseException { public void testAnalysis() throws AnalysisException, DatabaseException {
try {
analyzer.initialize();
final Dependency result = new Dependency(BaseTest.getResourceAsFile(this, final Dependency result = new Dependency(BaseTest.getResourceAsFile(this,
"ruby/vulnerable/gems/rails-4.1.15/Gemfile.lock")); "ruby/vulnerable/gems/rails-4.1.15/Gemfile.lock"));
final Engine engine = new Engine(); final Engine engine = new Engine();
@@ -113,8 +110,12 @@ public class RubyBundleAuditAnalyzerTest extends BaseTest {
Dependency dependency = engine.getDependencies().get(0); Dependency dependency = engine.getDependencies().get(0);
assertTrue(dependency.getProductEvidence().toString().toLowerCase().contains("redcarpet")); assertTrue(dependency.getProductEvidence().toString().toLowerCase().contains("redcarpet"));
assertTrue(dependency.getVersionEvidence().toString().toLowerCase().contains("2.2.2")); assertTrue(dependency.getVersionEvidence().toString().toLowerCase().contains("2.2.2"));
}
} catch (Exception e) {
LOGGER.warn("Exception setting up RubyBundleAuditAnalyzer. Make sure Ruby gem bundle-audit is installed. You may also need to set property \"analyzer.bundle.audit.path\".", e);
Assume.assumeNoException("Exception setting up RubyBundleAuditAnalyzer; bundle audit may not be installed, or property \"analyzer.bundle.audit.path\" may not be set.", e);
}
}
/** /**
* Test when Ruby bundle-audit is not available on the system. * Test when Ruby bundle-audit is not available on the system.
@@ -133,7 +134,7 @@ public class RubyBundleAuditAnalyzerTest extends BaseTest {
} }
finally { finally {
assertThat(analyzer.isEnabled(), is(false)); assertThat(analyzer.isEnabled(), is(false));
LOGGER.info("Ruby Bundle Audit Analyzer is disabled as expected."); LOGGER.info("phantom-bundle-audit is not available. Ruby Bundle Audit Analyzer is disabled as expected.");
} }
} }
} }