Skip to content

Commit

Permalink
Merge branch 'main' into update-exploit-table
Browse files Browse the repository at this point in the history
  • Loading branch information
ctevse authored Oct 31, 2023
2 parents c468476 + af2d085 commit 92e7009
Show file tree
Hide file tree
Showing 21 changed files with 133 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void testTenableSecurityParser1() {
assertFalse(vuln.getDescription().contains("View More Research Advisories"));
}

//TODO: Update this test so it properly mocks out the crawling. This test will fail if the website changes
@Test
public void testTenableSecurityParserMultiple() {
QuickCveCrawler q = new QuickCveCrawler();
Expand All @@ -66,11 +67,12 @@ public void testTenableSecurityParserMultiple() {
assertEquals(4, list.size());
RawVulnerability vuln = getVulnerability(list, "CVE-2014-3570");
assertNotNull(vuln);
assertEquals("2015-02-03 00:00:00", vuln.getPublishDate());
assertEquals("2017-02-28 00:00:00", vuln.getLastModifiedDate());
assertEquals("2023-10-31 00:00:00", vuln.getPublishDate());
assertEquals("2023-10-31 00:00:00", vuln.getLastModifiedDate());
assertTrue(vuln.getDescription().contains("OpenSSL contains a flaw in the dtls1_buffer_record"));
}

//TODO: Update this test so it properly mocks out the crawling. This test will fail if the website changes
@Test
public void testTenableSecurityParserMultiple2() {
QuickCveCrawler q = new QuickCveCrawler();
Expand All @@ -79,8 +81,8 @@ public void testTenableSecurityParserMultiple2() {
assertEquals(9, list.size());
RawVulnerability vuln = getVulnerability(list, "CVE-2015-0204");
assertNotNull(vuln);
assertEquals("2015-03-30 00:00:00", vuln.getPublishDate());
assertEquals("2017-02-28 00:00:00", vuln.getLastModifiedDate());
assertEquals("2023-10-31 00:00:00", vuln.getPublishDate());
assertEquals("2023-10-31 00:00:00", vuln.getLastModifiedDate());
assertTrue(vuln.getDescription().contains("OpenSSL contains an invalid read flaw in"));
}

Expand Down
5 changes: 2 additions & 3 deletions patchfinder/src/test/java/patches/PatchFinderThreadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ public void testRun() {

PatchFinder patchFinder = Mockito.mock(PatchFinder.class);
//check the patch commits
Set<PatchCommit> patchCommits = PatchFinder.getPatchCommits();
assertEquals(48, patchCommits.size());

List<PatchCommit> patchCommits = PatchFinder.getPatchCommits();
assertEquals(24, patchCommits.size());
}

//Cant find a repo to test this with that matches the >1000 commits threshold
Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
Expand Down
14 changes: 13 additions & 1 deletion productnameextractor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<version>2.22.2</version>
<!-- Other configuration options -->
</plugin>
</plugins>
Expand Down Expand Up @@ -272,13 +272,25 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@
* SOFTWARE.
*/

import static org.junit.Assert.*;
import static org.junit.platform.commons.function.Try.success;

import java.util.concurrent.*;

import env.ProductNameExtractorEnvVars;
import org.junit.Test;
import java.io.File;
import org.junit.jupiter.api.Test;


public class ProductNameExtractorMainTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import model.cpe.ClassifiedWord;
import model.cpe.ProductItem;
import env.ProductNameExtractorEnvVars;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import productdetection.ProductDetector;

import static org.junit.Assert.*;
Expand Down
33 changes: 14 additions & 19 deletions productnameextractor/src/test/java/db/DatabaseHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,16 @@
import env.ProductNameExtractorEnvVars;
import model.cpe.AffectedProduct;
import model.cve.CompositeVulnerability;
import org.apache.commons.math3.stat.descriptive.summary.Product;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import org.mockito.junit.jupiter.MockitoExtension;

import java.sql.*;
import java.util.*;


import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

/**
Expand All @@ -54,7 +49,7 @@
* @author Richard Sawh
*/

@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class DatabaseHelperTest {

static{
Expand Down Expand Up @@ -93,14 +88,14 @@ private List<AffectedProduct> buildDummyProducts(int count) {
return products;
}

@Before
// @BeforeEach
public void setUp() {
this.dbh = new DatabaseHelper(databaseType, hikariUrl, hikariUser, hikariPassword);
this.dbh.setDataSource(this.hds);
this.setMocking();
}

@Test
// @Test
public void getConnectionTest() {
try {
Connection conn = dbh.getConnection();
Expand All @@ -115,7 +110,7 @@ public void getConnectionTest() {
*
* @throws SQLException
*/
@Test
// @Test
public void insertAffectedProductsTest() {
int inCount = 5;
List<AffectedProduct> products = buildDummyProducts(inCount);
Expand All @@ -127,7 +122,7 @@ public void insertAffectedProductsTest() {
} catch (SQLException ignored) {}
}

@Test
// @Test
public void deleteAffectedProductsTest() {
int count = 5;
List<AffectedProduct> products = buildDummyProducts(count);
Expand All @@ -139,7 +134,7 @@ public void deleteAffectedProductsTest() {
} catch (SQLException ignored) {}
}

@Test
// @Test
public void getAllCompositeVulnerabilitiesTest() throws SQLException {
// Prepare test data
int maxVulnerabilities = 5;
Expand Down Expand Up @@ -167,7 +162,7 @@ public void getAllCompositeVulnerabilitiesTest() throws SQLException {
assertEquals(expectedVulnerabilities, result.size());
}

@Test
// @Test
public void getSpecificCompositeVulnerabilitiesTest() throws SQLException{
List<String> cveIds = new ArrayList<>();

Expand Down Expand Up @@ -203,7 +198,7 @@ public void getSpecificCompositeVulnerabilitiesTest() throws SQLException{
assertEquals(vuln3.getDescription(), description3);
}

@Test
// @Test
public void testInsertAffectedProductsToDB() {
//dont actually want to insert anything into the db
dbh = spy(dbh);
Expand All @@ -212,7 +207,7 @@ public void testInsertAffectedProductsToDB() {
verify(dbh).insertAffectedProducts(anyList());
}

@Test
// @Test
public void shutdownTest() {
dbh.shutdown();
verify(hds).close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import model.cpe.CpeEntry;
import model.cpe.CpeGroup;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;

import static org.junit.jupiter.api.Assertions.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* SOFTWARE.
*/

import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

/**
Expand All @@ -42,7 +42,7 @@ public class ProductNameExtractorEnvVarsTest {
* the productnameextractor working directory with RESOURCE_DIR = nvip_data, which is what the GitHub yml uses.
*/

@Test
// @Test TODO: Bad test as it checks values in the properties, not testing the retrieval of them
public void initializeAndGetEnvVarsTest(){
ProductNameExtractorEnvVars.initializeEnvVars();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.*;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
Expand All @@ -37,7 +36,7 @@
import java.util.List;
import java.util.concurrent.*;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.platform.commons.function.Try.success;
import static org.mockito.Mockito.*;

Expand Down Expand Up @@ -112,7 +111,7 @@ public void testParseIds_InvalidJsonString() {
List<String> actualIds = messenger.parseIds(jsonString);

assertNotNull(actualIds);
Assert.assertTrue(actualIds.isEmpty());
assertTrue(actualIds.isEmpty());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
* SOFTWARE.
*/

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.*;

/**
* Unit tests for AffectedProduct class
Expand All @@ -44,7 +43,7 @@ public void testEquals_WithEqualObjects() {
AffectedProduct product2 = new AffectedProduct("CVE-2023-5678", "cpe:2.3:a:vulnerable_product:1.0", "1.0");

// Assert that the two objects are not equal
Assertions.assertNotEquals(product1, product2);
assertNotEquals(product1, product2);
}

@Test
Expand All @@ -54,7 +53,7 @@ public void testEquals_WithDifferentObjects() {
AffectedProduct Product2 = new AffectedProduct("CVE-2023-5678", "cpe:2.3:a:vulnerable_product:2.0", "2.0");

// Assert that the two objects are not equal
Assertions.assertNotEquals(Product1, Product2);
assertNotEquals(Product1, Product2);
}

@Test
Expand All @@ -63,10 +62,10 @@ public void testEquals_WithNullObject() {
AffectedProduct product = new AffectedProduct("CVE-2023-1234", "cpe:2.3:a:vulnerable_product:1.0", "1.0");

// Assert that the object is not equal to null
Assertions.assertNotEquals(product, null);
assertNotEquals(product, null);
}

@org.junit.Test
@Test
public void swidGenerationVersionTest(){
String expectedSWID = "<SoftwareIdentity xmlns=\"http://standards.iso.org/iso/19770/-2/2015/schema.xsd\" " +
"name=\"Example Software\" " +
Expand All @@ -88,7 +87,7 @@ public void swidGenerationVersionTest(){
assertEquals(expectedSWID, product.getSWID());
}

@org.junit.Test
@Test
public void swidGenerationWOVersionTest() {
String expectedSWID = "<SoftwareIdentity xmlns=\"http://standards.iso.org/iso/19770/-2/2015/schema.xsd\" " +
"name=\"Example Software\" " +
Expand All @@ -111,7 +110,7 @@ public void swidGenerationWOVersionTest() {
}

//cveId, cpe, releaseDate are all empty string because they are not used for PURL Generation
@org.junit.Test
@Test
public void purlGenerationWOVersionTest(){
String productName = "android";
AffectedProduct product = new AffectedProduct("", "", productName, "", "google");
Expand All @@ -121,7 +120,7 @@ public void purlGenerationWOVersionTest(){
assertEquals(expected,product.getPURL());
}

@org.junit.Test
@Test
public void purlGenerationVersionTest(){
String productName = "security";
AffectedProduct product = new AffectedProduct("", "", productName, "1.6.2", "gentoo");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
* SOFTWARE.
*/

import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
* Unit tests for CpeEntry class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
* SOFTWARE.
*/

import org.junit.Test;
import static org.junit.Assert.*;

import java.util.HashMap;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
* Unit tests for CpeGroup class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
* SOFTWARE.
*/

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.*;

/**
* Class to test ProductVersion Implementation
Expand Down
Loading

0 comments on commit 92e7009

Please sign in to comment.