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.utils.Settings;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class NexusSearchTest extends BaseTest {
34
35 private static final Logger LOGGER = LoggerFactory.getLogger(NexusSearchTest.class);
36 private NexusSearch searcher;
37
38 @Before
39 public void setUp() throws Exception {
40 String nexusUrl = Settings.getString(Settings.KEYS.ANALYZER_NEXUS_URL);
41 LOGGER.debug(nexusUrl);
42 searcher = new NexusSearch(new URL(nexusUrl));
43 Assume.assumeTrue(searcher.preflightRequest());
44 }
45
46 @Test(expected = IllegalArgumentException.class)
47 @Ignore
48 public void testNullSha1() throws Exception {
49 searcher.searchSha1(null);
50 }
51
52 @Test(expected = IllegalArgumentException.class)
53 @Ignore
54 public void testMalformedSha1() throws Exception {
55 searcher.searchSha1("invalid");
56 }
57
58
59
60
61 @Test
62 @Ignore
63 public void testValidSha1() throws Exception {
64 MavenArtifact ma = searcher.searchSha1("9977a8d04e75609cf01badc4eb6a9c7198c4c5ea");
65 assertEquals("Incorrect group", "org.apache.maven.plugins", ma.getGroupId());
66 assertEquals("Incorrect artifact", "maven-compiler-plugin", ma.getArtifactId());
67 assertEquals("Incorrect version", "3.1", ma.getVersion());
68 assertNotNull("URL Should not be null", ma.getArtifactUrl());
69 }
70
71
72
73
74 @Test(expected = FileNotFoundException.class)
75 @Ignore
76 public void testMissingSha1() throws Exception {
77 searcher.searchSha1("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
78 }
79 }
80
81