aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2016-01-28 11:30:24 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2016-02-01 13:46:16 +0100
commit5eca24289637ca2821104ad682d912841c0dcfa5 (patch)
tree69d630a5c9f48eeec325d800b47547d15ef34898
parent4da794930af2336e2802aa5d778aa091d646f016 (diff)
downloadsonarqube-5eca24289637ca2821104ad682d912841c0dcfa5.tar.gz
sonarqube-5eca24289637ca2821104ad682d912841c0dcfa5.zip
SONAR-7249 Update ITs
-rw-r--r--it/it-tests/src/test/java/it/authorisation/BaseIdentityProviderTest.java34
-rw-r--r--it/it-tests/src/test/java/it/authorisation/OAuth2IdentityProviderTest.java8
-rw-r--r--it/it-tests/src/test/java/util/user/UserRule.java29
3 files changed, 37 insertions, 34 deletions
diff --git a/it/it-tests/src/test/java/it/authorisation/BaseIdentityProviderTest.java b/it/it-tests/src/test/java/it/authorisation/BaseIdentityProviderTest.java
index 8e5825cdee7..cb789b06c14 100644
--- a/it/it-tests/src/test/java/it/authorisation/BaseIdentityProviderTest.java
+++ b/it/it-tests/src/test/java/it/authorisation/BaseIdentityProviderTest.java
@@ -49,8 +49,8 @@ public class BaseIdentityProviderTest {
static String FAKE_PROVIDER_KEY = "fake-base-id-provider";
- static String USER_PROVIDER_LOGIN = "john";
-
+ static String USER_LOGIN = "john";
+ static String USER_PROVIDER_ID = "fake-john";
static String USER_NAME = "John";
static String USER_EMAIL = "john@email.com";
@@ -63,6 +63,7 @@ public class BaseIdentityProviderTest {
public static void setUp() {
ORCHESTRATOR.resetData();
adminWsClient = newAdminWsClient(ORCHESTRATOR);
+ setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabled", "true");
}
@After
@@ -72,45 +73,42 @@ public class BaseIdentityProviderTest {
@Test
public void create_new_user_when_authenticate() throws Exception {
- setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabled", "true");
- setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.user", USER_PROVIDER_LOGIN + "," + USER_NAME + "," + USER_EMAIL);
+ setUserCreatedByAuthPlugin(USER_LOGIN, USER_PROVIDER_ID, USER_NAME, USER_EMAIL);
- userRule.verifyUserDoesNotExist(USER_EMAIL);
+ userRule.verifyUserDoesNotExist(USER_LOGIN);
// First connection, user is created
authenticateWithFakeAuthProvider();
- userRule.verifyUserExists(USER_NAME, USER_EMAIL);
+ userRule.verifyUserExists(USER_LOGIN, USER_NAME, USER_EMAIL);
}
@Test
public void update_existing_user_when_authenticate() throws Exception {
- setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabled", "true");
- setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.user", USER_PROVIDER_LOGIN + "," + USER_NAME + "," + USER_EMAIL);
+ setUserCreatedByAuthPlugin(USER_LOGIN, USER_PROVIDER_ID, USER_NAME, USER_EMAIL);
+
// First connection, user is created
authenticateWithFakeAuthProvider();
- setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.user", USER_PROVIDER_LOGIN + "," + USER_NAME_UPDATED + "," + USER_EMAIL_UPDATED);
+ setUserCreatedByAuthPlugin(USER_LOGIN, USER_PROVIDER_ID, USER_NAME_UPDATED, USER_EMAIL_UPDATED);
// Second connection, user should be updated
authenticateWithFakeAuthProvider();
- userRule.verifyUserDoesNotExist(USER_EMAIL);
- userRule.verifyUserExists(USER_NAME_UPDATED, USER_EMAIL_UPDATED);
+ userRule.verifyUserExists(USER_LOGIN, USER_NAME_UPDATED, USER_EMAIL_UPDATED);
}
@Test
@Ignore("Waiting for SONAR-7233 to be implemented")
public void reactivate_disabled_user() throws Exception {
- setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabled", "true");
- setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.user", USER_PROVIDER_LOGIN + "," + USER_NAME + "," + USER_EMAIL);
+ setUserCreatedByAuthPlugin(USER_LOGIN, USER_PROVIDER_ID, USER_NAME, USER_EMAIL);
- userRule.verifyUserDoesNotExist(USER_EMAIL);
+ userRule.verifyUserDoesNotExist(USER_LOGIN);
// First connection, user is created
authenticateWithFakeAuthProvider();
- Optional<Users.User> user = userRule.getUserByEmail(USER_EMAIL);
+ Optional<Users.User> user = userRule.getUserByLogin(USER_EMAIL);
assertThat(user).isPresent();
// Disable user
@@ -118,7 +116,11 @@ public class BaseIdentityProviderTest {
// Second connection, user is reactivated
authenticateWithFakeAuthProvider();
- userRule.verifyUserExists(USER_NAME, USER_EMAIL);
+ userRule.verifyUserExists(USER_LOGIN, USER_NAME, USER_EMAIL);
+ }
+
+ private void setUserCreatedByAuthPlugin(String login, String providerId, String name, String email){
+ setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.user", login + "," + providerId + "," + name + "," + email);
}
private void authenticateWithFakeAuthProvider() {
diff --git a/it/it-tests/src/test/java/it/authorisation/OAuth2IdentityProviderTest.java b/it/it-tests/src/test/java/it/authorisation/OAuth2IdentityProviderTest.java
index f1e5c3e2e40..9d34c18d935 100644
--- a/it/it-tests/src/test/java/it/authorisation/OAuth2IdentityProviderTest.java
+++ b/it/it-tests/src/test/java/it/authorisation/OAuth2IdentityProviderTest.java
@@ -49,8 +49,8 @@ public class OAuth2IdentityProviderTest {
static String FAKE_PROVIDER_KEY = "fake-oauth2-id-provider";
- static String USER_PROVIDER_LOGIN = "john";
-
+ static String USER_LOGIN = "john";
+ static String USER_PROVIDER_ID = "fake-john";
static String USER_NAME = "John";
static String USER_EMAIL = "john@email.com";
@@ -83,11 +83,11 @@ public class OAuth2IdentityProviderTest {
setServerProperty(ORCHESTRATOR, "sonar.auth.fake-oauth2-id-provider.enabled", "true");
setServerProperty(ORCHESTRATOR, "sonar.auth.fake-oauth2-id-provider.url", fakeServerAuthProviderUrl);
- setServerProperty(ORCHESTRATOR, "sonar.auth.fake-oauth2-id-provider.user", USER_PROVIDER_LOGIN + "," + USER_NAME + "," + USER_EMAIL);
+ setServerProperty(ORCHESTRATOR, "sonar.auth.fake-oauth2-id-provider.user", USER_LOGIN + "," + USER_PROVIDER_ID + "," + USER_NAME + "," + USER_EMAIL);
authenticateWithFakeAuthProvider();
- userRule.verifyUserExists(USER_NAME, USER_EMAIL);
+ userRule.verifyUserExists(USER_LOGIN, USER_NAME, USER_EMAIL);
}
private void authenticateWithFakeAuthProvider() {
diff --git a/it/it-tests/src/test/java/util/user/UserRule.java b/it/it-tests/src/test/java/util/user/UserRule.java
index 4c6b94ea98e..588738c4ea9 100644
--- a/it/it-tests/src/test/java/util/user/UserRule.java
+++ b/it/it-tests/src/test/java/util/user/UserRule.java
@@ -57,25 +57,26 @@ public class UserRule extends ExternalResource {
adminWsClient = newAdminWsClient(orchestrator);
}
- public void verifyUserExists(String name, String email) {
- Optional<Users.User> user = getUserByEmail(email);
- assertThat(user).isPresent();
+ public void verifyUserExists(String login, String name, String email) {
+ Optional<Users.User> user = getUserByLogin(login);
+ assertThat(user).as("User with login '%s' hasn't been found", login).isPresent();
+ Assertions.assertThat(user.get().getLogin()).isEqualTo(login);
Assertions.assertThat(user.get().getName()).isEqualTo(name);
Assertions.assertThat(user.get().getEmail()).isEqualTo(email);
}
- public void verifyUserDoesNotExist(String email) {
- assertThat(getUserByEmail(email)).isAbsent();
+ public void verifyUserDoesNotExist(String login) {
+ assertThat(getUserByLogin(login)).as("Unexpected user with login '%s' has been found", login).isAbsent();
}
- public Optional<Users.User> getUserByEmail(String email) {
- return FluentIterable.from(getUsers().getUsers()).firstMatch(new MatchUserEmail(email));
+ public Optional<Users.User> getUserByLogin(String login) {
+ return FluentIterable.from(getUsers().getUsers()).firstMatch(new MatchUserLogin(login));
}
public List<Users.User> getUsersByEmails(String... emails) {
List<Users.User> foundUsers = new ArrayList<>();
for (String email : emails) {
- Optional<Users.User> user = FluentIterable.from(getUsers().getUsers()).firstMatch(new MatchUserEmail(email));
+ Optional<Users.User> user = FluentIterable.from(getUsers().getUsers()).firstMatch(new MatchUserLogin(email));
if (user.isPresent()) {
foundUsers.add(user.get());
}
@@ -90,17 +91,17 @@ public class UserRule extends ExternalResource {
return Users.parse(response.content());
}
- private class MatchUserEmail implements Predicate<Users.User> {
- private final String email;
+ private class MatchUserLogin implements Predicate<Users.User> {
+ private final String login;
- private MatchUserEmail(String email) {
- this.email = email;
+ private MatchUserLogin(String login) {
+ this.login = login;
}
@Override
public boolean apply(@Nonnull Users.User user) {
- String userEmail = user.getEmail();
- return userEmail != null && userEmail.equals(email) && user.isActive();
+ String login = user.getLogin();
+ return login != null && login.equals(this.login) && user.isActive();
}
}