use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class DeactivateActionTest method fail_to_deactivate_last_administrator_of_organization.
@Test
public void fail_to_deactivate_last_administrator_of_organization() throws Exception {
// user1 is the unique administrator of org1 and org2.
// user1 and user2 are both administrators of org3
UserDto user1 = createUser();
OrganizationDto org1 = db.organizations().insert(newOrganizationDto().setKey("org1"));
OrganizationDto org2 = db.organizations().insert(newOrganizationDto().setKey("org2"));
OrganizationDto org3 = db.organizations().insert(newOrganizationDto().setKey("org3"));
db.users().insertPermissionOnUser(org1, user1, SYSTEM_ADMIN);
db.users().insertPermissionOnUser(org2, user1, SYSTEM_ADMIN);
db.users().insertPermissionOnUser(org3, user1, SYSTEM_ADMIN);
UserDto user2 = createUser();
db.users().insertPermissionOnUser(org3, user2, SYSTEM_ADMIN);
logInAsSystemAdministrator();
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("User is last administrator of organizations [org1, org2], and cannot be deactivated");
deactivate(user1.getLogin());
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class CoveredFilesActionTest method fail_when_test_uuid_is_unknown.
@Test
public void fail_when_test_uuid_is_unknown() {
userSessionRule.addComponentUuidPermission(UserRole.CODEVIEWER, "SonarQube", "test-file-uuid");
when(testIndex.getNullableByTestUuid(anyString())).thenReturn(Optional.<TestDoc>absent());
when(testIndex.coveredFiles("test-uuid")).thenReturn(Arrays.asList(new CoveredFileDoc().setFileUuid(FILE_1_ID).setCoveredLines(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), new CoveredFileDoc().setFileUuid(FILE_2_ID).setCoveredLines(Arrays.asList(1, 2, 3))));
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
when(dbClient.componentDao().selectByUuids(any(DbSession.class), anyList())).thenReturn(Arrays.asList(newFileDto(newProjectDto(organizationDto), null, FILE_1_ID).setKey("org.foo.Bar.java").setLongName("src/main/java/org/foo/Bar.java"), newFileDto(newProjectDto(organizationDto), null, FILE_2_ID).setKey("org.foo.File.java").setLongName("src/main/java/org/foo/File.java")));
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Test with id 'test-uuid' is not found");
ws.newRequest().setParam(TEST_ID, "test-uuid").execute();
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class ServerUserSessionTest method hasPermission_on_organization_keeps_cache_of_permissions_of_logged_in_user.
@Test
public void hasPermission_on_organization_keeps_cache_of_permissions_of_logged_in_user() {
OrganizationDto org = db.organizations().insert();
db.users().insertPermissionOnUser(org, userDto, PROVISIONING);
UserSession session = newUserSession(userDto);
// feed the cache
assertThat(session.hasPermission(PROVISION_PROJECTS, org.getUuid())).isTrue();
// change permissions without updating the cache
db.users().deletePermissionFromUser(org, userDto, PROVISION_PROJECTS);
db.users().insertPermissionOnUser(org, userDto, SCAN);
assertThat(session.hasPermission(PROVISION_PROJECTS, org.getUuid())).isTrue();
assertThat(session.hasPermission(ADMINISTER, org.getUuid())).isFalse();
assertThat(session.hasPermission(SCAN, org.getUuid())).isFalse();
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class ServerUserSessionTest method test_hasPermission_on_organization_for_logged_in_user.
@Test
public void test_hasPermission_on_organization_for_logged_in_user() {
OrganizationDto org = db.organizations().insert();
ComponentDto project = db.components().insertProject(org);
db.users().insertPermissionOnUser(org, userDto, PROVISION_PROJECTS);
db.users().insertProjectPermissionOnUser(userDto, UserRole.ADMIN, project);
UserSession session = newUserSession(userDto);
assertThat(session.hasPermission(PROVISION_PROJECTS, org.getUuid())).isTrue();
assertThat(session.hasPermission(ADMINISTER, org.getUuid())).isFalse();
assertThat(session.hasPermission(PROVISION_PROJECTS, "another-org")).isFalse();
}
use of org.sonar.db.organization.OrganizationDto in project sonarqube by SonarSource.
the class ServerUserSessionTest method checkPermission_throws_ForbiddenException_when_user_doesnt_have_the_specified_permission_on_organization.
@Test
public void checkPermission_throws_ForbiddenException_when_user_doesnt_have_the_specified_permission_on_organization() {
OrganizationDto org = db.organizations().insert();
db.users().insertUser(NON_ROOT_USER_DTO);
expectInsufficientPrivilegesForbiddenException();
newUserSession(NON_ROOT_USER_DTO).checkPermission(PROVISION_PROJECTS, org);
}
Aggregations