import com.sonar.orchestrator.Orchestrator;
import com.sonar.orchestrator.selenium.Selenese;
import java.util.Map;
+import org.apache.commons.lang.RandomStringUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.sonar.wsclient.connectors.ConnectionException;
import org.sonar.wsclient.connectors.HttpClient4Connector;
import org.sonar.wsclient.services.AuthenticationQuery;
-import org.sonar.wsclient.services.PropertyUpdateQuery;
import org.sonar.wsclient.services.UserPropertyCreateQuery;
import org.sonar.wsclient.services.UserPropertyQuery;
import org.sonar.wsclient.user.UserParameters;
public static final Orchestrator orchestrator = Orchestrator.builderEnv()
.addPlugin(pluginArtifact("security-plugin"))
.setServerProperty("sonar.security.realm", "FakeRealm")
- .setServerProperty("sonar.security.localUsers", "admin," + TECH_USER)
.build();
@Before
setServerProperty(orchestrator, "sonar.security.updateUserAttributes", null);
setServerProperty(orchestrator, "sonar.security.savePassword", null);
setServerProperty(orchestrator, "sonar.authenticator.createUsers", null);
- setServerProperty(orchestrator, "sonar.security.localUsers", null);
resetUsers(USER_LOGIN, TECH_USER);
}
assertThat(loginAttempt(login, password)).isEqualTo(NOT_AUTHORIZED);
}
- /**
- * SONAR-4543
- */
- @Test
- public void shouldNotAccessExternalSystemForLocalAccounts() {
- // Given clean Sonar installation and no users in external system
- setServerProperty(orchestrator, "sonar.security.savePassword", "false");
- String login = "localuser";
- String localPassword = "1234567";
- String remotePassword = "7654321";
- Map<String, String> users = Maps.newHashMap();
-
- // When user created in external system
- users.put(login + ".password", remotePassword);
- updateUsersInExtAuth(users);
- // And user exists in local database
- createUserInDb(login, localPassword);
-
- // Then this is external system that should be used
- assertThat(loginAttempt(login, remotePassword)).isEqualTo(AUTHORIZED);
- assertThat(loginAttempt(login, localPassword)).isEqualTo(NOT_AUTHORIZED);
-
- // Now set this user as technical account
- orchestrator.getServer().getAdminWsClient().update(new PropertyUpdateQuery("sonar.security.localUsers", "admin," + login));
-
- // Then this is local DB that should be used
- assertThat(loginAttempt(login, remotePassword)).isEqualTo(NOT_AUTHORIZED);
- assertThat(loginAttempt(login, localPassword)).isEqualTo(AUTHORIZED);
- }
-
/**
* SONAR-4543
*/
* SONAR-1334 (createUsers=false)
*/
@Test
- @Ignore("Fails because user is disable and rails doesn't handle this case (it's using User.find_by_login to know if user exists or not)")
public void shouldNotCreateNewUsers() {
// Given clean Sonar installation and no users in external system
setServerProperty(orchestrator, "sonar.authenticator.createUsers", "false");
- String username = USER_LOGIN;
+ // Use a random user name because if we use existing disabled user then it doesn't work because rails doesn't handle this case
+ // (it's using User.find_by_login to know if user exists or not
+ String username = RandomStringUtils.randomAlphanumeric(20);
String password = "1234567";
Map<String, String> users = Maps.newHashMap();
return adminWsClient;
}
- public void verifyUserExists(String login, String name, @Nullable String email) {
+ public Users.User verifyUserExists(String login, String name, @Nullable 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);
+ return user.get();
+ }
+
+ public void verifyUserExists(String login, String name, @Nullable String email, boolean local) {
+ Users.User user = verifyUserExists(login, name, email);
+ Assertions.assertThat(user.isLocal()).isEqualTo(local);
}
public void verifyUserDoesNotExist(String login) {
private final List<String> groups;
private final List<String> scmAccounts;
private final boolean active;
+ private final boolean local;
private int tokensCount;
- private User(String login, String name, String email, List<String> groups, List<String> scmAccounts, boolean active, int tokensCount) {
+ private User(String login, String name, String email, List<String> groups, List<String> scmAccounts, boolean active, boolean local, int tokensCount) {
this.login = login;
this.name = name;
this.email = email;
this.scmAccounts = scmAccounts;
this.active = active;
this.tokensCount = tokensCount;
+ this.local = local;
}
public String getLogin() {
return active;
}
+ public boolean isLocal() {
+ return local;
+ }
+
public int getTokensCount() {
return tokensCount;
}