]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9140 enforce permission consistency for private component in UTs
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 19 Apr 2017 13:22:24 +0000 (15:22 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 27 Apr 2017 12:25:54 +0000 (14:25 +0200)
ie. in UserDbTester

server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/permission/GroupPermissionDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDbTester.java
server/sonar-server/src/test/java/org/sonar/server/organization/ws/DeleteActionTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/index/PermissionIndexerDaoTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/index/PermissionIndexerTest.java
server/sonar-server/src/test/java/org/sonar/server/permission/ws/SearchProjectPermissionsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/qualitygate/QgateProjectFinderTest.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/ProjectsActionTest.java
server/sonar-server/src/test/java/org/sonar/server/user/ServerUserSessionTest.java
server/sonar-server/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java

index 832cb34720a8f9e1c976cc7ad5c15226f0d8906a..27d1436e522f8a20a85e662464a137d4808fe317 100644 (file)
@@ -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);
index ebf1282582c074fd4cb5088e6da85771c23bac06..4248603a803f81f82314cba9ec030c58783ed037 100644 (file)
@@ -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();
@@ -76,6 +76,32 @@ public class GroupPermissionDaoTest {
     ComponentDto project2 = db.components().insertPrivateProject();
     ComponentDto project3 = db.components().insertPrivateProject();
 
+    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);
+    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);
@@ -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);
@@ -180,6 +206,31 @@ public class GroupPermissionDaoTest {
       builderOnComponent.setPermission(USER).build())).containsOnlyOnce(ANYONE);
   }
 
+  @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");
@@ -285,13 +336,48 @@ public class GroupPermissionDaoTest {
     assertThat(underTest.selectByGroupIds(dbSession, org.getUuid(), Collections.emptyList(), project.getId())).isEmpty();
   }
 
+  @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);
index 3fa01eec830bd12e99d9f47ff19f61894b24a347..31d3741c31a198312a6d2817487f9721a1a58a75 100644 (file)
@@ -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)
index d1a471340bca576ad2a40d0efbfa77d2d29ed6a5..54f0928d22c67bb312aa817b0e869f036c97d62f 100644 (file)
@@ -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");
index ee915dfcc3b8e60f1c7aaae2a45d07acd306e22e..e336195f3b81eb71b915c96d574be5bdaa844c16 100644 (file)
@@ -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();
index aa6234fcde05c4610333ced4cd22a383eb438683..8e0d2c54d87a26b9f02c8ff1e110c9e8681d8659 100644 (file)
@@ -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;
   }
index 4659cb5090313d43043cb012160754eabc745225..9c7dfc4d288debb65e81379f815a796d34c4f2da 100644 (file)
@@ -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"));
index 8f3a44c875b4e9898cfb7d9d3df116818e5e42eb..aaa33da188809169f5dd4cbd6bd22b8942c4a0a4 100644 (file)
@@ -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
index d7f8208f0e09273b13051cfd25625098e265b3f3..a2b292d80d13ee3f359459212ee7742cc22855ee 100644 (file)
@@ -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) {
index b8bc5b40540ccc0190b1a1c9e630287dcfa85200..d781a3a93deb153964e326acf75e1074c179c977 100644 (file)
@@ -291,15 +291,6 @@ public class ServerUserSessionTest {
     assertThat(hasComponentPermissionByDtoOrUuid(underTest, UserRole.CODEVIEWER, privateProject)).isFalse();
   }
 
-  @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);
@@ -326,14 +317,6 @@ public class ServerUserSessionTest {
     assertThat(hasComponentPermissionByDtoOrUuid(underTest, "p1", publicProject)).isTrue();
   }
 
-  @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();
index a26325f0635a3cd0ae1f814eb9b5938b4ac01ab4..e97151a52a5037ee589ba0d68c08a0e0aeb25b2d 100644 (file)
@@ -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);