From c8ccfa2cedc3b7e33730ad5303382eaf75907cdb Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 27 Sep 2016 09:41:52 +0200 Subject: Clean-up AuthorizationDao --- .../org/sonar/db/user/AuthorizationDaoTest.java | 89 ++-------------------- ...ed_users_for_role_and_project_for_anonymous.xml | 46 ----------- ...orized_users_for_role_and_project_for_group.xml | 46 ----------- ...horized_users_for_role_and_project_for_user.xml | 41 ---------- 4 files changed, 5 insertions(+), 217 deletions(-) delete mode 100644 sonar-db/src/test/resources/org/sonar/db/user/AuthorizationDaoTest/keep_authorized_users_for_role_and_project_for_anonymous.xml delete mode 100644 sonar-db/src/test/resources/org/sonar/db/user/AuthorizationDaoTest/keep_authorized_users_for_role_and_project_for_group.xml delete mode 100644 sonar-db/src/test/resources/org/sonar/db/user/AuthorizationDaoTest/keep_authorized_users_for_role_and_project_for_user.xml (limited to 'sonar-db/src/test') 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.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.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.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.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.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.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 @@ - - - - - - - - - - - - - - - - - - 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 @@ - - - - - - - - - - - - - - - - - - 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 @@ - - - - - - - - - - - - - - - -- cgit v1.2.3