From 860434a1d5424b1265c9076439ac90cfb5a2be5a Mon Sep 17 00:00:00 2001 From: Will Stranathan Date: Mon, 13 Jan 2014 14:16:41 -0500 Subject: [PATCH] Added files I missed during the last change Former-commit-id: 2f6f9cdb93c3a3f055694447b8a5d5bfbe440708 --- .../owasp/dependencycheck/utils/Settings.java | 8 +++ .../data/nexus/NexusSearchTest.java | 56 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 dependency-check-core/src/test/java/org/owasp/dependencycheck/data/nexus/NexusSearchTest.java diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java index 81a94a009..706399999 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/Settings.java @@ -147,6 +147,14 @@ public final class Settings { * The key for a list of suppression files. */ public static final String SUPPRESSION_FILE = "suppression.file"; + /** + * The properties key for whether the Nexus analyzer is enabled. + */ + public static final String ANALYZER_NEXUS_ENABLED = "analyzer.nexus.enabled"; + /** + * The properties key for the Nexus search URL. + */ + public static final String ANALYZER_NEXUS_URL = "analyzer.nexus.url"; } /** * The properties file location. diff --git a/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/nexus/NexusSearchTest.java b/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/nexus/NexusSearchTest.java new file mode 100644 index 000000000..e19fab5a2 --- /dev/null +++ b/dependency-check-core/src/test/java/org/owasp/dependencycheck/data/nexus/NexusSearchTest.java @@ -0,0 +1,56 @@ +package org.owasp.dependencycheck.data.nexus; + +import java.io.FileNotFoundException; +import java.net.URL; +import java.util.logging.Logger; + +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import org.owasp.dependencycheck.utils.Settings; + +public class NexusSearchTest { + private static final Logger LOGGER = Logger.getLogger(NexusSearchTest.class.getName()); + private NexusSearch searcher; + + @Before + public void setUp() throws Exception { + String nexusUrl = Settings.getString(Settings.KEYS.ANALYZER_NEXUS_URL); + LOGGER.fine(nexusUrl); + searcher = new NexusSearch(new URL(nexusUrl)); + } + + @Test(expected = IllegalArgumentException.class) + public void testNullSha1() throws Exception { + searcher.searchSha1(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testMalformedSha1() throws Exception { + searcher.searchSha1("invalid"); + } + + // This test does generate network traffic and communicates with a host + // you may not be able to reach. Remove the @Ignore annotation if you want to + // test it anyway + @Ignore @Test + public void testValidSha1() throws Exception { + MavenArtifact ma = searcher.searchSha1("9977a8d04e75609cf01badc4eb6a9c7198c4c5ea"); + assertEquals("Incorrect group", "org.apache.maven.plugins", ma.getGroupId()); + assertEquals("Incorrect artifact", "maven-compiler-plugin", ma.getArtifactId()); + assertEquals("Incorrect version", "3.1", ma.getVersion()); + assertNotNull("URL Should not be null", ma.getArtifactUrl()); + } + + // This test does generate network traffic and communicates with a host + // you may not be able to reach. Remove the @Ignore annotation if you want to + // test it anyway + @Ignore @Test(expected = FileNotFoundException.class) + public void testMissingSha1() throws Exception { + searcher.searchSha1("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); + } +} + +// vim: cc=120:sw=4:ts=4:sts=4