1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.owasp.dependencycheck.data.nexus;
19
20 import java.io.FileNotFoundException;
21 import java.net.URL;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotNull;
24 import org.junit.Assume;
25 import org.junit.Before;
26 import org.junit.Ignore;
27 import org.junit.Test;
28 import org.owasp.dependencycheck.BaseTest;
29 import org.owasp.dependencycheck.analyzer.NexusAnalyzer;
30 import org.owasp.dependencycheck.utils.Settings;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class NexusSearchTest extends BaseTest {
35
36 private static final Logger LOGGER = LoggerFactory.getLogger(NexusSearchTest.class);
37 private NexusSearch searcher;
38
39 @Before
40 public void setUp() throws Exception {
41 String nexusUrl = Settings.getString(Settings.KEYS.ANALYZER_NEXUS_URL);
42 LOGGER.debug(nexusUrl);
43 searcher = new NexusSearch(new URL(nexusUrl), NexusAnalyzer.useProxy());
44 Assume.assumeTrue(searcher.preflightRequest());
45 }
46
47 @Test(expected = IllegalArgumentException.class)
48 @Ignore
49 public void testNullSha1() throws Exception {
50 searcher.searchSha1(null);
51 }
52
53 @Test(expected = IllegalArgumentException.class)
54 @Ignore
55 public void testMalformedSha1() throws Exception {
56 searcher.searchSha1("invalid");
57 }
58
59
60
61
62 @Test
63 @Ignore
64 public void testValidSha1() throws Exception {
65 MavenArtifact ma = searcher.searchSha1("9977a8d04e75609cf01badc4eb6a9c7198c4c5ea");
66 assertEquals("Incorrect group", "org.apache.maven.plugins", ma.getGroupId());
67 assertEquals("Incorrect artifact", "maven-compiler-plugin", ma.getArtifactId());
68 assertEquals("Incorrect version", "3.1", ma.getVersion());
69 assertNotNull("URL Should not be null", ma.getArtifactUrl());
70 }
71
72
73
74
75 @Test(expected = FileNotFoundException.class)
76 @Ignore
77 public void testMissingSha1() throws Exception {
78 searcher.searchSha1("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
79 }
80 }
81
82