View Javadoc

    1   /*
    2    * This file is part of dependency-check-core.
    3    *
    4    * Dependency-check-core is free software: you can redistribute it and/or modify it
    5    * under the terms of the GNU General Public License as published by the Free
    6    * Software Foundation, either version 3 of the License, or (at your option) any
    7    * later version.
    8    *
    9    * Dependency-check-core is distributed in the hope that it will be useful, but
    10   * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    12   * details.
    13   *
    14   * You should have received a copy of the GNU General Public License along with
    15   * dependency-check-core. If not, see http://www.gnu.org/licenses/.
    16   *
    17   * Copyright (c) 2013 Jeremy Long. All Rights Reserved.
    18   */
    19  package org.owasp.dependencycheck.data.nvdcve;
    20
    21  import java.io.File;
    22  import java.io.IOException;
    23  import java.sql.SQLException;
    24  import java.util.List;
    25  import java.util.Set;
    26  import java.util.logging.Level;
    27  import java.util.logging.Logger;
    28  import org.junit.After;
    29  import org.junit.AfterClass;
    30  import org.junit.Before;
    31  import org.junit.BeforeClass;
    32  import org.junit.Test;
    33  import org.owasp.dependencycheck.dependency.Vulnerability;
    34  import org.owasp.dependencycheck.dependency.VulnerableSoftware;
    35
    36  /**
    37   *
    38   * @author Jeremy Long (jeremy.long@owasp.org)
    39   */
    40  public class CveDBTest extends BaseDBTestCase {
    41
    42      @BeforeClass
    43      public static void setUpClass() {
    44      }
    45
    46      @AfterClass
    47      public static void tearDownClass() {
    48      }
    49
    50      @Before
    51      @Override
    52      public void setUp() throws Exception {
    53          super.setUp();
    54      }
    55
    56      @After
    57      @Override
    58      public void tearDown() throws Exception {
    59          super.tearDown();
    60      }
    61
    62      /**
    63       * Pretty useless tests of open, commit, and close methods, of class CveDB.
    64       */
    65      @Test
    66      public void testOpen() throws Exception {
    67          CveDB instance = new CveDB();
    68          instance.open();
    69          instance.commit();
    70          instance.close();
    71      }
    72
    73      /**
    74       * Test of getCPEs method, of class CveDB.
    75       */
    76      @Test
    77      public void testGetCPEs() throws Exception {
    78          CveDB instance = new CveDB();
    79          try {
    80              String vendor = "apache";
    81              String product = "struts";
    82              instance.open();
    83              Set<VulnerableSoftware> result = instance.getCPEs(vendor, product);
    84              assertTrue(result.size() > 5);
    85          } finally {
    86              instance.close();
    87          }
    88      }
    89
    90      /**
    91       * Test of getVulnerabilities method, of class CveDB.
    92       */
    93      @Test
    94      public void testGetVulnerabilities() throws Exception {
    95          String cpeStr = "cpe:/a:apache:struts:2.1.2";
    96          CveDB instance = new CveDB();
    97          try {
    98              instance.open();
    99              List result = instance.getVulnerabilities(cpeStr);
    100             assertTrue(result.size() > 5);
    101         } finally {
    102             instance.close();
    103         }
    104     }
    105 }