aboutsummaryrefslogtreecommitdiffstats
path: root/it
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2017-04-12 14:40:57 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2017-04-13 11:51:55 +0200
commit31fd813798325787f929ceac48e035f2fc7856bb (patch)
treeffffc89e77fc02327e29e641ad0b8d30fc7a2096 /it
parente77e47287738cef87f89645ad0f939e1cc7d51c5 (diff)
downloadsonarqube-31fd813798325787f929ceac48e035f2fc7856bb.tar.gz
sonarqube-31fd813798325787f929ceac48e035f2fc7856bb.zip
SONAR-9037 Add ITs checking that users are not member of default organization
Diffstat (limited to 'it')
-rw-r--r--it/it-tests/src/test/java/it/Category6Suite.java11
-rw-r--r--it/it-tests/src/test/java/it/organization/OrganizationMembershipTest.java7
-rw-r--r--it/it-tests/src/test/java/it/user/OrganizationIdentityProviderTest.java144
3 files changed, 158 insertions, 4 deletions
diff --git a/it/it-tests/src/test/java/it/Category6Suite.java b/it/it-tests/src/test/java/it/Category6Suite.java
index adfbca5970d..8f5f70f0d30 100644
--- a/it/it-tests/src/test/java/it/Category6Suite.java
+++ b/it/it-tests/src/test/java/it/Category6Suite.java
@@ -24,12 +24,14 @@ import it.organization.IssueAssignTest;
import it.organization.OrganizationMembershipTest;
import it.organization.OrganizationQualityProfilesPageTest;
import it.organization.OrganizationTest;
+import it.user.OrganizationIdentityProviderTest;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import static java.util.Collections.emptyMap;
+import static util.ItUtils.pluginArtifact;
import static util.ItUtils.xooPlugin;
/**
@@ -37,17 +39,18 @@ import static util.ItUtils.xooPlugin;
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
- // organization
- OrganizationTest.class,
- OrganizationMembershipTest.class,
IssueAssignTest.class,
- OrganizationQualityProfilesPageTest.class
+ OrganizationIdentityProviderTest.class,
+ OrganizationMembershipTest.class,
+ OrganizationQualityProfilesPageTest.class,
+ OrganizationTest.class
})
public class Category6Suite {
@ClassRule
public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
.addPlugin(xooPlugin())
+ .addPlugin(pluginArtifact("base-auth-plugin"))
.build();
@BeforeClass
diff --git a/it/it-tests/src/test/java/it/organization/OrganizationMembershipTest.java b/it/it-tests/src/test/java/it/organization/OrganizationMembershipTest.java
index 5637ca782b0..4f6dbe6cc15 100644
--- a/it/it-tests/src/test/java/it/organization/OrganizationMembershipTest.java
+++ b/it/it-tests/src/test/java/it/organization/OrganizationMembershipTest.java
@@ -83,6 +83,13 @@ public class OrganizationMembershipTest {
}
@Test
+ public void new_user_should_not_become_member_of_default_organization() throws Exception {
+ String login = createUser();
+
+ verifyMembership(login, "default-organization", false);
+ }
+
+ @Test
public void add_and_remove_member() throws Exception {
String organizationKey = createOrganization();
String login = createUser();
diff --git a/it/it-tests/src/test/java/it/user/OrganizationIdentityProviderTest.java b/it/it-tests/src/test/java/it/user/OrganizationIdentityProviderTest.java
new file mode 100644
index 00000000000..d62e6863a8e
--- /dev/null
+++ b/it/it-tests/src/test/java/it/user/OrganizationIdentityProviderTest.java
@@ -0,0 +1,144 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package it.user;
+
+import com.google.common.base.Joiner;
+import com.sonar.orchestrator.Orchestrator;
+import it.Category6Suite;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonarqube.ws.client.GetRequest;
+import org.sonarqube.ws.client.WsClient;
+import util.user.UserRule;
+
+import static it.Category6Suite.enableOrganizationsSupport;
+import static util.ItUtils.newAdminWsClient;
+import static util.ItUtils.resetSettings;
+import static util.ItUtils.setServerProperty;
+
+public class OrganizationIdentityProviderTest {
+
+ @ClassRule
+ public static Orchestrator ORCHESTRATOR = Category6Suite.ORCHESTRATOR;
+
+ @ClassRule
+ public static UserRule userRule = UserRule.from(ORCHESTRATOR);
+
+ private static String USER_LOGIN = "john";
+
+ private static String GROUP = "group";
+
+ private static WsClient adminWsClient;
+
+ @BeforeClass
+ public static void enableOrganizations() {
+ enableOrganizationsSupport();
+ adminWsClient = newAdminWsClient(ORCHESTRATOR);
+ setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabled", "true");
+ }
+
+ private static void purgeSettings(){
+ resetSettings(ORCHESTRATOR, null, "sonar.auth.fake-base-id-provider.enabled", "sonar.auth.fake-base-id-provider.user",
+ "sonar.auth.fake-base-id-provider.throwUnauthorizedMessage", "sonar.auth.fake-base-id-provider.enabledGroupsSync", "sonar.auth.fake-base-id-provider.groups",
+ "sonar.auth.fake-base-id-provider.allowsUsersToSignUp");
+ }
+
+ @AfterClass
+ public static void cleanUp() throws Exception {
+ purgeSettings();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ userRule.deactivateUsers(USER_LOGIN);
+ userRule.removeGroups(GROUP);
+ purgeSettings();
+ }
+
+ @Test
+ public void default_group_is_not_added_for_new_user_when_organizations_are_enabled() throws Exception {
+ enablePlugin();
+ userRule.createGroup(GROUP);
+ enableUserCreationByAuthPlugin();
+ setGroupsReturnedByAuthPlugin(GROUP);
+
+ authenticateWithFakeAuthProvider();
+
+ // No default group membership
+ userRule.verifyUserGroupMembership(USER_LOGIN, GROUP);
+ }
+
+ @Test
+ public void default_group_is_not_sync_for_existing_user_when_organizations_are_enabled() throws Exception {
+ enablePlugin();
+ userRule.createGroup(GROUP);
+ userRule.createUser(USER_LOGIN, "password");
+ enableUserCreationByAuthPlugin();
+ setGroupsReturnedByAuthPlugin(GROUP);
+
+ authenticateWithFakeAuthProvider();
+
+ // No default group membership
+ userRule.verifyUserGroupMembership(USER_LOGIN, GROUP);
+ }
+
+ @Test
+ public void remove_default_group_when_organizations_are_enabled() throws Exception {
+ enablePlugin();
+ userRule.createGroup(GROUP);
+ userRule.createUser(USER_LOGIN, "password");
+ // Add user as member of default organization
+ adminWsClient.organizations().addMember("default-organization", USER_LOGIN);
+ userRule.verifyUserGroupMembership(USER_LOGIN, "Members");
+ enableUserCreationByAuthPlugin();
+ // No group is returned by the plugin
+ setGroupsReturnedByAuthPlugin();
+
+ authenticateWithFakeAuthProvider();
+
+ // No default group membership
+ userRule.verifyUserGroupMembership(USER_LOGIN);
+ }
+
+ private static void enablePlugin() {
+ setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabled", "true");
+ }
+
+ private static void enableUserCreationByAuthPlugin() {
+ setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.user", USER_LOGIN + ",fake-john,John,john@email.com");
+ }
+
+ private static void setGroupsReturnedByAuthPlugin(String... groups) {
+ setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabledGroupsSync", "true");
+ if (groups.length > 0) {
+ setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.groups", Joiner.on(",").join(groups));
+ }
+ }
+
+ private static void authenticateWithFakeAuthProvider() {
+ adminWsClient.wsConnector().call(
+ new GetRequest("/sessions/init/fake-base-id-provider"))
+ .failIfNotSuccessful();
+ }
+
+}