import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
+import org.sonar.wsclient.services.PropertyUpdateQuery;
import org.sonarqube.ws.WsUserTokens;
import org.sonarqube.ws.client.GetRequest;
import org.sonarqube.ws.client.HttpConnector;
assertThat(buildResult.isSuccess()).isFalse();
}
+ @Test
+ public void authentication_with_web_service() {
+ assertThat(checkAuthenticationThroughWebService("admin", "admin")).isTrue();
+ assertThat(checkAuthenticationThroughWebService("wrong", "admin")).isFalse();
+ assertThat(checkAuthenticationThroughWebService("admin", "wrong")).isFalse();
+ assertThat(checkAuthenticationThroughWebService(null, null)).isTrue();
+
+ ORCHESTRATOR.getServer().getAdminWsClient().update(new PropertyUpdateQuery("sonar.forceAuthentication", "true"));
+
+ assertThat(checkAuthenticationThroughWebService("admin", "admin")).isTrue();
+ assertThat(checkAuthenticationThroughWebService("wrong", "admin")).isFalse();
+ assertThat(checkAuthenticationThroughWebService("admin", "wrong")).isFalse();
+ assertThat(checkAuthenticationThroughWebService(null, null)).isFalse();
+ }
+
+ private boolean checkAuthenticationThroughWebService(String login, String password) {
+ String result = ORCHESTRATOR.getServer().wsClient(login, password).get("/api/authentication/validate");
+ return result.contains("true");
+ }
+
private static void createUser(String login, String password) {
adminWsClient.wsConnector().call(
new PostRequest("api/users/create")