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