Search in sources :

Example 56 with DockerRegistry

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

the class ToolGroupApiServiceTest method setUp.

@Before
public void setUp() throws Exception {
    TestUtils.configureDockerClientMock(dockerClient, clientFactory);
    registry = new DockerRegistry();
    registry.setPath(TEST_REPO);
    registry.setOwner(TEST_USER);
    registryDao.createDockerRegistry(registry);
    existingGroup = new ToolGroup();
    existingGroup.setRegistryId(registry.getId());
    existingGroup.setName(TEST_GROUP_NAME);
    existingGroup.setOwner(TEST_USER);
    toolGroupDao.createToolGroup(existingGroup);
    // Create SID for "test" user
    testUserSid = new AclTestDao.AclSid(true, TEST_USER);
    aclTestDao.createAclSid(testUserSid);
    user2Sid = new AclTestDao.AclSid(true, TEST_USER2);
    aclTestDao.createAclSid(user2Sid);
    // And for USER group, which all users are belong to
    userGroupSid = new AclTestDao.AclSid(false, "ROLE_USER");
    aclTestDao.createAclSid(userGroupSid);
    // Mock ACL stuff
    AclTestDao.AclClass groupAclClass = new AclTestDao.AclClass(ToolGroup.class.getCanonicalName());
    aclTestDao.createAclClassIfNotPresent(groupAclClass);
    AclTestDao.AclClass registryAclClass = new AclTestDao.AclClass(DockerRegistry.class.getCanonicalName());
    aclTestDao.createAclClassIfNotPresent(registryAclClass);
    AclTestDao.AclObjectIdentity registryIdentity = new AclTestDao.AclObjectIdentity(testUserSid, registry.getId(), registryAclClass.getId(), null, true);
    aclTestDao.createObjectIdentity(registryIdentity);
    AclTestDao.AclObjectIdentity groupIdentity = new AclTestDao.AclObjectIdentity(testUserSid, existingGroup.getId(), groupAclClass.getId(), registryIdentity, true);
    aclTestDao.createObjectIdentity(groupIdentity);
    // Make group private
    AclTestDao.AclEntry groupAclEntry = new AclTestDao.AclEntry(groupIdentity, 1, userGroupSid, AclPermission.ALL_DENYING_PERMISSIONS.getMask(), false);
    aclTestDao.createAclEntry(groupAclEntry);
    // TEST_USER is allowed to write
    groupAclEntry = new AclTestDao.AclEntry(groupIdentity, 2, testUserSid, AclPermission.WRITE.getMask(), true);
    aclTestDao.createAclEntry(groupAclEntry);
    // All Test users can write to registry
    AclTestDao.AclEntry registryAclEntry = new AclTestDao.AclEntry(registryIdentity, 1, testUserSid, AclPermission.WRITE.getMask(), true);
    aclTestDao.createAclEntry(registryAclEntry);
    registryAclEntry.setSid(user2Sid);
    registryAclEntry.setOrder(2);
    aclTestDao.createAclEntry(registryAclEntry);
    existingTool = ToolApiServiceTest.generateTool();
    existingTool.setToolGroup(existingGroup.getName());
    existingTool.setToolGroupId(existingGroup.getId());
    existingTool.setRegistryId(registry.getId());
    existingTool.setOwner(TEST_USER);
    toolDao.createTool(existingTool);
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) AclTestDao(com.epam.pipeline.dao.util.AclTestDao) Before(org.junit.Before)

Example 57 with DockerRegistry

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

the class DockerRegistryLoaderTest method shouldLoadDockerRegistryTest.

@Test
void shouldLoadDockerRegistryTest() throws EntityNotFoundException {
    DockerRegistry expectedRegistry = new DockerRegistry();
    expectedRegistry.setId(1L);
    expectedRegistry.setDescription(TEST_DESCRIPTION);
    expectedRegistry.setName(TEST_NAME);
    expectedRegistry.setPath(TEST_PATH);
    expectedRegistry.setOwner(TEST_NAME);
    expectedRegistry.setUserName(USER_NAME);
    DockerRegistryLoader dockerRegistryLoader = new DockerRegistryLoader(apiClient);
    when(apiClient.loadDockerRegistry(anyLong())).thenReturn(expectedRegistry);
    Optional<EntityContainer<DockerRegistry>> container = dockerRegistryLoader.loadEntity(1L);
    EntityContainer<DockerRegistry> registryEntityContainer = container.orElseThrow(AssertionError::new);
    DockerRegistry actualRegistry = registryEntityContainer.getEntity();
    assertNotNull(actualRegistry);
    verifyRegistry(expectedRegistry, actualRegistry);
    verifyPipelineUser(registryEntityContainer.getOwner());
    verifyPermissions(PERMISSIONS_CONTAINER_WITH_OWNER, registryEntityContainer.getPermissions());
    verifyMetadata(EXPECTED_METADATA, new ArrayList<>(registryEntityContainer.getMetadata().values()));
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) EntityContainer(com.epam.pipeline.elasticsearchagent.model.EntityContainer) Test(org.junit.jupiter.api.Test)

Aggregations

DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)57 Transactional (org.springframework.transaction.annotation.Transactional)24 ToolGroup (com.epam.pipeline.entity.pipeline.ToolGroup)22 Tool (com.epam.pipeline.entity.pipeline.Tool)19 Test (org.junit.Test)14 Before (org.junit.Before)10 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)7 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)6 MessageHelper (com.epam.pipeline.common.MessageHelper)4 AclClass (com.epam.pipeline.entity.security.acl.AclClass)4 DockerClient (com.epam.pipeline.manager.docker.DockerClient)4 DockerRegistryManager (com.epam.pipeline.manager.docker.DockerRegistryManager)4 IOException (java.io.IOException)4 List (java.util.List)4 Optional (java.util.Optional)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 MessageConstants (com.epam.pipeline.common.MessageConstants)3 PermissionGrantVO (com.epam.pipeline.controller.vo.PermissionGrantVO)3 AbstractSecuredEntity (com.epam.pipeline.entity.AbstractSecuredEntity)3 ToolVersionScanResult (com.epam.pipeline.entity.scan.ToolVersionScanResult)3