Search in sources :

Example 51 with UserDto

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

the class OrganizationCreationImplTest method createForUser_creates_guarded_organization_with_key_name_and_description_generated_from_user_login_and_name_and_associated_to_user.

@Test
public void createForUser_creates_guarded_organization_with_key_name_and_description_generated_from_user_login_and_name_and_associated_to_user() {
    UserDto user = dbTester.users().insertUser(A_LOGIN);
    when(organizationValidation.generateKeyFrom(A_LOGIN)).thenReturn(SLUG_OF_A_LOGIN);
    mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
    enableCreatePersonalOrg(true);
    underTest.createForUser(dbSession, user);
    OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, SLUG_OF_A_LOGIN).get();
    assertThat(organization.getUuid()).isEqualTo(SOME_UUID);
    assertThat(organization.getKey()).isEqualTo(SLUG_OF_A_LOGIN);
    assertThat(organization.getName()).isEqualTo(user.getName());
    assertThat(organization.getDescription()).isEqualTo(user.getName() + "'s personal organization");
    assertThat(organization.getUrl()).isNull();
    assertThat(organization.getAvatarUrl()).isNull();
    assertThat(organization.isGuarded()).isTrue();
    assertThat(organization.getUserId()).isEqualTo(user.getId());
    assertThat(organization.getCreatedAt()).isEqualTo(SOME_DATE);
    assertThat(organization.getUpdatedAt()).isEqualTo(SOME_DATE);
}
Also used : UserDto(org.sonar.db.user.UserDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 52 with UserDto

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

the class CreateActionTest method request_creates_default_template_for_owner_group_and_anyone.

@Test
public void request_creates_default_template_for_owner_group_and_anyone() {
    mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
    UserDto user = dbTester.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    executeRequest("orgFoo");
    OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, "orgfoo").get();
    GroupDto ownersGroup = dbClient.groupDao().selectByName(dbSession, organization.getUuid(), "Owners").get();
    PermissionTemplateDto defaultTemplate = dbClient.permissionTemplateDao().selectByName(dbSession, organization.getUuid(), "default template");
    assertThat(defaultTemplate.getName()).isEqualTo("Default template");
    assertThat(defaultTemplate.getDescription()).isEqualTo("Default permission template of organization orgFoo");
    DefaultTemplates defaultTemplates = dbClient.organizationDao().getDefaultTemplates(dbSession, organization.getUuid()).get();
    assertThat(defaultTemplates.getProjectUuid()).isEqualTo(defaultTemplate.getUuid());
    assertThat(defaultTemplates.getViewUuid()).isNull();
    assertThat(dbClient.permissionTemplateDao().selectGroupPermissionsByTemplateId(dbSession, defaultTemplate.getId())).extracting(PermissionTemplateGroupDto::getGroupId, PermissionTemplateGroupDto::getPermission).containsOnly(tuple(ownersGroup.getId(), UserRole.ADMIN), tuple(ownersGroup.getId(), UserRole.ISSUE_ADMIN), tuple(ownersGroup.getId(), GlobalPermissions.SCAN_EXECUTION), tuple(0, UserRole.USER), tuple(0, UserRole.CODEVIEWER));
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) UserDto(org.sonar.db.user.UserDto) PermissionTemplateGroupDto(org.sonar.db.permission.template.PermissionTemplateGroupDto) GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) DefaultTemplates(org.sonar.db.organization.DefaultTemplates) Test(org.junit.Test)

Example 53 with UserDto

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

the class SearchMyOrganizationsActionTest method verify_response_example.

@Test
public void verify_response_example() {
    OrganizationDto organization1 = dbTester.organizations().insertForKey("my-org");
    OrganizationDto organization2 = dbTester.organizations().insertForKey("foo-corp");
    UserDto user = dbTester.users().insertUser();
    dbTester.users().insertPermissionOnUser(organization1, user, SYSTEM_ADMIN);
    dbTester.users().insertPermissionOnUser(organization2, user, SYSTEM_ADMIN);
    userSessionRule.logIn(user);
    TestResponse response = underTest.newRequest().execute();
    assertJson(response.getInput()).isSimilarTo(underTest.getDef().responseExampleAsString());
}
Also used : TestResponse(org.sonar.server.ws.TestResponse) UserDto(org.sonar.db.user.UserDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 54 with UserDto

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

the class EnableSupportActionTest method enabling_support_saves_internal_property_and_flags_caller_as_root.

@Test
public void enabling_support_saves_internal_property_and_flags_caller_as_root() {
    UserDto user = db.users().insertUser();
    UserDto otherUser = db.users().insertUser();
    verifyFeatureEnabled(false);
    verifyRoot(user, false);
    verifyRoot(otherUser, false);
    logInAsSystemAdministrator(user.getLogin());
    call();
    verifyFeatureEnabled(true);
    verifyRoot(user, true);
    verifyRoot(otherUser, false);
}
Also used : UserDto(org.sonar.db.user.UserDto) Test(org.junit.Test)

Example 55 with UserDto

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

the class PermissionIndexerTest method initializeOnStartup_does_not_grant_access_to_anybody.

@Test
public void initializeOnStartup_does_not_grant_access_to_anybody() {
    ComponentDto project = createAndIndexProject();
    UserDto user = userDbTester.insertUser();
    GroupDto group = userDbTester.insertGroup();
    indexOnStartup();
    verifyAnyoneNotAuthorized(project);
    verifyNotAuthorized(project, user);
    verifyNotAuthorized(project, user, group);
}
Also used : UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) GroupDto(org.sonar.db.user.GroupDto) 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