aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-04-19 15:22:24 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-04-27 14:25:54 +0200
commitcf5bf7ff58c380a7b6bb9e8036f90b1244f3532f (patch)
tree846b35640ecf1507a1da958ae57da3d9ee9e4791 /server
parente21722bdc3de86eaf47dfb96809eb567118e4c96 (diff)
downloadsonarqube-cf5bf7ff58c380a7b6bb9e8036f90b1244f3532f.tar.gz
sonarqube-cf5bf7ff58c380a7b6bb9e8036f90b1244f3532f.zip
SONAR-9140 enforce permission consistency for private component in UTs
ie. in UserDbTester
Diffstat (limited to 'server')
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java28
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java219
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDbTester.java1
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualitygate/QgateProjectFinderTest.java18
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java17
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java2
11 files changed, 234 insertions, 67 deletions
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
index 832cb34720a..27d1436e522 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
@@ -469,11 +469,11 @@ public class AuthorizationDaoTest {
}
@Test
- public void selectProjectPermissionsOfAnonymous_returns_permissions_of_anonymous_user_on_specified_project() {
- ComponentDto project = db.components().insertPrivateProject(org);
+ public void selectProjectPermissionsOfAnonymous_returns_permissions_of_anonymous_user_on_specified_public_project() {
+ ComponentDto project = db.components().insertPublicProject(org);
db.users().insertProjectPermissionOnAnyone(UserRole.CODEVIEWER, project);
db.users().insertProjectPermissionOnUser(db.users().insertUser(), UserRole.USER, project);
- ComponentDto otherProject = db.components().insertPrivateProject();
+ ComponentDto otherProject = db.components().insertPublicProject();
db.users().insertProjectPermissionOnAnyone(UserRole.ISSUE_ADMIN, otherProject);
assertThat(underTest.selectProjectPermissionsOfAnonymous(dbSession, project.uuid())).containsOnly(UserRole.CODEVIEWER);
@@ -481,23 +481,17 @@ public class AuthorizationDaoTest {
@Test
public void selectProjectPermissionsOfAnonymous_returns_empty_set_when_project_does_not_exist() {
- ComponentDto project = db.components().insertPrivateProject(org);
- db.users().insertProjectPermissionOnAnyone(UserRole.CODEVIEWER, project);
-
assertThat(underTest.selectProjectPermissionsOfAnonymous(dbSession, "does_not_exist")).isEmpty();
}
@Test
public void selectProjectPermissions_returns_empty_set_when_logged_in_user_and_project_does_not_exist() {
- ComponentDto project = db.components().insertPrivateProject(org);
- db.users().insertProjectPermissionOnAnyone(UserRole.CODEVIEWER, project);
-
assertThat(underTest.selectProjectPermissions(dbSession, "does_not_exist", user.getId())).isEmpty();
}
@Test
- public void selectProjectPermissions_returns_permissions_of_logged_in_user_on_specified_project_through_anonymous_permissions() {
- ComponentDto project = db.components().insertPrivateProject(org);
+ public void selectProjectPermissions_returns_permissions_of_logged_in_user_on_specified_public_project_through_anonymous_permissions() {
+ ComponentDto project = db.components().insertPublicProject(org);
db.users().insertProjectPermissionOnAnyone(UserRole.CODEVIEWER, project);
db.users().insertProjectPermissionOnAnyone(UserRole.ISSUE_ADMIN, project);
@@ -524,9 +518,19 @@ public class AuthorizationDaoTest {
}
@Test
- public void selectProjectPermissions_returns_permissions_of_logged_in_user_on_specified_project_through_all_possible_configurations() {
+ public void selectProjectPermissions_returns_permissions_of_logged_in_user_on_specified_private_project_through_all_possible_configurations() {
ComponentDto project = db.components().insertPrivateProject(org);
db.users().insertProjectPermissionOnUser(user, UserRole.CODEVIEWER, project);
+ db.users().insertProjectPermissionOnGroup(group1, UserRole.USER, project);
+ db.users().insertMember(group1, user);
+
+ assertThat(underTest.selectProjectPermissions(dbSession, project.uuid(), user.getId())).containsOnly(UserRole.CODEVIEWER, UserRole.USER);
+ }
+
+ @Test
+ public void selectProjectPermissions_returns_permissions_of_logged_in_user_on_specified_public_project_through_all_possible_configurations() {
+ ComponentDto project = db.components().insertPublicProject(org);
+ db.users().insertProjectPermissionOnUser(user, UserRole.CODEVIEWER, project);
db.users().insertProjectPermissionOnAnyone(UserRole.ISSUE_ADMIN, project);
db.users().insertProjectPermissionOnGroup(group1, UserRole.USER, project);
db.users().insertMember(group1, user);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
index ebf1282582c..4248603a803 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
@@ -68,7 +68,7 @@ public class GroupPermissionDaoTest {
}
@Test
- public void group_count_by_permission_and_component_id() {
+ public void group_count_by_permission_and_component_id_on_private_projects() {
GroupDto group1 = db.users().insertGroup();
GroupDto group2 = db.users().insertGroup();
GroupDto group3 = db.users().insertGroup();
@@ -80,6 +80,32 @@ public class GroupPermissionDaoTest {
db.users().insertProjectPermissionOnGroup(group1, ADMIN, project2);
db.users().insertProjectPermissionOnGroup(group2, ADMIN, project2);
db.users().insertProjectPermissionOnGroup(group3, ADMIN, project2);
+ db.users().insertProjectPermissionOnGroup(group1, USER, project2);
+ db.users().insertProjectPermissionOnGroup(group1, USER, project3);
+
+ final List<CountPerProjectPermission> result = new ArrayList<>();
+ underTest.groupsCountByComponentIdAndPermission(dbSession, asList(project2.getId(), project3.getId(), 789L),
+ context -> result.add((CountPerProjectPermission) context.getResultObject()));
+
+ assertThat(result).hasSize(3);
+ assertThat(result).extracting("permission").containsOnly(ADMIN, USER);
+ assertThat(result).extracting("componentId").containsOnly(project2.getId(), project3.getId());
+ assertThat(result).extracting("count").containsOnly(3, 1);
+ }
+
+ @Test
+ public void group_count_by_permission_and_component_id_on_public_projects() {
+ GroupDto group1 = db.users().insertGroup();
+ GroupDto group2 = db.users().insertGroup();
+ GroupDto group3 = db.users().insertGroup();
+ ComponentDto project1 = db.components().insertPublicProject();
+ ComponentDto project2 = db.components().insertPublicProject();
+ ComponentDto project3 = db.components().insertPublicProject();
+
+ db.users().insertProjectPermissionOnGroup(group1, ISSUE_ADMIN, project1);
+ db.users().insertProjectPermissionOnGroup(group1, ADMIN, project2);
+ db.users().insertProjectPermissionOnGroup(group2, ADMIN, project2);
+ db.users().insertProjectPermissionOnGroup(group3, ADMIN, project2);
// anyone group
db.users().insertProjectPermissionOnAnyone(ADMIN, project2);
db.users().insertProjectPermissionOnGroup(group1, USER, project2);
@@ -154,13 +180,13 @@ public class GroupPermissionDaoTest {
}
@Test
- public void select_groups_by_query_with_project_permissions() {
+ public void select_groups_by_query_with_project_permissions_on_public_projects() {
GroupDto group1 = db.users().insertGroup();
GroupDto group2 = db.users().insertGroup();
GroupDto group3 = db.users().insertGroup();
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto anotherProject = db.components().insertPrivateProject();
+ ComponentDto project = db.components().insertPublicProject();
+ ComponentDto anotherProject = db.components().insertPublicProject();
db.users().insertProjectPermissionOnGroup(group1, SCAN_EXECUTION, project);
db.users().insertProjectPermissionOnGroup(group1, PROVISIONING, project);
@@ -181,6 +207,31 @@ public class GroupPermissionDaoTest {
}
@Test
+ public void select_groups_by_query_with_project_permissions_on_private_projects() {
+ GroupDto group1 = db.users().insertGroup();
+ GroupDto group2 = db.users().insertGroup();
+ GroupDto group3 = db.users().insertGroup();
+
+ ComponentDto project = db.components().insertPrivateProject();
+ ComponentDto anotherProject = db.components().insertPrivateProject();
+
+ db.users().insertProjectPermissionOnGroup(group1, SCAN_EXECUTION, project);
+ db.users().insertProjectPermissionOnGroup(group1, PROVISIONING, project);
+
+ db.users().insertProjectPermissionOnGroup(group1, SYSTEM_ADMIN, anotherProject);
+ db.users().insertProjectPermissionOnGroup(group3, SCAN_EXECUTION, anotherProject);
+ db.users().insertPermissionOnGroup(group2, SCAN);
+
+ PermissionQuery.Builder builderOnComponent = newQuery().setComponentUuid(project.uuid());
+ assertThat(underTest.selectGroupNamesByQuery(dbSession,
+ builderOnComponent.withAtLeastOnePermission().build())).containsOnlyOnce(group1.getName());
+ assertThat(underTest.selectGroupNamesByQuery(dbSession,
+ builderOnComponent.setPermission(SCAN_EXECUTION).build())).containsOnlyOnce(group1.getName());
+ assertThat(underTest.selectGroupNamesByQuery(dbSession,
+ builderOnComponent.setPermission(USER).build())).isEmpty();
+ }
+
+ @Test
public void selectGroupNamesByQuery_is_paginated() {
IntStream.rangeClosed(0, 9).forEach(i -> db.users().insertGroup(db.getDefaultOrganization(), i + "-name"));
@@ -249,13 +300,13 @@ public class GroupPermissionDaoTest {
}
@Test
- public void selectByGroupIds_on_projects() {
+ public void selectByGroupIds_on_public_projects() {
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org, "Group-1");
db.users().insertPermissionOnGroup(group1, PROVISION_PROJECTS);
GroupDto group2 = db.users().insertGroup(org, "Group-2");
- ComponentDto project = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(org));
+ ComponentDto project = db.components().insertPublicProject(org);
db.users().insertProjectPermissionOnGroup(group2, USER, project);
GroupDto group3 = db.users().insertGroup(org, "Group-3");
@@ -286,12 +337,47 @@ public class GroupPermissionDaoTest {
}
@Test
+ public void selectByGroupIds_on_private_projects() {
+ OrganizationDto org = db.organizations().insert();
+ GroupDto group1 = db.users().insertGroup(org, "Group-1");
+ db.users().insertPermissionOnGroup(group1, PROVISION_PROJECTS);
+
+ GroupDto group2 = db.users().insertGroup(org, "Group-2");
+ ComponentDto project = db.components().insertPrivateProject(org);
+ db.users().insertProjectPermissionOnGroup(group2, USER, project);
+
+ GroupDto group3 = db.users().insertGroup(org, "Group-3");
+ db.users().insertProjectPermissionOnGroup(group3, USER, project);
+
+ // Anyone group
+ db.users().insertPermissionOnAnyone(org, SCAN);
+
+ assertThat(underTest.selectByGroupIds(dbSession, defaultOrganizationUuid, singletonList(group1.getId()), project.getId())).isEmpty();
+
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group2.getId()), project.getId()))
+ .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
+ .containsOnly(tuple(group2.getId(), USER, project.getId()));
+
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group3.getId()), project.getId()))
+ .extracting(GroupPermissionDto::getGroupId, GroupPermissionDto::getRole, GroupPermissionDto::getResourceId)
+ .containsOnly(tuple(group3.getId(), USER, project.getId()));
+
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(ANYONE_ID), project.getId()))
+ .isEmpty();
+
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), asList(group1.getId(), group2.getId(), ANYONE_ID), project.getId())).hasSize(1);
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(MISSING_ID), project.getId())).isEmpty();
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), singletonList(group1.getId()), 123L)).isEmpty();
+ assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), Collections.emptyList(), project.getId())).isEmpty();
+ }
+
+ @Test
public void selectGlobalPermissionsOfGroup() {
OrganizationDto org1 = db.organizations().insert();
OrganizationDto org2 = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org1, "group1");
GroupDto group2 = db.users().insertGroup(org2, "group2");
- ComponentDto project = db.components().insertPrivateProject(org1);
+ ComponentDto project = db.components().insertPublicProject(org1);
db.users().insertPermissionOnAnyone(org1, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
@@ -310,11 +396,11 @@ public class GroupPermissionDaoTest {
}
@Test
- public void selectProjectPermissionsOfGroup() {
+ public void selectProjectPermissionsOfGroup_on_public_project() {
OrganizationDto org1 = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org1, "group1");
- ComponentDto project1 = db.components().insertPrivateProject(org1);
- ComponentDto project2 = db.components().insertPrivateProject(org1);
+ ComponentDto project1 = db.components().insertPublicProject(org1);
+ ComponentDto project2 = db.components().insertPublicProject(org1);
db.users().insertPermissionOnAnyone(org1, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
@@ -334,11 +420,34 @@ public class GroupPermissionDaoTest {
}
@Test
- public void selectAllPermissionsByGroupId() throws Exception {
+ public void selectProjectPermissionsOfGroup_on_private_project() {
OrganizationDto org1 = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org1, "group1");
ComponentDto project1 = db.components().insertPrivateProject(org1);
ComponentDto project2 = db.components().insertPrivateProject(org1);
+
+ db.users().insertPermissionOnAnyone(org1, "perm1");
+ db.users().insertPermissionOnGroup(group1, "perm2");
+ db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
+ db.users().insertProjectPermissionOnGroup(group1, "perm4", project1);
+ db.users().insertProjectPermissionOnGroup(group1, "perm5", project2);
+
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project1.getId()))
+ .containsOnly("perm3", "perm4");
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), group1.getId(), project2.getId()))
+ .containsOnly("perm5");
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), null, project1.getId()))
+ .isEmpty();
+ assertThat(underTest.selectProjectPermissionsOfGroup(dbSession, org1.getUuid(), null, project2.getId()))
+ .isEmpty();
+ }
+
+ @Test
+ public void selectAllPermissionsByGroupId_on_public_project() throws Exception {
+ OrganizationDto org1 = db.organizations().insert();
+ GroupDto group1 = db.users().insertGroup(org1, "group1");
+ ComponentDto project1 = db.components().insertPublicProject(org1);
+ ComponentDto project2 = db.components().insertPublicProject(org1);
db.users().insertPermissionOnAnyone(org1, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
@@ -354,7 +463,26 @@ public class GroupPermissionDaoTest {
}
@Test
- public void deleteByRootComponentId() {
+ public void selectAllPermissionsByGroupId_on_private_project() throws Exception {
+ OrganizationDto org1 = db.organizations().insert();
+ GroupDto group1 = db.users().insertGroup(org1, "group1");
+ ComponentDto project1 = db.components().insertPrivateProject(org1);
+ ComponentDto project2 = db.components().insertPrivateProject(org1);
+ db.users().insertPermissionOnAnyone(org1, "perm1");
+ db.users().insertPermissionOnGroup(group1, "perm2");
+ db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
+ db.users().insertProjectPermissionOnGroup(group1, "perm4", project1);
+ db.users().insertProjectPermissionOnGroup(group1, "perm5", project2);
+
+ List<GroupPermissionDto> result = new ArrayList<>();
+ underTest.selectAllPermissionsByGroupId(dbSession, org1.getUuid(), group1.getId(), context -> result.add((GroupPermissionDto) context.getResultObject()));
+ assertThat(result).extracting(GroupPermissionDto::getResourceId, GroupPermissionDto::getRole).containsOnly(
+ tuple(null, "perm2"),
+ tuple(project1.getId(), "perm3"), tuple(project1.getId(), "perm4"), tuple(project2.getId(), "perm5"));
+ }
+
+ @Test
+ public void deleteByRootComponentId_on_private_project() {
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org);
GroupDto group2 = db.users().insertGroup(org);
@@ -362,8 +490,7 @@ public class GroupPermissionDaoTest {
ComponentDto project2 = db.components().insertPrivateProject(org);
db.users().insertPermissionOnGroup(group1, "perm1");
db.users().insertProjectPermissionOnGroup(group1, "perm2", project1);
- db.users().insertProjectPermissionOnAnyone("perm3", project1);
- db.users().insertProjectPermissionOnGroup(group2, "perm4", project2);
+ db.users().insertProjectPermissionOnGroup(group2, "perm3", project2);
underTest.deleteByRootComponentId(dbSession, project1.getId());
dbSession.commit();
@@ -373,10 +500,30 @@ public class GroupPermissionDaoTest {
}
@Test
- public void delete_global_permission_from_group() {
+ public void deleteByRootComponentId_on_public_project() {
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org);
- ComponentDto project1 = db.components().insertPrivateProject(org);
+ GroupDto group2 = db.users().insertGroup(org);
+ ComponentDto project1 = db.components().insertPublicProject(org);
+ ComponentDto project2 = db.components().insertPublicProject(org);
+ db.users().insertPermissionOnGroup(group1, "perm1");
+ db.users().insertProjectPermissionOnGroup(group1, "perm2", project1);
+ db.users().insertProjectPermissionOnGroup(group2, "perm3", project2);
+ db.users().insertProjectPermissionOnAnyone("perm4", project1);
+ db.users().insertProjectPermissionOnAnyone("perm5", project2);
+
+ underTest.deleteByRootComponentId(dbSession, project1.getId());
+ dbSession.commit();
+
+ assertThat(db.countSql("select count(id) from group_roles where resource_id=" + project1.getId())).isEqualTo(0);
+ assertThat(db.countRowsOfTable("group_roles")).isEqualTo(3);
+ }
+
+ @Test
+ public void delete_global_permission_from_group_on_public_project() {
+ OrganizationDto org = db.organizations().insert();
+ GroupDto group1 = db.users().insertGroup(org);
+ ComponentDto project1 = db.components().insertPublicProject(org);
db.users().insertPermissionOnAnyone(org, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
@@ -390,13 +537,29 @@ public class GroupPermissionDaoTest {
}
@Test
- public void delete_global_permission_from_anyone() {
+ public void delete_global_permission_from_group_on_private_project() {
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org);
ComponentDto project1 = db.components().insertPrivateProject(org);
db.users().insertPermissionOnAnyone(org, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
+
+ underTest.delete(dbSession, "perm2", group1.getOrganizationUuid(), group1.getId(), null);
+ dbSession.commit();
+
+ assertThatNoPermission("perm2");
+ assertThat(db.countRowsOfTable("group_roles")).isEqualTo(2);
+ }
+
+ @Test
+ public void delete_global_permission_from_anyone_on_public_project() {
+ OrganizationDto org = db.organizations().insert();
+ GroupDto group1 = db.users().insertGroup(org);
+ ComponentDto project1 = db.components().insertPublicProject(org);
+ db.users().insertPermissionOnAnyone(org, "perm1");
+ db.users().insertPermissionOnGroup(group1, "perm2");
+ db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
db.users().insertProjectPermissionOnAnyone("perm4", project1);
underTest.delete(dbSession, "perm1", group1.getOrganizationUuid(), null, null);
@@ -407,13 +570,29 @@ public class GroupPermissionDaoTest {
}
@Test
- public void delete_project_permission_from_group() {
+ public void delete_project_permission_from_group_on_private_project() {
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org);
ComponentDto project1 = db.components().insertPrivateProject(org);
db.users().insertPermissionOnAnyone(org, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
+
+ underTest.delete(dbSession, "perm3", group1.getOrganizationUuid(), group1.getId(), project1.getId());
+ dbSession.commit();
+
+ assertThatNoPermission("perm3");
+ assertThat(db.countRowsOfTable("group_roles")).isEqualTo(2);
+ }
+
+ @Test
+ public void delete_project_permission_from_group_on_public_project() {
+ OrganizationDto org = db.organizations().insert();
+ GroupDto group1 = db.users().insertGroup(org);
+ ComponentDto project1 = db.components().insertPublicProject(org);
+ db.users().insertPermissionOnAnyone(org, "perm1");
+ db.users().insertPermissionOnGroup(group1, "perm2");
+ db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
db.users().insertProjectPermissionOnAnyone("perm4", project1);
underTest.delete(dbSession, "perm3", group1.getOrganizationUuid(), group1.getId(), project1.getId());
@@ -424,10 +603,10 @@ public class GroupPermissionDaoTest {
}
@Test
- public void delete_project_permission_from_anybody() {
+ public void delete_project_permission_from_anybody_on_private_project() {
OrganizationDto org = db.organizations().insert();
GroupDto group1 = db.users().insertGroup(org);
- ComponentDto project1 = db.components().insertPrivateProject(org);
+ ComponentDto project1 = db.components().insertPublicProject(org);
db.users().insertPermissionOnAnyone(org, "perm1");
db.users().insertPermissionOnGroup(group1, "perm2");
db.users().insertProjectPermissionOnGroup(group1, "perm3", project1);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDbTester.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDbTester.java
index 3fa01eec830..31d3741c31a 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDbTester.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDbTester.java
@@ -213,6 +213,7 @@ public class UserDbTester {
}
public GroupPermissionDto insertProjectPermissionOnAnyone(String permission, ComponentDto project) {
+ checkArgument(!project.isPrivate(), "No permission to group AnyOne can be granted on a private project");
GroupPermissionDto dto = new GroupPermissionDto()
.setOrganizationUuid(project.getOrganizationUuid())
.setGroupId(null)
diff --git a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java
index d1a471340bc..54f0928d22c 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java
@@ -255,8 +255,8 @@ public class DeleteActionTest {
GroupDto otherGroup1 = db.users().insertGroup(otherOrg);
GroupDto otherGroup2 = db.users().insertGroup(otherOrg);
- ComponentDto projectDto = db.components().insertPrivateProject(org);
- ComponentDto otherProjectDto = db.components().insertPrivateProject(otherOrg);
+ ComponentDto projectDto = db.components().insertPublicProject(org);
+ ComponentDto otherProjectDto = db.components().insertPublicProject(otherOrg);
db.users().insertPermissionOnAnyone(org, "u1");
db.users().insertPermissionOnAnyone(otherOrg, "not deleted u1");
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java
index ee915dfcc3b..e336195f3b8 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java
@@ -70,8 +70,8 @@ public class PermissionIndexerDaoTest {
@Before
public void setUp() throws Exception {
- project1 = componentDbTester.insertPrivateProject();
- project2 = componentDbTester.insertPrivateProject();
+ project1 = componentDbTester.insertPublicProject();
+ project2 = componentDbTester.insertPublicProject();
view1 = componentDbTester.insertView();
view2 = componentDbTester.insertView();
user1 = userDbTester.insertUser();
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java
index aa6234fcde0..8e0d2c54d87 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java
@@ -273,13 +273,13 @@ public class PermissionIndexerTest {
}
private ComponentDto createAndIndexProject() {
- ComponentDto project = componentDbTester.insertPrivateProject();
+ ComponentDto project = componentDbTester.insertPublicProject();
fooIndexer.indexProject(project.uuid(), ProjectIndexer.Cause.PROJECT_CREATION);
return project;
}
private ComponentDto createAndIndexProject(OrganizationDto org) {
- ComponentDto project = componentDbTester.insertPrivateProject(org);
+ ComponentDto project = componentDbTester.insertPublicProject(org);
fooIndexer.indexProject(project.uuid(), ProjectIndexer.Cause.PROJECT_CREATION);
return project;
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java
index 4659cb50903..9c7dfc4d288 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java
@@ -250,7 +250,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea
}
private ComponentDto insertJdk7() {
- return db.components().insertComponent(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization())
+ return db.components().insertComponent(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization())
.setName("JDK 7")
.setKey("net.java.openjdk:jdk7")
.setUuid("0bd7b1e7-91d6-439e-a607-4a3a9aad3c6a"));
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/QgateProjectFinderTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/QgateProjectFinderTest.java
index 8f3a44c875b..aaa33da1888 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualitygate/QgateProjectFinderTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualitygate/QgateProjectFinderTest.java
@@ -89,8 +89,8 @@ public class QgateProjectFinderTest {
@Test
public void return_all_projects() throws Exception {
OrganizationDto org = dbTester.organizations().insert();
- ComponentDto associatedProject = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org));
- ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org));
+ ComponentDto associatedProject = insertProjectAuthorizedToAnyone(ComponentTesting.newPublicProjectDto(org));
+ ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(ComponentTesting.newPublicProjectDto(org));
associateProjectToQualitGate(associatedProject.getId());
Association result = underTest.find(
@@ -108,8 +108,8 @@ public class QgateProjectFinderTest {
@Test
public void return_only_associated_project() throws Exception {
OrganizationDto org = dbTester.organizations().insert();
- ComponentDto associatedProject = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org));
- insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org));
+ ComponentDto associatedProject = insertProjectAuthorizedToAnyone(ComponentTesting.newPublicProjectDto(org));
+ insertProjectAuthorizedToAnyone(ComponentTesting.newPublicProjectDto(org));
associateProjectToQualitGate(associatedProject.getId());
Association result = underTest.find(
@@ -126,8 +126,8 @@ public class QgateProjectFinderTest {
@Test
public void return_only_unassociated_project() throws Exception {
OrganizationDto org = dbTester.organizations().insert();
- ComponentDto associatedProject = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org));
- ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org));
+ ComponentDto associatedProject = insertProjectAuthorizedToAnyone(ComponentTesting.newPublicProjectDto(org));
+ ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(ComponentTesting.newPublicProjectDto(org));
associateProjectToQualitGate(associatedProject.getId());
Association result = underTest.find(
@@ -178,9 +178,9 @@ public class QgateProjectFinderTest {
@Test
public void test_paging() throws Exception {
OrganizationDto org = dbTester.organizations().insert();
- ComponentDto project1 = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org).setName("Project 1"));
- ComponentDto project2 = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org).setName("Project 2"));
- ComponentDto project3 = insertProjectAuthorizedToAnyone(ComponentTesting.newPrivateProjectDto(org).setName("Project 3"));
+ ComponentDto project1 = insertProjectAuthorizedToAnyone(ComponentTesting.newPublicProjectDto(org).setName("Project 1"));
+ ComponentDto project2 = insertProjectAuthorizedToAnyone(ComponentTesting.newPublicProjectDto(org).setName("Project 2"));
+ ComponentDto project3 = insertProjectAuthorizedToAnyone(ComponentTesting.newPublicProjectDto(org).setName("Project 3"));
associateProjectToQualitGate(project1.getId());
// Return partial result on first page
diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java
index d7f8208f0e0..a2b292d80d1 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java
@@ -208,7 +208,7 @@ public class ProjectsActionTest {
}
private ComponentDto newProject(String uuid, String name) {
- return ComponentTesting.newPrivateProjectDto(organizationDto, uuid).setName(name);
+ return ComponentTesting.newPublicProjectDto(organizationDto, uuid).setName(name);
}
private void addBrowsePermissionToAnyone(ComponentDto... projects) {
diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
index b8bc5b40540..d781a3a93de 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
@@ -292,15 +292,6 @@ public class ServerUserSessionTest {
}
@Test
- public void hasComponentPermissionByDtoOrUuid_returns_false_for_authenticated_user_for_permissions_USER_and_CODEVIEWER_on_private_projects_with_global_permissions() {
- ServerUserSession underTest = newUserSession(user);
- db.users().insertProjectPermissionOnAnyone("p1", privateProject);
-
- assertThat(hasComponentPermissionByDtoOrUuid(underTest, UserRole.USER, this.privateProject)).isFalse();
- assertThat(hasComponentPermissionByDtoOrUuid(underTest, UserRole.CODEVIEWER, this.privateProject)).isFalse();
- }
-
- @Test
public void hasComponentPermissionByDtoOrUuid_returns_false_for_authenticated_user_for_permissions_USER_and_CODEVIEWER_on_private_projects_with_group_permissions() {
ServerUserSession underTest = newUserSession(user);
db.users().insertProjectPermissionOnGroup(db.users().insertGroup(organization), "p1", privateProject);
@@ -327,14 +318,6 @@ public class ServerUserSessionTest {
}
@Test
- public void hasComponentPermissionByDtoOrUuid_returns_true_for_anonymous_user_for_inserted_permissions_on_group_AnyOne_on_private_projects() {
- ServerUserSession underTest = newAnonymousSession();
- db.users().insertProjectPermissionOnAnyone("p1", privateProject);
-
- assertThat(hasComponentPermissionByDtoOrUuid(underTest, "p1", privateProject)).isTrue();
- }
-
- @Test
public void hasComponentPermissionByDtoOrUuid_returns_false_for_anonymous_user_for_inserted_permissions_on_group_on_public_projects() {
ServerUserSession underTest = newAnonymousSession();
db.users().insertProjectPermissionOnGroup(groupOfUser, "p1", publicProject);
diff --git a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
index a26325f0635..e97151a52a5 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java
@@ -165,7 +165,7 @@ public class ViewIndexerTest {
}
private ComponentDto addProjectWithIssue(RuleDto rule, OrganizationDto org) {
- ComponentDto project = ComponentTesting.newPrivateProjectDto(org);
+ ComponentDto project = ComponentTesting.newPublicProjectDto(org);
ComponentDto file = ComponentTesting.newFileDto(project, null);
dbTester.components().insertComponents(project, file);
dbTester.users().insertProjectPermissionOnAnyone(UserRole.USER, project);