Search in sources :

Example 51 with ToolGroup

use of com.epam.pipeline.entity.pipeline.ToolGroup 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 52 with ToolGroup

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

the class ToolGroupApiServiceTest method testCreateToolInOwnGroupOk.

@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
@WithMockUser(username = TEST_USER2, roles = TOOL_GROUP_MANAGER_ROLE)
@Test
public void testCreateToolInOwnGroupOk() {
    ToolGroup privateGroup = toolGroupApiService.createPrivate(registry.getId());
    Tool tool = ToolApiServiceTest.generateTool();
    tool.setImage(privateGroup.getName() + "/" + tool.getImage());
    tool.setToolGroupId(privateGroup.getId());
    tool.setToolGroup(privateGroup.getName());
    toolApiService.create(tool);
    ToolGroup loadedPrivateGroup = toolGroupApiService.loadPrivate(registry.getId());
    Assert.assertEquals(privateGroup.getId(), loadedPrivateGroup.getId());
    Assert.assertEquals(privateGroup.getName(), loadedPrivateGroup.getName());
    Assert.assertEquals(privateGroup.getRegistryId(), loadedPrivateGroup.getRegistryId());
    Assert.assertFalse(loadedPrivateGroup.getTools().isEmpty());
    Assert.assertTrue(loadedPrivateGroup.getTools().stream().anyMatch(t -> t.getImage().equals(tool.getImage())));
    Assert.assertTrue(loadedPrivateGroup.isPrivateGroup());
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) TestApplicationWithAclSecurity(com.epam.pipeline.app.TestApplicationWithAclSecurity) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) AclTestDao(com.epam.pipeline.dao.util.AclTestDao) Mock(org.mockito.Mock) Autowired(org.springframework.beans.factory.annotation.Autowired) Propagation(org.springframework.transaction.annotation.Propagation) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) AclPermission(com.epam.pipeline.security.acl.AclPermission) TestUtils(com.epam.pipeline.util.TestUtils) Before(org.junit.Before) MockBean(org.springframework.boot.test.mock.mockito.MockBean) ToolDao(com.epam.pipeline.dao.tool.ToolDao) Test(org.junit.Test) AccessDeniedException(org.springframework.security.access.AccessDeniedException) DockerRegistryDao(com.epam.pipeline.dao.docker.DockerRegistryDao) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) Tool(com.epam.pipeline.entity.pipeline.Tool) List(java.util.List) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ContextConfiguration(org.springframework.test.context.ContextConfiguration) DockerClientFactory(com.epam.pipeline.manager.docker.DockerClientFactory) Assert(org.junit.Assert) ToolGroupDao(com.epam.pipeline.dao.tool.ToolGroupDao) DockerClient(com.epam.pipeline.manager.docker.DockerClient) Transactional(org.springframework.transaction.annotation.Transactional) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Tool(com.epam.pipeline.entity.pipeline.Tool) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AbstractManagerTest(com.epam.pipeline.manager.AbstractManagerTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 53 with ToolGroup

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

the class ToolGroupLoaderTest method shouldLoadToolGroupTest.

@Test
void shouldLoadToolGroupTest() throws EntityNotFoundException {
    ToolGroup expectedToolGroup = new ToolGroup();
    expectedToolGroup.setId(1L);
    expectedToolGroup.setName(TEST_NAME);
    expectedToolGroup.setRegistryId(1L);
    expectedToolGroup.setOwner(TEST_NAME);
    expectedToolGroup.setDescription(TEST_DESCRIPTION);
    ToolGroupLoader toolGroupLoader = new ToolGroupLoader(apiClient);
    when(apiClient.loadToolGroup(anyString())).thenReturn(expectedToolGroup);
    Optional<EntityContainer<ToolGroup>> container = toolGroupLoader.loadEntity(1L);
    EntityContainer<ToolGroup> toolEntityContainer = container.orElseThrow(AssertionError::new);
    ToolGroup actualToolGroup = toolEntityContainer.getEntity();
    assertNotNull(actualToolGroup);
    verifyToolGroup(expectedToolGroup, actualToolGroup);
    verifyPipelineUser(toolEntityContainer.getOwner());
    verifyPermissions(PERMISSIONS_CONTAINER_WITH_OWNER, toolEntityContainer.getPermissions());
    verifyMetadata(EXPECTED_METADATA, new ArrayList<>(toolEntityContainer.getMetadata().values()));
}
Also used : ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) LoaderVerificationUtils.verifyToolGroup(com.epam.pipeline.elasticsearchagent.LoaderVerificationUtils.verifyToolGroup) EntityContainer(com.epam.pipeline.elasticsearchagent.model.EntityContainer) Test(org.junit.jupiter.api.Test)

Aggregations

ToolGroup (com.epam.pipeline.entity.pipeline.ToolGroup)53 Transactional (org.springframework.transaction.annotation.Transactional)27 DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)25 Test (org.junit.Test)20 Tool (com.epam.pipeline.entity.pipeline.Tool)14 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)10 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)10 Before (org.junit.Before)10 AclPermission (com.epam.pipeline.security.acl.AclPermission)6 List (java.util.List)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Propagation (org.springframework.transaction.annotation.Propagation)6 DockerRegistryDao (com.epam.pipeline.dao.docker.DockerRegistryDao)4 AclTestDao (com.epam.pipeline.dao.util.AclTestDao)4 AclClass (com.epam.pipeline.entity.security.acl.AclClass)4 Optional (java.util.Optional)4 Assert (org.junit.Assert)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 PermissionGrantVO (com.epam.pipeline.controller.vo.PermissionGrantVO)3 ToolGroupDao (com.epam.pipeline.dao.tool.ToolGroupDao)3