use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.
the class DockerRegistryDaoTest method testLoadAllRegistriesContent.
@Test
@Ignore
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testLoadAllRegistriesContent() {
List<DockerRegistry> created = initTestHierarchy();
Set<Long> createdRegistryIds = created.stream().map(BaseEntity::getId).collect(Collectors.toSet());
List<DockerRegistry> dockerRegistries = registryDao.loadAllRegistriesContent();
Assert.assertFalse(dockerRegistries.isEmpty());
for (int i = 0; i < dockerRegistries.size(); i++) {
DockerRegistry loadedRegistry = dockerRegistries.get(i);
if (createdRegistryIds.contains(loadedRegistry.getId())) {
Assert.assertFalse(loadedRegistry.getGroups().isEmpty());
Assert.assertEquals(loadedRegistry.getGroups().get(0).getName(), created.get(i).getGroups().get(0).getName());
Assert.assertEquals(loadedRegistry.getGroups().get(0).getDescription(), created.get(i).getGroups().get(0).getDescription());
for (int j = 0; j < created.get(i).getGroups().get(0).getTools().size(); j++) {
Tool tool = created.get(i).getGroups().get(0).getTools().get(j);
Tool loadedTool = loadedRegistry.getGroups().get(0).getTools().get(j);
Assert.assertEquals(tool.getId(), loadedTool.getId());
Assert.assertEquals(tool.getImage(), loadedTool.getImage());
Assert.assertEquals(tool.getCpu(), loadedTool.getCpu());
}
}
}
}
use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.
the class DockerRegistryDaoTest method createTool.
private static Tool createTool(String image, long registryId, ToolGroup group) {
Tool tool = new Tool();
tool.setImage(image);
tool.setCpu(CPU);
tool.setRam(RAM);
tool.setRegistryId(registryId);
tool.setOwner(TEST_USER);
tool.setToolGroupId(group.getId());
return tool;
}
use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.
the class ToolContextualPreferenceHandlerTest method isValidShouldReturnTrueIfToolExists.
@Test
public void isValidShouldReturnTrueIfToolExists() {
final ContextualPreference preference = new ContextualPreference(NAME, VALUE, resource);
when(toolDao.loadTool(eq(Long.valueOf(RESOURCE_ID)))).thenReturn(new Tool());
assertTrue(handler().isValid(preference));
}
use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.
the class DockerRegistryManagerTest method generateTool.
private Tool generateTool(ToolGroup group) {
Tool tool = new Tool();
tool.setImage(TEST_IMAGE);
tool.setRegistry(ANOTHER_PATH);
tool.setRam(TEST_RAM);
tool.setCpu(TEST_CPU);
tool.setOwner(TEST_USER);
tool.setToolGroupId(group.getId());
return tool;
}
use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.
the class AggregatingToolScanManagerTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
Whitebox.setInternalState(aggregatingToolScanManager, "preferenceManager", preferenceManager);
when(preferenceManager.getPreference(SystemPreferences.DOCKER_SECURITY_TOOL_POLICY_DENY_NOT_SCANNED)).thenReturn(DENY_NOT_SCANNED);
when(preferenceManager.getPreference(SystemPreferences.DOCKER_SECURITY_TOOL_POLICY_MAX_CRITICAL_VULNERABILITIES)).thenReturn(MAX_CRITICAL_VULNERABILITIES);
when(preferenceManager.getPreference(SystemPreferences.DOCKER_SECURITY_TOOL_POLICY_MAX_HIGH_VULNERABILITIES)).thenReturn(MAX_HIGH_VULNERABILITIES);
when(preferenceManager.getPreference(SystemPreferences.DOCKER_SECURITY_TOOL_POLICY_MAX_MEDIUM_VULNERABILITIES)).thenReturn(MAX_MEDIUM_VULNERABILITIES);
when(preferenceManager.getPreference(SystemPreferences.DOCKER_SECURITY_TOOL_GRACE_HOURS)).thenReturn(0);
// Dummy line, to shut up PMD
Assert.assertNotNull(pipelineConfigurationManager);
testUser.setAdmin(false);
DockerRegistry testRegistry = new DockerRegistry();
testTool = new Tool();
testTool.setId(1L);
testTool.setImage(TEST_IMAGE);
ManifestV2 testManifest = new ManifestV2();
testManifest.setLayers(Arrays.asList(new ManifestV2.Config(DIGEST_1, null), new ManifestV2.Config(DIGEST_2, null), new ManifestV2.Config(DIGEST_3, null)));
toolScanResult.setLastLayerRef(DIGEST_1);
toolScanResult.setScanDate(DateUtils.now());
toolScanResult.setVulnerabilities(Collections.emptyList());
ToolVersion attributes = new ToolVersion();
attributes.setVersion(LATEST_VERSION);
attributes.setDigest(DIGEST_3);
ToolVersion actualAttr = new ToolVersion();
actualAttr.setVersion(ACTUAL_SCANNED_VERSION);
actualAttr.setDigest(DIGEST_3);
actual.setLastLayerRef(aggregatingToolScanManager.getLayerName(TEST_IMAGE, ACTUAL_SCANNED_VERSION));
actual.setScanDate(DateUtils.now());
actual.setSuccessScanDate(DateUtils.now());
actual.setDigest(DIGEST_3);
ClairScanResult testScanResult = new ClairScanResult();
feature = new ClairScanResult.ClairFeature();
feature.setName("test");
feature.setVersion("test1");
clairVulnerability = new ClairScanResult.ClairVulnerability();
clairVulnerability.setSeverity(VulnerabilitySeverity.Critical);
clairVulnerability.setName(TEST_VULNERABILITY_NAME);
clairVulnerability.setDescription(TEST_VULNERABILITY_DESCRIPTION);
feature.setVulnerabilities(Collections.singletonList(clairVulnerability));
testScanResult.setFeatures(Collections.singletonList(feature));
DockerComponentScanResult dockerComponentScanResult = new DockerComponentScanResult();
DockerComponentLayerScanResult layerScanResult = new DockerComponentLayerScanResult();
testDependency = new ToolDependency(1, "latest", "test", "1.0", ToolDependency.Ecosystem.R_PKG, "R Package");
layerScanResult.setDependencies(Collections.singletonList(testDependency));
dockerComponentScanResult.setLayers(Collections.singletonList(layerScanResult));
when(dataStorageApiService.getDataStorages()).thenReturn(Collections.emptyList());
when(versionManager.getValidDockerImage(TEST_IMAGE)).thenReturn(TEST_IMAGE);
when(authManager.getCurrentUser()).thenReturn(testUser);
when(dockerRegistryManager.load(testTool.getRegistryId())).thenReturn(testRegistry);
when(dockerClientFactory.getDockerClient(eq(testRegistry), anyString())).thenReturn(mockDockerClient);
when(mockDockerClient.getManifest(any(), Mockito.anyString(), Mockito.anyString())).thenReturn(Optional.of(testManifest));
when(mockDockerClient.getVersionAttributes(any(), eq(TEST_IMAGE), eq(LATEST_VERSION))).thenReturn(attributes);
when(mockDockerClient.getVersionAttributes(any(), eq(TEST_IMAGE), eq(ACTUAL_SCANNED_VERSION))).thenReturn(actualAttr);
when(clairService.scanLayer(any(ClairScanRequest.class))).then((Answer<MockCall<ClairScanRequest>>) invocation -> new MockCall<>((ClairScanRequest) invocation.getArguments()[0]));
when(clairService.getScanResult(Mockito.anyString())).thenReturn(new MockCall<>(testScanResult));
when(compScanService.scanLayer(any(DockerComponentScanRequest.class))).then((Answer<MockCall<DockerComponentScanRequest>>) invocation -> new MockCall<>((DockerComponentScanRequest) invocation.getArguments()[0]));
when(compScanService.getScanResult(Mockito.anyString())).thenReturn(new MockCall<>(dockerComponentScanResult));
when(messageHelper.getMessage(Mockito.anyString(), Mockito.any())).thenReturn("testMessage");
when(messageHelper.getMessage(any(), any())).thenReturn("testMessage");
when(toolManager.loadByNameOrId(TEST_IMAGE)).thenReturn(testTool);
when(toolManager.loadToolVersionScan(testTool.getId(), LATEST_VERSION)).thenReturn(Optional.of(toolScanResult));
when(toolManager.loadToolVersionScan(testTool.getId(), ACTUAL_SCANNED_VERSION)).thenReturn(Optional.of(actual));
ToolVersion actual = new ToolVersion();
actual.setDigest(DIGEST_3);
when(toolVersionManager.loadToolVersion(testTool.getId(), ACTUAL_SCANNED_VERSION)).thenReturn(actual);
ToolVersion old = new ToolVersion();
old.setDigest(DIGEST_2);
when(toolVersionManager.loadToolVersion(testTool.getId(), LATEST_VERSION)).thenReturn(old);
when(toolManager.getTagFromImageName(Mockito.anyString())).thenReturn(LATEST_VERSION);
}
Aggregations