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;
}
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());
}
Aggregations