Search in sources :

Example 41 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class SsoAuthenticatorTest method verifyUserInDb.

private void verifyUserInDb(String expectedLogin, String expectedName, @Nullable String expectedEmail, GroupDto... expectedGroups) {
    UserDto userDto = db.users().selectUserByLogin(expectedLogin).get();
    assertThat(userDto.isActive()).isTrue();
    assertThat(userDto.getName()).isEqualTo(expectedName);
    assertThat(userDto.getEmail()).isEqualTo(expectedEmail);
    assertThat(userDto.getExternalIdentity()).isEqualTo(expectedLogin);
    assertThat(userDto.getExternalIdentityProvider()).isEqualTo("sonarqube");
    verityUserGroups(expectedLogin, expectedGroups);
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto)

Example 42 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class SsoAuthenticatorTest method update_user_when_user_in_token_but_refresh_time_is_old.

@Test
public void update_user_when_user_in_token_but_refresh_time_is_old() throws Exception {
    startWithSso();
    UserDto user = insertUser(DEFAULT_USER, group1);
    // Refresh time was updated 6 minutes ago => more than 5 minutes
    setUserInToken(user, NOW - 6 * 60 * 1000L);
    HttpServletRequest request = createRequest(DEFAULT_LOGIN, "new name", "new email", GROUP2);
    underTest.authenticate(request, response);
    // User is updated
    verifyUserInDb(DEFAULT_LOGIN, "new name", "new email", group2);
    verifyTokenIsUpdated(NOW);
    verify(authenticationEvent).loginSuccess(request, DEFAULT_LOGIN, Source.sso());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) Test(org.junit.Test)

Example 43 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class IssueServiceMediumTest method assign.

@Test
public void assign() {
    RuleDto rule = newRule();
    ComponentDto project = newProject();
    ComponentDto file = newFile(project);
    userSessionRule.logIn("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
    IssueDto issue = saveIssue(IssueTesting.newDto(rule, file, project));
    UserDto user = new UserDto().setLogin("perceval").setName("Perceval");
    db.userDao().insert(session, user);
    session.commit();
    index();
    assertThat(getIssueByKey(issue.getKey()).assignee()).isNull();
    service.assign(issue.getKey(), user.getLogin());
    assertThat(getIssueByKey(issue.getKey()).assignee()).isEqualTo("perceval");
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 44 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class SearchActionMediumTest method load_additional_fields.

@Test
public void load_additional_fields() throws Exception {
    db.userDao().insert(session, new UserDto().setLogin("simon").setName("Simon").setEmail("simon@email.com"));
    db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
    ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY").setLanguage("java"));
    ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY").setLanguage("js"));
    setProjectPermission(project, USER);
    IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2").setAuthorLogin("John").setAssignee("simon");
    db.issueDao().insert(session, issue);
    session.commit();
    IssueIndexer r = tester.get(IssueIndexer.class);
    r.indexOnStartup(r.getIndexTypes());
    WsTester.Result result = wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH).setParam("additionalFields", "_all").execute();
    result.assertJson(this.getClass(), "load_additional_fields.json");
}
Also used : WsTester(org.sonar.server.ws.WsTester) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) Test(org.junit.Test)

Example 45 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class SearchActionMediumTest method issue_with_comment_hidden.

@Test
public void issue_with_comment_hidden() throws Exception {
    db.userDao().insert(session, new UserDto().setLogin("john").setName("John").setEmail("john@email.com"));
    db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
    ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
    setDefaultProjectPermission(project);
    ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
    IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2");
    db.issueDao().insert(session, issue);
    tester.get(IssueChangeDao.class).insert(session, new IssueChangeDto().setIssueKey(issue.getKey()).setKey("COMMENT-ABCD").setChangeData("*My comment*").setChangeType(IssueChangeDto.TYPE_COMMENT).setUserLogin("john").setCreatedAt(DateUtils.parseDateTime("2014-09-09T12:00:00+0000").getTime()));
    tester.get(IssueChangeDao.class).insert(session, new IssueChangeDto().setIssueKey(issue.getKey()).setKey("COMMENT-ABCE").setChangeData("Another comment").setChangeType(IssueChangeDto.TYPE_COMMENT).setUserLogin("fabrice").setCreatedAt(DateUtils.parseDateTime("2014-09-10T19:10:03+0000").getTime()));
    session.commit();
    IssueIndexer r = tester.get(IssueIndexer.class);
    r.indexOnStartup(r.getIndexTypes());
    userSessionRule.logIn("john");
    WsTester.Result result = wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH).setParam(PARAM_HIDE_COMMENTS, "true").execute();
    result.assertJson(this.getClass(), "issue_with_comment_hidden.json");
    assertThat(result.outputAsString()).doesNotContain("fabrice");
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) WsTester(org.sonar.server.ws.WsTester) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) IssueChangeDao(org.sonar.db.issue.IssueChangeDao) Test(org.junit.Test)

Aggregations

UserDto (org.sonar.db.user.UserDto)1318 Test (org.junit.Test)1173 ComponentDto (org.sonar.db.component.ComponentDto)332 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)216 GroupDto (org.sonar.db.user.GroupDto)152 IssueDto (org.sonar.db.issue.IssueDto)131 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)108 TestRequest (org.sonar.server.ws.TestRequest)102 NotFoundException (org.sonar.server.exceptions.NotFoundException)84 DbSession (org.sonar.db.DbSession)82 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)80 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)64 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)57 Rule (org.junit.Rule)57 DbTester (org.sonar.db.DbTester)54 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)52 WebService (org.sonar.api.server.ws.WebService)44 BadRequestException (org.sonar.server.exceptions.BadRequestException)43 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)41 UserSessionRule (org.sonar.server.tester.UserSessionRule)41