diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-09-27 09:41:52 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-09-28 16:32:36 +0200 |
commit | c8ccfa2cedc3b7e33730ad5303382eaf75907cdb (patch) | |
tree | 2f6a2cb95b6427388d599e3b6d3a1e87254564d7 /sonar-db/src/test | |
parent | 9974dee49c30039d9c61d2e67b476f8beaea5959 (diff) | |
download | sonarqube-c8ccfa2cedc3b7e33730ad5303382eaf75907cdb.tar.gz sonarqube-c8ccfa2cedc3b7e33730ad5303382eaf75907cdb.zip |
Clean-up AuthorizationDao
Diffstat (limited to 'sonar-db/src/test')
4 files changed, 5 insertions, 217 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/user/AuthorizationDaoTest.java b/sonar-db/src/test/java/org/sonar/db/user/AuthorizationDaoTest.java index 53c43c9be32..44e07eb3b90 100644 --- a/sonar-db/src/test/java/org/sonar/db/user/AuthorizationDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/user/AuthorizationDaoTest.java @@ -29,19 +29,17 @@ import org.sonar.db.DbTester; import static com.google.common.collect.Sets.newHashSet; import static org.assertj.core.api.Assertions.assertThat; - public class AuthorizationDaoTest { private static final int USER = 100; private static final Long PROJECT_ID = 300L; private static final Long PROJECT_ID_WITHOUT_SNAPSHOT = 400L; private static final String PROJECT = "pj-w-snapshot"; - private static final String PROJECT_WIHOUT_SNAPSHOT = "pj-wo-snapshot"; @Rule public DbTester dbTester = DbTester.create(System2.INSTANCE); - AuthorizationDao authorization = dbTester.getDbClient().authorizationDao(); + private AuthorizationDao authorization = dbTester.getDbClient().authorizationDao(); @Test public void user_should_be_authorized() { @@ -61,7 +59,7 @@ public class AuthorizationDaoTest { assertThat(componentIds).isEmpty(); assertThat(authorization.keepAuthorizedProjectIds(dbTester.getSession(), - Collections.<Long>emptySet(), + Collections.emptySet(), USER, "admin")).isEmpty(); } @@ -75,7 +73,7 @@ public class AuthorizationDaoTest { assertThat(authorization.keepAuthorizedProjectIds(dbTester.getSession(), newHashSet(PROJECT_ID), USER, "admin")).isEmpty(); // Empty list - assertThat(authorization.keepAuthorizedProjectIds(dbTester.getSession(), Collections.<Long>emptySet(), USER, "admin")).isEmpty(); + assertThat(authorization.keepAuthorizedProjectIds(dbTester.getSession(), Collections.emptySet(), USER, "admin")).isEmpty(); } @Test @@ -88,7 +86,7 @@ public class AuthorizationDaoTest { assertThat(authorization.keepAuthorizedProjectIds(dbTester.getSession(), newHashSet(PROJECT_ID), USER, "admin")).isEmpty(); // Empty list - assertThat(authorization.keepAuthorizedProjectIds(dbTester.getSession(), Collections.<Long>emptySet(), USER, "admin")).isEmpty(); + assertThat(authorization.keepAuthorizedProjectIds(dbTester.getSession(), Collections.emptySet(), USER, "admin")).isEmpty(); } @Test @@ -101,38 +99,7 @@ public class AuthorizationDaoTest { assertThat(authorization.keepAuthorizedProjectIds(dbTester.getSession(), newHashSet(PROJECT_ID), null, "admin")).isEmpty(); // Empty list - assertThat(authorization.keepAuthorizedProjectIds(dbTester.getSession(), Collections.<Long>emptySet(), null, "admin")).isEmpty(); - } - - @Test - public void is_authorized_component_key_for_user() { - dbTester.prepareDbUnit(getClass(), "keep_authorized_project_ids_for_user.xml"); - - assertThat(authorization.isAuthorizedComponentKey(PROJECT, USER, "user")).isTrue(); - assertThat(authorization.isAuthorizedComponentKey(PROJECT_WIHOUT_SNAPSHOT, USER, "user")).isFalse(); - - // user does not have the role "admin" - assertThat(authorization.isAuthorizedComponentKey(PROJECT, USER, "admin")).isFalse(); - } - - @Test - public void is_authorized_component_key_for_group() { - dbTester.prepareDbUnit(getClass(), "keep_authorized_project_ids_for_group.xml"); - - assertThat(authorization.isAuthorizedComponentKey(PROJECT, USER, "user")).isTrue(); - assertThat(authorization.isAuthorizedComponentKey(PROJECT_WIHOUT_SNAPSHOT, USER, "user")).isFalse(); - - // user does not have the role "admin" - assertThat(authorization.isAuthorizedComponentKey(PROJECT, USER, "admin")).isFalse(); - } - - @Test - public void is_authorized_component_key_for_anonymous() { - dbTester.prepareDbUnit(getClass(), "keep_authorized_project_ids_for_anonymous.xml"); - - assertThat(authorization.isAuthorizedComponentKey(PROJECT, null, "user")).isTrue(); - assertThat(authorization.isAuthorizedComponentKey(PROJECT_WIHOUT_SNAPSHOT, null, "user")).isFalse(); - assertThat(authorization.isAuthorizedComponentKey(PROJECT, null, "admin")).isFalse(); + assertThat(authorization.keepAuthorizedProjectIds(dbTester.getSession(), Collections.emptySet(), null, "admin")).isEmpty(); } @Test @@ -282,50 +249,4 @@ public class AuthorizationDaoTest { assertThat(authorization.selectGlobalPermissions("anyone_user")).containsOnly("user", "profileadmin"); } - @Test - public void keep_authorized_users_for_role_and_project_for_user() { - dbTester.prepareDbUnit(getClass(), "keep_authorized_users_for_role_and_project_for_user.xml"); - - assertThat(authorization.keepAuthorizedUsersForRoleAndProject(dbTester.getSession(), - // Only 100 and 101 has 'user' role on project - newHashSet(100L, 101L, 102L), "user", PROJECT_ID)).containsOnly(100L, 101L); - - assertThat(authorization.keepAuthorizedUsersForRoleAndProject(dbTester.getSession(), - // Only 100 and 101 has 'user' role on project - newHashSet(100L), "user", PROJECT_ID)).containsOnly(100L); - - // user does not have the role "admin" - assertThat(authorization.keepAuthorizedUsersForRoleAndProject(dbTester.getSession(), newHashSet(100L), "admin", PROJECT_ID)).isEmpty(); - - // Empty list - assertThat(authorization.keepAuthorizedUsersForRoleAndProject(dbTester.getSession(), Collections.<Long>emptySet(), "user", PROJECT_ID)).isEmpty(); - } - - @Test - public void keep_authorized_users_for_role_and_project_for_group() { - dbTester.prepareDbUnit(getClass(), "keep_authorized_users_for_role_and_project_for_group.xml"); - - assertThat(authorization.keepAuthorizedUsersForRoleAndProject(dbTester.getSession(), - // Only 100 and 101 has 'user' role on project - newHashSet(100L, 101L, 102L), "user", PROJECT_ID)).containsOnly(100L, 101L); - - assertThat(authorization.keepAuthorizedUsersForRoleAndProject(dbTester.getSession(), - newHashSet(100L), "user", PROJECT_ID)).containsOnly(100L); - - // user does not have the role "admin" - assertThat(authorization.keepAuthorizedUsersForRoleAndProject(dbTester.getSession(), newHashSet(100L), "admin", PROJECT_ID)).isEmpty(); - - // Empty list - assertThat(authorization.keepAuthorizedUsersForRoleAndProject(dbTester.getSession(), Collections.<Long>emptySet(), "user", PROJECT_ID)).isEmpty(); - } - - @Test - public void keep_authorized_users_returns_empty_list_for_role_and_project_for_anonymous() { - dbTester.prepareDbUnit(getClass(), "keep_authorized_users_for_role_and_project_for_anonymous.xml"); - - assertThat(authorization.keepAuthorizedUsersForRoleAndProject(dbTester.getSession(), - // Only 100 and 101 has 'user' role on project - newHashSet(100L, 101L, 102L), "user", PROJECT_ID)).isEmpty(); - } - } diff --git a/sonar-db/src/test/resources/org/sonar/db/user/AuthorizationDaoTest/keep_authorized_users_for_role_and_project_for_anonymous.xml b/sonar-db/src/test/resources/org/sonar/db/user/AuthorizationDaoTest/keep_authorized_users_for_role_and_project_for_anonymous.xml deleted file mode 100644 index 93356a34bda..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/user/AuthorizationDaoTest/keep_authorized_users_for_role_and_project_for_anonymous.xml +++ /dev/null @@ -1,46 +0,0 @@ -<dataset> - - <!-- users 100 and 101 have no direct grant access, but are in the group 200 that has the role "user" on the project 300 --> - <user_roles id="1" - user_id="100" - resource_id="999" - role="user"/> - <user_roles id="2" - user_id="101" - resource_id="999" - role="user"/> - <user_roles id="3" - user_id="102" - resource_id="999" - role="user"/> - - <groups_users user_id="100" - group_id="200"/> - <groups_users user_id="101" - group_id="200"/> - <groups_users user_id="102" - group_id="201"/> - - <group_roles id="1" - group_id="[null]" - resource_id="300" - role="user"/> - <group_roles id="2" - group_id="201" - resource_id="400" - role="user"/> - - <projects id="300" - kee="pj-w-snapshot" - uuid="DEFG" - uuid_path="NOT_USED" - root_uuid="DEFG" - module_uuid="[null]"/> - <projects id="400" - kee="pj-wo-snapshot" - uuid="EFGH" - uuid_path="NOT_USED" - root_uuid="EFGH" - module_uuid="[null]"/> - -</dataset> diff --git a/sonar-db/src/test/resources/org/sonar/db/user/AuthorizationDaoTest/keep_authorized_users_for_role_and_project_for_group.xml b/sonar-db/src/test/resources/org/sonar/db/user/AuthorizationDaoTest/keep_authorized_users_for_role_and_project_for_group.xml deleted file mode 100644 index 3b7278e4c0a..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/user/AuthorizationDaoTest/keep_authorized_users_for_role_and_project_for_group.xml +++ /dev/null @@ -1,46 +0,0 @@ -<dataset> - - <!-- users 100 and 101 have no direct grant access, but are in the group 200 that has the role "user" on the project 300 --> - <user_roles id="1" - user_id="100" - resource_id="999" - role="user"/> - <user_roles id="2" - user_id="101" - resource_id="999" - role="user"/> - <user_roles id="3" - user_id="102" - resource_id="999" - role="user"/> - - <groups_users user_id="100" - group_id="200"/> - <groups_users user_id="101" - group_id="200"/> - <groups_users user_id="102" - group_id="201"/> - - <group_roles id="1" - group_id="200" - resource_id="300" - role="user"/> - <group_roles id="2" - group_id="201" - resource_id="400" - role="user"/> - - <projects id="300" - kee="pj-w-snapshot" - uuid="DEFG" - uuid_path="NOT_USED" - root_uuid="DEFG" - module_uuid="[null]"/> - <projects id="400" - kee="pj-wo-snapshot" - uuid="EFGH" - uuid_path="NOT_USED" - root_uuid="EFGH" - module_uuid="[null]"/> - -</dataset> diff --git a/sonar-db/src/test/resources/org/sonar/db/user/AuthorizationDaoTest/keep_authorized_users_for_role_and_project_for_user.xml b/sonar-db/src/test/resources/org/sonar/db/user/AuthorizationDaoTest/keep_authorized_users_for_role_and_project_for_user.xml deleted file mode 100644 index 173657868ec..00000000000 --- a/sonar-db/src/test/resources/org/sonar/db/user/AuthorizationDaoTest/keep_authorized_users_for_role_and_project_for_user.xml +++ /dev/null @@ -1,41 +0,0 @@ -<dataset> - - <!-- Users 100 and 101 are 'user' on project 300 --> - <user_roles id="1" - user_id="100" - resource_id="300" - role="user"/> - <user_roles id="2" - user_id="101" - resource_id="300" - role="user"/> - <user_roles id="3" - user_id="102" - resource_id="300" - role="admin"/> - <user_roles id="4" - user_id="100" - resource_id="400" - role="user"/> - - <groups_users user_id="100" - group_id="200"/> - <group_roles id="1" - group_id="200" - resource_id="400" - role="user"/> - - <projects id="300" - kee="pj-w-snapshot" - uuid="DEFG" - uuid_path="NOT_USED" - root_uuid="DEFG" - module_uuid="[null]"/> - <projects id="400" - kee="pj-wo-snapshot" - uuid="EFGH" - uuid_path="NOT_USED" - root_uuid="EFGH" - module_uuid="[null]"/> - -</dataset> |