@After
public void cleanUpUsersAndGroupsAndProperties() throws Exception {
- userRule.deactivateUsers(USER_LOGIN);
+ userRule.resetUsers();
userRule.removeGroups(GROUP1, GROUP2, GROUP3);
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.throwUnauthorizedMessage", "sonar.auth.fake-base-id-provider.enabledGroupsSync", "sonar.auth.fake-base-id-provider.groups",
+ "sonar.auth.fake-base-id-provider.allowsUsersToSignUp");
}
@Test
userRule.verifyUserGroupMembership(USER_LOGIN);
}
+ @Test
+ public void allow_user_login_with_2_characters() throws Exception {
+ enablePlugin();
+ String login = "jo";
+ setUserCreatedByAuthPlugin(login, USER_PROVIDER_ID, USER_NAME, USER_EMAIL);
+ userRule.verifyUserDoesNotExist(login);
+
+ // First connection, user is created
+ authenticateWithFakeAuthProvider();
+
+ userRule.verifyUserExists(login, USER_NAME, USER_EMAIL, false);
+ }
+
private static void enablePlugin() {
setServerProperty(ORCHESTRATOR, "sonar.auth.fake-base-id-provider.enabled", "true");
}
assertThat(checkAuthenticationWithAuthenticateWebService(login, password)).isFalse();
}
+ @Test
+ public void allow_user_login_with_2_characters() throws Exception {
+ userRule.createUser("jo", "password");
+
+ assertThat(checkAuthenticationWithAuthenticateWebService("jo", "password")).isTrue();
+ }
+
@Test
public void allow_users_to_sign_up() throws IOException {
setServerProperty(ORCHESTRATOR, "sonar.allowUsersToSignUp", "true");
import org.sonarqube.ws.client.WsClientFactories;
import org.sonarqube.ws.client.WsResponse;
import util.selenium.SeleneseTest;
+import util.user.UserRule;
import static java.net.HttpURLConnection.HTTP_OK;
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
.setServerProperty("sonar.security.realm", "FakeRealm")
.build();
+ @ClassRule
+ public static UserRule USER_RULE = UserRule.from(orchestrator);
+
@Before
@After
public void resetData() throws Exception {
setServerProperty(orchestrator, USERS_PROPERTY, null);
setServerProperty(orchestrator, "sonar.security.updateUserAttributes", null);
setServerProperty(orchestrator, "sonar.authenticator.createUsers", null);
- resetUsers(USER_LOGIN, TECH_USER);
- }
-
- private void resetUsers(String... logins) {
- for (String login : logins) {
- String result = orchestrator.getServer().adminWsClient().get("/api/users/search?q=" + login);
- if (result.contains(login)) {
- orchestrator.getServer().adminWsClient().userClient().deactivate(login);
- }
- }
+ USER_RULE.resetUsers();
}
/**
assertThat(checkAuthenticationWithWebService(null, null).code()).isEqualTo(HTTP_UNAUTHORIZED);
}
+ @Test
+ public void allow_user_login_with_2_characters() {
+ String username = "jo";
+ String password = "1234567";
+ updateUsersInExtAuth(ImmutableMap.of(username + ".password", password));
+
+ assertThat(loginAttempt(username, password)).isEqualTo(AUTHORIZED);
+ }
+
protected void verifyHttpException(Exception e, int expectedCode) {
assertThat(e).isInstanceOf(HttpException.class);
HttpException exception = (HttpException) e;
*/
package org.sonar.api.server.authentication;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.FluentIterable.from;
-import static org.apache.commons.lang.StringUtils.isNotBlank;
-import static org.sonar.api.user.UserGroupValidation.validateGroupName;
-
import com.google.common.base.Predicate;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.concurrent.Immutable;
import org.sonar.api.CoreProperties;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.FluentIterable.from;
+import static org.apache.commons.lang.StringUtils.isNotBlank;
+import static org.sonar.api.user.UserGroupValidation.validateGroupName;
+
/**
* User information provided by the Identity Provider to be register into the platform.
*
private static void validateLogin(String login) {
checkArgument(isNotBlank(login), "User login must not be blank");
- checkArgument(login.length() <= 255 && login.length() >= 3, "User login size is incorrect (Between 3 and 255 characters)");
+ checkArgument(login.length() <= 255 && login.length() >= 2, "User login size is incorrect (Between 2 and 255 characters)");
}
private static void validateName(String name) {
*/
package org.sonar.api.server.authentication;
-import static com.google.common.collect.Sets.newHashSet;
-import static org.assertj.core.api.Assertions.assertThat;
-
import com.google.common.base.Strings;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import static com.google.common.collect.Sets.newHashSet;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class UserIdentityTest {
@Rule
@Test
public void fail_when_login_is_too_long() throws Exception {
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("User login size is incorrect (Between 3 and 255 characters)");
+ thrown.expectMessage("User login size is incorrect (Between 2 and 255 characters)");
UserIdentity.builder()
.setProviderLogin("john")
.setLogin(Strings.repeat("1", 256))
@Test
public void fail_when_login_is_too_small() throws Exception {
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("User login size is incorrect (Between 3 and 255 characters)");
+ thrown.expectMessage("User login size is incorrect (Between 2 and 255 characters)");
UserIdentity.builder()
.setProviderLogin("john")
- .setLogin("12")
+ .setLogin("j")
.setName("John")
.setEmail("john@email.com")
.build();