Search in sources :

Example 6 with Vulnerability

use of com.epam.pipeline.entity.scan.Vulnerability in project cloud-pipeline by epam.

the class ToolVulnerabilityDaoTest method testLoadVulnerabilitiesByVersion.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testLoadVulnerabilitiesByVersion() {
    Vulnerability prevVulnerability = createVulnerability(tool, PREV, "test1", "feature-1", PREV);
    Vulnerability latestVulnerability = createVulnerability(tool, LATEST_VERSION, "test2", "feature-2", LATEST_VERSION);
    List<Vulnerability> vulnerabilities = toolVulnerabilityDao.loadVulnerabilities(tool.getId(), PREV);
    Assert.assertTrue(vulnerabilities.size() == 1);
    Vulnerability loaded = vulnerabilities.get(0);
    TestUtils.checkEquals(prevVulnerability, loaded, objectMapper);
    vulnerabilities = toolVulnerabilityDao.loadVulnerabilities(tool.getId(), LATEST_VERSION);
    Assert.assertTrue(vulnerabilities.size() == 1);
    loaded = vulnerabilities.get(0);
    TestUtils.checkEquals(latestVulnerability, loaded, objectMapper);
}
Also used : Vulnerability(com.epam.pipeline.entity.scan.Vulnerability) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with Vulnerability

use of com.epam.pipeline.entity.scan.Vulnerability in project cloud-pipeline by epam.

the class TestUtils method generateScanResult.

public static void generateScanResult(int criticalVulnerabilitiesCount, int highVulnerabilitiesCount, int mediumVulnerabilitiesCount, ToolVersionScanResult versionScanResult) {
    List<Vulnerability> testVulnerabilities = IntStream.range(0, criticalVulnerabilitiesCount).mapToObj(i -> createVulnerability(VulnerabilitySeverity.Critical)).collect(Collectors.toList());
    testVulnerabilities.addAll(IntStream.range(0, highVulnerabilitiesCount).mapToObj(i -> createVulnerability(VulnerabilitySeverity.High)).collect(Collectors.toList()));
    testVulnerabilities.addAll(IntStream.range(0, mediumVulnerabilitiesCount).mapToObj(i -> createVulnerability(VulnerabilitySeverity.Medium)).collect(Collectors.toList()));
    versionScanResult.setVulnerabilities(testVulnerabilities);
    versionScanResult.setScanDate(new Date());
    versionScanResult.setSuccessScanDate(new Date());
    versionScanResult.setStatus(ToolScanStatus.COMPLETED);
}
Also used : IntStream(java.util.stream.IntStream) Date(java.util.Date) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ManifestV2(com.epam.pipeline.entity.docker.ManifestV2) Vulnerability(com.epam.pipeline.entity.scan.Vulnerability) Collectors(java.util.stream.Collectors) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) List(java.util.List) ToolVersionScanResult(com.epam.pipeline.entity.scan.ToolVersionScanResult) Map(java.util.Map) Optional(java.util.Optional) VulnerabilitySeverity(com.epam.pipeline.entity.scan.VulnerabilitySeverity) DockerClientFactory(com.epam.pipeline.manager.docker.DockerClientFactory) Assert(org.junit.Assert) Collections(java.util.Collections) DockerClient(com.epam.pipeline.manager.docker.DockerClient) ToolVersion(com.epam.pipeline.entity.docker.ToolVersion) ToolScanStatus(com.epam.pipeline.entity.pipeline.ToolScanStatus) Vulnerability(com.epam.pipeline.entity.scan.Vulnerability) Date(java.util.Date)

Aggregations

Vulnerability (com.epam.pipeline.entity.scan.Vulnerability)7 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)2 ManifestV2 (com.epam.pipeline.entity.docker.ManifestV2)2 ToolScanStatus (com.epam.pipeline.entity.pipeline.ToolScanStatus)2 ToolVersionScanResult (com.epam.pipeline.entity.scan.ToolVersionScanResult)2 VulnerabilitySeverity (com.epam.pipeline.entity.scan.VulnerabilitySeverity)2 DockerClient (com.epam.pipeline.manager.docker.DockerClient)2 DockerClientFactory (com.epam.pipeline.manager.docker.DockerClientFactory)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 Transactional (org.springframework.transaction.annotation.Transactional)2 MessageConstants (com.epam.pipeline.common.MessageConstants)1 MessageHelper (com.epam.pipeline.common.MessageHelper)1 ToolVersion (com.epam.pipeline.entity.docker.ToolVersion)1 DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)1 Tool (com.epam.pipeline.entity.pipeline.Tool)1