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) 2023 Jeremy Long. All Rights Reserved.
17   */
18  package org.owasp.dependencycheck.data.update;
19  
20  import java.time.ZonedDateTime;
21  import java.util.Map;
22  import java.util.Properties;
23  import org.junit.After;
24  import org.junit.AfterClass;
25  import org.junit.Before;
26  import org.junit.BeforeClass;
27  import org.junit.Test;
28  import static org.junit.Assert.*;
29  import org.owasp.dependencycheck.Engine;
30  
31  /**
32   *
33   * @author Jeremy Long
34   */
35  public class NvdApiDataSourceTest {
36  
37      /**
38       * Test of extractUrlData method, of class NvdApiDataSource.
39       */
40      @Test
41      public void testExtractUrlData() {
42          String nvdDataFeedUrl = "https://internal.server/nist/nvdcve-{0}.json.gz";
43          NvdApiDataSource instance = new NvdApiDataSource();
44          String expectedUrl = "https://internal.server/nist/";
45          String expectedPattern = "nvdcve-{0}.json.gz";
46          NvdApiDataSource.UrlData result = instance.extractUrlData(nvdDataFeedUrl);
47  
48          nvdDataFeedUrl = "https://internal.server/nist/";
49          expectedUrl = "https://internal.server/nist/";
50          result = instance.extractUrlData(nvdDataFeedUrl);
51  
52          assertEquals(expectedUrl, result.getUrl());
53          assertNull(result.getPattern());
54          
55          nvdDataFeedUrl = "https://internal.server/nist";
56          expectedUrl = "https://internal.server/nist/";
57          result = instance.extractUrlData(nvdDataFeedUrl);
58  
59          assertEquals(expectedUrl, result.getUrl());
60          assertNull(result.getPattern());
61      }
62  
63  //    /**
64  //     * Test of getRemoteCacheProperties method, of class NvdApiDataSource.
65  //     */
66  //    @Test
67  //    public void testGetRemoteCacheProperties() throws Exception {
68  //        System.out.println("getRemoteCacheProperties");
69  //        String url = "";
70  //        NvdApiDataSource instance = new NvdApiDataSource();
71  //        Properties expResult = null;
72  //        Properties result = instance.getRemoteCacheProperties(url);
73  //        assertEquals(expResult, result);
74  //        // TODO review the generated test code and remove the default call to fail.
75  //        fail("The test case is a prototype.");
76  //    }
77  }