View Javadoc
1   /*
2    * This file is part of dependency-check-core.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   * Copyright (c) 2014 Jeremy Long. All Rights Reserved.
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      // This test does generate network traffic and communicates with a host
60      // you may not be able to reach. Remove the @Ignore annotation if you want to
61      // test it anyway
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      // This test does generate network traffic and communicates with a host
73      // you may not be able to reach. Remove the @Ignore annotation if you want to
74      // test it anyway
75      @Test(expected = FileNotFoundException.class)
76      @Ignore
77      public void testMissingSha1() throws Exception {
78          searcher.searchSha1("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
79      }
80  }
81  
82  // vim: cc=120:sw=4:ts=4:sts=4