@Test public void select_by_email() { UserDto activeUser1 = db.users().insertUser(u -> u.setEmail("user1@email.com")); UserDto activeUser2 = db.users().insertUser(u -> u.setEmail("user1@email.com")); UserDto disableUser = db.users().insertUser(u -> u.setActive(false)); assertThat(underTest.selectByEmail(session, "user1@email.com")).hasSize(2); assertThat(underTest.selectByEmail(session, disableUser.getEmail())).isEmpty(); assertThat(underTest.selectByEmail(session, "unknown")).isEmpty(); }
@Test public void overall_dispatchers() { UserDto user = db.users().insertUser(); userSession.logIn(user); when(dispatchers.getGlobalDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_ISSUES, NOTIF_NEW_QUALITY_GATE_STATUS)); ListResponse result = call(); assertThat(result.getGlobalTypesList()).containsExactly(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_ISSUES, NOTIF_NEW_QUALITY_GATE_STATUS); }
@Test public void selectUserByLogin_ignore_inactive() { db.users().insertUser(user -> user.setLogin("user1")); db.users().insertUser(user -> user.setLogin("user2")); db.users().insertUser(user -> user.setLogin("inactive_user").setActive(false)); UserDto user = underTest.selectActiveUserByLogin(session, "inactive_user"); assertThat(user).isNull(); }
@Test public void count_groups_by_logins() { db.users().insertMember(group1, user1); db.users().insertMember(group2, user1); db.users().insertMember(group3, user1); db.users().insertMember(group2, user2); assertThat(underTest.selectGroupsByLogins(db.getSession(), emptyList()).keys()).isEmpty(); Multimap<String, String> groupsByLogin = underTest.selectGroupsByLogins(db.getSession(), asList(user1.getLogin(), user2.getLogin(), user3.getLogin())); assertThat(groupsByLogin.get(user1.getLogin())).containsOnly(group1.getName(), group2.getName(), group3.getName()); assertThat(groupsByLogin.get(user2.getLogin())).containsOnly(group2.getName()); assertThat(groupsByLogin.get(user3.getLogin())).isEmpty(); }
@Test public void fail_when_unknown_project_dispatcher_on_public_project() { UserDto user = db.users().insertUser(); userSession.logIn(user); ComponentDto project = db.components().insertPublicProject(); when(dispatchers.getGlobalDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_ISSUES)); when(dispatchers.getProjectDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_ISSUES)); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Value of parameter 'type' (Dispatcher42) must be one of: [Dispatcher1, Dispatcher2]"); call("Dispatcher42", null, project.getKey(), null); }
@Test public void fail_if_login_is_provided_and_unknown() { UserDto user = db.users().insertUser(); userSession.logIn(user).setSystemAdministrator(); when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); expectedException.expect(NotFoundException.class); expectedException.expectMessage("User 'LOGIN 404' not found"); call(NOTIF_MY_NEW_ISSUES, null, null, "LOGIN 404"); }
@Test public void set_default_assignee() { settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik"); UserDto userDto = db.users().insertUser("erik"); db.organizations().addMember(organizationDto, userDto); assertThat(underTest.loadDefaultAssigneeUuid()).isEqualTo(userDto.getUuid()); }
private UserDto insertUser(String login) { UserDto user = db.users().insertUser(login); db.organizations().addMember(db.getDefaultOrganization(), user); return user; }
@Test public void add_notification_on_private_with_USER_permission() { UserDto user = db.users().insertUser(); userSession.logIn(user); ComponentDto project = db.components().insertPrivateProject(); userSession.addProjectPermission(USER, project); when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); call(NOTIF_MY_NEW_ISSUES, null, project.getDbKey(), null); db.notifications().assertExists(defaultChannel.getKey(), NOTIF_MY_NEW_ISSUES, userSession.getUserId(), project); }
@Test public void apply_has_no_effect_when_adding_CODEVIEWER_permission_to_group_AnyOne_on_a_public_project() { GroupIdOrAnyone groupId = GroupIdOrAnyone.forAnyone(org.getUuid()); apply(new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.CODEVIEWER, new ProjectId(publicProject), groupId, permissionService)); assertThat(db.users().selectAnyonePermissions(org, publicProject)).isEmpty(); }
@Test public void fail_when_component_is_not_a_project() { UserDto user = db.users().insertUser(); userSession.logIn(user); when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES)); db.components().insertViewAndSnapshot(newView(db.organizations().insert()).setDbKey("VIEW_1")); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Component 'VIEW_1' must be a project"); call(request.setProject("VIEW_1")); }
@Test public void add_to_a_specific_channel() { UserDto user = db.users().insertUser(); userSession.logIn(user); when(dispatchers.getGlobalDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_QUALITY_GATE_STATUS)); call(NOTIF_NEW_QUALITY_GATE_STATUS, twitterChannel.getKey(), null, null); db.notifications().assertExists(twitterChannel.getKey(), NOTIF_NEW_QUALITY_GATE_STATUS, userSession.getUserId(), null); }
@Test public void createForUser_gives_all_permissions_for_new_organization_to_current_user() { UserDto user = db.users().insertUser(dto -> dto.setLogin(A_LOGIN).setName(A_NAME)); when(organizationValidation.generateKeyFrom(A_LOGIN)).thenReturn(SLUG_OF_A_LOGIN); enableCreatePersonalOrg(true); builtInQProfileRepositoryRule.initialize(); db.qualityGates().insertBuiltInQualityGate(); underTest.createForUser(dbSession, user); OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, SLUG_OF_A_LOGIN).get(); assertThat(dbClient.userPermissionDao().selectGlobalPermissionsOfUser(dbSession, user.getId(), organization.getUuid())) .containsOnly(GlobalPermissions.ALL.toArray(new String[GlobalPermissions.ALL.size()])); }
@Test public void configured_login_is_disabled() { settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik"); db.users().insertUser(user -> user.setLogin("erik").setActive(false)); assertThat(underTest.loadDefaultAssigneeUuid()).isNull(); }
@Test public void filter_channels() { UserDto user = db.users().insertUser(); userSession.logIn(user); when(dispatchers.getGlobalDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_ISSUES, NOTIF_NEW_QUALITY_GATE_STATUS)); notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, null); notificationUpdater.add(dbSession, "Unknown Channel", NOTIF_MY_NEW_ISSUES, user, null); dbSession.commit(); ListResponse result = call(); assertThat(result.getNotificationsList()).extracting(Notification::getChannel).containsOnly(emailChannel.getKey()); }
@Test public void filter_overall_dispatchers() { UserDto user = db.users().insertUser(); userSession.logIn(user); when(dispatchers.getGlobalDispatchers()).thenReturn(asList(NOTIF_MY_NEW_ISSUES, NOTIF_NEW_ISSUES, NOTIF_NEW_QUALITY_GATE_STATUS)); notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, user, null); notificationUpdater.add(dbSession, emailChannel.getKey(), "Unknown Notification", user, null); dbSession.commit(); ListResponse result = call(); assertThat(result.getNotificationsList()).extracting(Notification::getType).containsOnly(NOTIF_MY_NEW_ISSUES); }
@Test public void delete_comment_using_deprecated_key_parameter() { IssueDto issueDto = issueDbTester.insertIssue(); UserDto user = dbTester.users().insertUser(); IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, user, "please fix it"); loginAndAddProjectPermission(user, issueDto, USER); tester.newRequest().setParam("key", commentDto.getKey()).setParam("text", "please have a look").execute(); verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class)); assertThat(dbClient.issueChangeDao().selectCommentByKey(dbTester.getSession(), commentDto.getKey())).isNotPresent(); verifyContentOfPreloadedSearchResponseData(issueDto); }
@Test public void create_creates_members_group_and_add_current_user_to_it() throws OrganizationUpdater.KeyConflictException { UserDto user = db.users().insertUser(); builtInQProfileRepositoryRule.initialize(); db.qualityGates().insertBuiltInQualityGate(); underTest.create(dbSession, user, FULL_POPULATED_NEW_ORGANIZATION, EMPTY_ORGANIZATION_CONSUMER); verifyMembersGroup(user, FULL_POPULATED_NEW_ORGANIZATION.getKey()); }
@Before public void setUp() throws Exception { org = db.organizations().insert(); group = db.users().insertGroup(org, "a-group"); privateProject = db.components().insertPrivateProject(org); publicProject = db.components().insertPublicProject(org); }
@Test public void fail_to_remove_admin_permission_if_no_more_admins() { GroupIdOrAnyone groupId = GroupIdOrAnyone.from(group); db.users().insertPermissionOnGroup(group, ADMINISTER); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Last group with permission 'admin'. Permission cannot be removed."); underTest.apply(db.getSession(), new GroupPermissionChange(PermissionChange.Operation.REMOVE, ADMINISTER.getKey(), null, groupId, permissionService)); }