Search in sources :

Example 1 with ToolScanResult

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

the class ToolManager method loadToolScanResult.

/**
 * Loads {@link ToolScanResult} for the specified tool
 * that contains information about scan result for each tool version
 * @param tool for which {@link ToolScanResult} will be loaded
 * @return a {@link ToolScanResult}
 */
public ToolScanResult loadToolScanResult(Tool tool) {
    ToolScanResult result = new ToolScanResult();
    result.setToolId(tool.getId());
    Map<String, ToolVersionScanResult> versionScanResults = toolVulnerabilityDao.loadAllToolVersionScans(tool.getId());
    for (String tag : loadTags(tool.getId())) {
        ToolVersionScanResult versionScan = getToolVersionScanResult(tool, versionScanResults, tag);
        result.getToolVersionScanResults().put(tag, versionScan);
    }
    return result;
}
Also used : ToolScanResult(com.epam.pipeline.entity.scan.ToolScanResult) ToolVersionScanResult(com.epam.pipeline.entity.scan.ToolVersionScanResult)

Example 2 with ToolScanResult

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

the class ToolManagerTest method testLoadToolScanResult.

@Test()
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testLoadToolScanResult() {
    String latestVersion = "latest", testRef = "testRef", prevVersion = "prev";
    Date scanDate = new Date();
    Mockito.doReturn(Arrays.asList(latestVersion, prevVersion)).when(dockerClient).getImageTags(any(), anyString());
    Tool tool = generateTool(TEST_GROUP_ID1);
    tool.setToolGroupId(firstToolGroup.getId());
    toolManager.create(tool, true);
    toolManager.updateToolVersionScanStatus(tool.getId(), ToolScanStatus.COMPLETED, scanDate, latestVersion, testRef, testRef);
    ToolScanResult loaded = toolManager.loadToolScanResult(tool);
    Assert.assertEquals(ToolScanStatus.COMPLETED, loaded.getToolVersionScanResults().get(latestVersion).getStatus());
    Assert.assertEquals(scanDate, loaded.getToolVersionScanResults().get(latestVersion).getSuccessScanDate());
    Assert.assertEquals(scanDate, loaded.getToolVersionScanResults().get(latestVersion).getScanDate());
    Optional<String> loadedRef = toolManager.loadToolVersionScan(tool.getId(), latestVersion).map(ToolVersionScanResult::getLastLayerRef);
    Assert.assertTrue(loadedRef.isPresent());
    Assert.assertEquals(testRef, loadedRef.get());
    Optional<String> loadedDigest = toolManager.loadToolVersionScan(tool.getId(), latestVersion).map(ToolVersionScanResult::getDigest);
    Assert.assertTrue(loadedDigest.isPresent());
    Assert.assertEquals(testRef, loadedDigest.get());
    // check that we will get empty ToolVersionScanResult for not scanned version
    Assert.assertEquals(ToolScanStatus.NOT_SCANNED, loaded.getToolVersionScanResults().get(prevVersion).getStatus());
    Assert.assertEquals(null, loaded.getToolVersionScanResults().get(prevVersion).getSuccessScanDate());
}
Also used : ToolScanResult(com.epam.pipeline.entity.scan.ToolScanResult) ToolVersionScanResult(com.epam.pipeline.entity.scan.ToolVersionScanResult) Matchers.anyString(org.mockito.Matchers.anyString) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ToolScanResult (com.epam.pipeline.entity.scan.ToolScanResult)2 ToolVersionScanResult (com.epam.pipeline.entity.scan.ToolVersionScanResult)2 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Transactional (org.springframework.transaction.annotation.Transactional)1