use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.
the class UserDaoTest method testUserCRUDWithAttributes.
@Test
public void testUserCRUDWithAttributes() {
Map<String, String> attributes = new HashMap<>();
attributes.put(ATTRIBUTES_KEY, ATTRIBUTES_VALUE);
PipelineUser user = new PipelineUser();
user.setUserName(TEST_USER1);
user.setAttributes(attributes);
PipelineUser savedUser = userDao.createUser(user, Arrays.asList(DefaultRoles.ROLE_ADMIN.getId(), DefaultRoles.ROLE_USER.getId()));
Assert.assertNotNull(savedUser);
Assert.assertNotNull(savedUser.getId());
Assert.assertNotNull(savedUser.getAttributes());
Collection<PipelineUser> users = userDao.loadAllUsers();
Assert.assertFalse(users.isEmpty());
Assert.assertTrue(users.stream().anyMatch(u -> u.getId().equals(savedUser.getId()) && assertUserAttributes(attributes, u.getAttributes())));
PipelineUser userById = userDao.loadUserById(savedUser.getId());
Assert.assertEquals(savedUser.getId(), userById.getId());
Assert.assertTrue(assertUserAttributes(attributes, userById.getAttributes()));
PipelineUser userByName = userDao.loadUserByName(TEST_USER1.toUpperCase());
Assert.assertEquals(savedUser.getId(), userByName.getId());
Assert.assertTrue(assertUserAttributes(attributes, userByName.getAttributes()));
savedUser.setUserName(TEST_USER2);
userDao.updateUser(savedUser);
PipelineUser userByChangedName = userDao.loadUserByName(TEST_USER2);
Assert.assertEquals(savedUser.getId(), userByChangedName.getId());
Assert.assertTrue(assertUserAttributes(attributes, userByChangedName.getAttributes()));
userDao.deleteUserRoles(savedUser.getId());
userDao.deleteUser(savedUser.getId());
Assert.assertNull(userDao.loadUserById(savedUser.getId()));
Collection<PipelineUser> usersAfterDeletion = userDao.loadAllUsers();
Assert.assertTrue(usersAfterDeletion.stream().noneMatch(u -> u.getId().equals(savedUser.getId())));
}
use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.
the class UserDaoTest method testUserCRUD.
@Test
public void testUserCRUD() {
PipelineUser user = new PipelineUser();
user.setUserName(TEST_USER1);
PipelineUser savedUser = userDao.createUser(user, Arrays.asList(DefaultRoles.ROLE_ADMIN.getId(), DefaultRoles.ROLE_USER.getId()));
Assert.assertNotNull(savedUser);
Assert.assertNotNull(savedUser.getId());
Collection<PipelineUser> users = userDao.loadAllUsers();
Assert.assertFalse(users.isEmpty());
Assert.assertTrue(users.stream().anyMatch(u -> u.getId().equals(savedUser.getId())));
PipelineUser userById = userDao.loadUserById(savedUser.getId());
Assert.assertEquals(savedUser.getId(), userById.getId());
PipelineUser userByName = userDao.loadUserByName(TEST_USER1.toUpperCase());
Assert.assertEquals(savedUser.getId(), userByName.getId());
savedUser.setUserName(TEST_USER2);
userDao.updateUser(savedUser);
PipelineUser userByChangedName = userDao.loadUserByName(TEST_USER2);
Assert.assertEquals(savedUser.getId(), userByChangedName.getId());
List<PipelineUser> loadedUsers = userDao.loadUsersByNames(Collections.singletonList(TEST_USER2));
Assert.assertFalse(loadedUsers.isEmpty());
userDao.updateUserRoles(savedUser, Collections.singletonList(DefaultRoles.ROLE_USER.getId()));
PipelineUser userUpdatedRoles = userDao.loadUserByName(TEST_USER2);
Assert.assertEquals(1, userUpdatedRoles.getRoles().size());
Assert.assertEquals(DefaultRoles.ROLE_USER.name(), userUpdatedRoles.getRoles().get(0).getName());
userDao.deleteUserRoles(savedUser.getId());
userDao.deleteUser(savedUser.getId());
Assert.assertNull(userDao.loadUserById(savedUser.getId()));
Collection<PipelineUser> usersAfterDeletion = userDao.loadAllUsers();
Assert.assertTrue(usersAfterDeletion.stream().noneMatch(u -> u.getId().equals(savedUser.getId())));
}
use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.
the class ToolSecurityPolicyAspect method checkToolBySecurityPolicy.
@Before("@annotation(com.epam.pipeline.manager.docker.scan.ToolSecurityPolicyCheck) && args(runVO,..)")
public void checkToolBySecurityPolicy(JoinPoint joinPoint, PipelineStart runVO) {
if (runVO.isForce()) {
PipelineUser user = authManager.getCurrentUser();
if (user != null && user.isAdmin()) {
return;
}
}
PipelineConfiguration configuration = configurationManager.getPipelineConfiguration(runVO);
String tag = toolManager.getTagFromImageName(configuration.getDockerImage());
Tool tool = toolManager.loadByNameOrId(configuration.getDockerImage());
if (!clairToolScanManager.checkTool(tool, tag)) {
throw new ToolExecutionDeniedException(messageHelper.getMessage(MessageConstants.ERROR_TOOL_SECURITY_POLICY_VIOLATION));
}
}
use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.
the class NotificationManagerTest method setUp.
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
admin = new PipelineUser("admin");
userDao.createUser(admin, Collections.singletonList(DefaultRoles.ROLE_ADMIN.getId()));
testOwner = new PipelineUser("testOwner");
userDao.createUser(testOwner, Collections.emptyList());
testUser1 = new PipelineUser("TestUser1");
userDao.createUser(testUser1, Collections.emptyList());
testUser2 = new PipelineUser("TestUser2");
userDao.createUser(testUser2, Collections.emptyList());
longRunningTemplate = createTemplate(1L, "testTemplate");
longRunningSettings = createSettings(NotificationType.LONG_RUNNING, longRunningTemplate.getId(), 1L, 1L);
issueTemplate = createTemplate(3L, "issueTemplate");
issueSettings = createSettings(NotificationType.NEW_ISSUE, issueTemplate.getId(), -1L, -1L);
issueCommentTemplate = createTemplate(4L, "issueCommentTemplate");
issueCommentSettings = createSettings(NotificationType.NEW_ISSUE_COMMENT, issueCommentTemplate.getId(), -1L, -1L);
createTemplate(NotificationType.IDLE_RUN.getId(), "idle-run-template");
createSettings(NotificationType.IDLE_RUN, NotificationType.IDLE_RUN.getId(), -1, -1);
longRunnging = new PipelineRun();
DateTime date = DateTime.now(DateTimeZone.UTC).minus(Duration.standardMinutes(6));
longRunnging.setStartDate(date.toDate());
longRunnging.setStatus(TaskStatus.RUNNING);
longRunnging.setOwner(admin.getUserName());
longRunnging.setPodId("longRunning");
when(pipelineRunManager.loadRunningAndTerminatedPipelineRuns()).thenReturn(Collections.singletonList(longRunnging));
when(pipelineRunManager.loadPipelineRun(org.mockito.Matchers.any())).thenReturn(longRunnging);
when(kubernetesManager.getKubernetesClient()).thenReturn(mockClient);
ExtendedRole noAdmins = new ExtendedRole();
noAdmins.setUsers(Collections.emptyList());
Pod mockPod = mock(Pod.class);
PodStatus podStatus = new PodStatus(null, null, "hostIp", "", "", "podIp", "bla-bla", "5 o'clock");
podMetadata = new ObjectMeta();
podMetadata.setLabels(Collections.emptyMap());
when(mockPod.getStatus()).thenReturn(podStatus);
when(mockPod.getMetadata()).thenReturn(podMetadata);
MixedOperation<Pod, PodList, DoneablePod, PodResource<Pod, DoneablePod>> mockPods = new KubernetesTestUtils.MockPods().mockNamespace(Matchers.any(String.class)).mockWithName(Matchers.any(String.class)).mockPod(mockPod).and().getMockedEntity();
when(mockClient.pods()).thenReturn(mockPods);
}
use of com.epam.pipeline.entity.user.PipelineUser in project cloud-pipeline by epam.
the class SMTPNotificationManagerTest method testEmailSending.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testEmailSending() {
PipelineUser user = new PipelineUser();
user.setUserName(USER_NAME);
user.setAdmin(true);
user.setAttributes(Collections.singletonMap(EMAIL_KEY, EMAIL));
userRepository.save(user);
NotificationMessage message = new NotificationMessage();
NotificationTemplate template = new NotificationTemplate();
template.setSubject(MESSAGE_SUBJECT);
template.setBody(MESSAGE_BODY);
message.setTemplate(template);
message.setTemplateParameters(Collections.emptyMap());
message.setToUserId(user.getId());
message.setCopyUserIds(Collections.singletonList(user.getId()));
smtpNotificationManager.notifySubscribers(message);
MimeMessage[] receivedMessages = greenMail.getReceivedMessages();
assertTrue(receivedMessages.length == 2);
assertTrue(GreenMailUtil.getBody(receivedMessages[0]).contains(MESSAGE_BODY));
}
Aggregations