1 package org.owasp.dependencycheck.data.central;
2
3 import org.junit.Before;
4 import org.junit.Test;
5 import org.owasp.dependencycheck.BaseTest;
6 import org.owasp.dependencycheck.data.nexus.MavenArtifact;
7 import org.owasp.dependencycheck.utils.Settings;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
10
11 import java.io.FileNotFoundException;
12 import java.net.URL;
13 import java.util.List;
14
15 import static org.junit.Assert.*;
16
17
18
19
20 public class CentralSearchTest extends BaseTest {
21 private static final Logger LOGGER = LoggerFactory.getLogger(CentralSearchTest.class);
22 private CentralSearch searcher;
23
24 @Before
25 public void setUp() throws Exception {
26 String centralUrl = Settings.getString(Settings.KEYS.ANALYZER_CENTRAL_URL);
27 LOGGER.debug(centralUrl);
28 searcher = new CentralSearch(new URL(centralUrl));
29 }
30
31 @Test(expected = IllegalArgumentException.class)
32 public void testNullSha1() throws Exception { searcher.searchSha1(null); }
33
34 @Test(expected = IllegalArgumentException.class)
35 public void testMalformedSha1() throws Exception {
36 searcher.searchSha1("invalid");
37 }
38
39
40
41
42 @Test
43 public void testValidSha1() throws Exception {
44 List<MavenArtifact> ma = searcher.searchSha1("9977a8d04e75609cf01badc4eb6a9c7198c4c5ea");
45 assertEquals("Incorrect group", "org.apache.maven.plugins", ma.get(0).getGroupId());
46 assertEquals("Incorrect artifact", "maven-compiler-plugin", ma.get(0).getArtifactId());
47 assertEquals("Incorrect version", "3.1", ma.get(0).getVersion());
48 }
49
50
51
52
53 @Test(expected = FileNotFoundException.class)
54 public void testMissingSha1() throws Exception {
55 searcher.searchSha1("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
56 }
57
58
59 @Test
60 public void testMultipleReturns() throws Exception {
61 List<MavenArtifact> ma = searcher.searchSha1("94A9CE681A42D0352B3AD22659F67835E560D107");
62 assertTrue(ma.size() > 1);
63 }
64 }