]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18397 add ITs for permanent users de-provisioning triggered by Azure (SCIM)
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Fri, 10 Feb 2023 09:47:32 +0000 (10:47 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 10 Feb 2023 20:02:45 +0000 (20:02 +0000)
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/ReportPublisher.java
sonar-ws/src/main/java/org/sonarqube/ws/client/DeleteRequest.java [new file with mode: 0644]
sonar-ws/src/main/java/org/sonarqube/ws/client/GetRequest.java
sonar-ws/src/main/java/org/sonarqube/ws/client/HttpConnector.java
sonar-ws/src/main/java/org/sonarqube/ws/client/RequestWithoutPayload.java [new file with mode: 0644]
sonar-ws/src/main/java/org/sonarqube/ws/client/WsRequest.java
sonar-ws/src/test/java/org/sonarqube/ws/client/DeleteRequestTest.java [new file with mode: 0644]
sonar-ws/src/test/java/org/sonarqube/ws/client/GetRequestTest.java [new file with mode: 0644]
sonar-ws/src/test/java/org/sonarqube/ws/client/ServiceTester.java

index a4783bab3f46a22dcbf36b4ab3009064d159789e..8d9d88d29c3225aff8ac6ef6fbc06b5a1feb5ac2 100644 (file)
@@ -55,6 +55,7 @@ import org.sonarqube.ws.Ce;
 import org.sonarqube.ws.MediaTypes;
 import org.sonarqube.ws.client.HttpException;
 import org.sonarqube.ws.client.PostRequest;
+import org.sonarqube.ws.client.RequestWithPayload.Part;
 import org.sonarqube.ws.client.WsResponse;
 
 import static java.net.URLEncoder.encode;
@@ -201,7 +202,7 @@ public class ReportPublisher implements Startable {
   String upload(File report) {
     LOG.debug("Upload report");
     long startTime = System.currentTimeMillis();
-    PostRequest.Part filePart = new PostRequest.Part(MediaTypes.ZIP, report);
+    Part filePart = new Part(MediaTypes.ZIP, report);
     PostRequest post = new PostRequest("api/ce/submit")
       .setMediaType(MediaTypes.PROTOBUF)
       .setParam("projectKey", moduleHierarchy.root().key())
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/DeleteRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/DeleteRequest.java
new file mode 100644 (file)
index 0000000..90f0e29
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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 org.sonarqube.ws.client;
+
+import java.util.function.Function;
+import okhttp3.Request;
+
+/**
+ * @since 5.3
+ */
+public class DeleteRequest extends RequestWithoutPayload<DeleteRequest> {
+  public DeleteRequest(String path) {
+    super(path);
+  }
+
+  @Override
+  public Method getMethod() {
+    return Method.DELETE;
+  }
+
+  @Override
+  Function<Request.Builder, Request.Builder> addVerbToBuilder() {
+    return Request.Builder::delete;
+  }
+}
index bc5a82d0e3c1fff8591a29562eeb9567d1c6dd29..e835346611d6e0ca92803f298578bc1a3f8458b4 100644 (file)
  */
 package org.sonarqube.ws.client;
 
+import java.util.function.Function;
+import okhttp3.Request;
+
 /**
  * @since 5.3
  */
-public class GetRequest extends BaseRequest<GetRequest> {
+public class GetRequest extends RequestWithoutPayload<GetRequest> {
   public GetRequest(String path) {
     super(path);
   }
@@ -31,4 +34,9 @@ public class GetRequest extends BaseRequest<GetRequest> {
   public Method getMethod() {
     return Method.GET;
   }
+
+  @Override
+  Function<Request.Builder, Request.Builder> addVerbToBuilder() {
+    return Request.Builder::get;
+  }
 }
index 92739e636f29dbf4ba97238381121d238dc1a3ee..a4fec2726a417a80932ff7aa0d09881ba8948657 100644 (file)
@@ -109,8 +109,8 @@ public class HttpConnector implements WsConnector {
 
   @Override
   public WsResponse call(WsRequest httpRequest) {
-    if (httpRequest instanceof GetRequest) {
-      return get((GetRequest) httpRequest);
+    if (httpRequest instanceof RequestWithoutPayload) {
+      return executeRequest((RequestWithoutPayload) httpRequest);
     }
     if (httpRequest instanceof RequestWithPayload) {
       return executeRequest((RequestWithPayload) httpRequest);
@@ -118,12 +118,13 @@ public class HttpConnector implements WsConnector {
     throw new IllegalArgumentException(format("Unsupported implementation: %s", httpRequest.getClass()));
   }
 
-  private WsResponse get(GetRequest getRequest) {
-    HttpUrl.Builder urlBuilder = prepareUrlBuilder(getRequest);
-    completeUrlQueryParameters(getRequest, urlBuilder);
+  private WsResponse executeRequest(RequestWithoutPayload<?> request) {
+    HttpUrl.Builder urlBuilder = prepareUrlBuilder(request);
+    completeUrlQueryParameters(request, urlBuilder);
 
-    Request.Builder okRequestBuilder = prepareOkRequestBuilder(getRequest, urlBuilder).get();
-    return new OkHttpResponse(doCall(prepareOkHttpClient(okHttpClient, getRequest), okRequestBuilder.build()));
+    Request.Builder okRequestBuilder = prepareOkRequestBuilder(request, urlBuilder);
+    okRequestBuilder = request.addVerbToBuilder().apply(okRequestBuilder);
+    return new OkHttpResponse(doCall(prepareOkHttpClient(okHttpClient, request), okRequestBuilder.build()));
   }
 
   private WsResponse executeRequest(RequestWithPayload<?> request) {
diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/RequestWithoutPayload.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/RequestWithoutPayload.java
new file mode 100644 (file)
index 0000000..d3ea011
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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 org.sonarqube.ws.client;
+
+import java.util.function.Function;
+import okhttp3.Request;
+
+/**
+ * @since 5.3
+ */
+public abstract class RequestWithoutPayload<T extends BaseRequest<RequestWithoutPayload<T>>> extends BaseRequest<RequestWithoutPayload<T>> {
+
+  protected RequestWithoutPayload(String path) {
+    super(path);
+  }
+
+  abstract Function<Request.Builder, Request.Builder> addVerbToBuilder();
+
+}
index c27274af5b25aa7f477945237bd03aee75f34136..2d4ab6d8438e01a75f0fc6f362d656ab4eb9c775 100644 (file)
@@ -51,6 +51,6 @@ public interface WsRequest {
   Headers getHeaders();
 
   enum Method {
-    GET, POST, PATCH
+    GET, POST, PATCH, DELETE
   }
 }
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/DeleteRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/DeleteRequestTest.java
new file mode 100644 (file)
index 0000000..24b3986
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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 org.sonarqube.ws.client;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DeleteRequestTest {
+
+  private DeleteRequest deleteRequest = new DeleteRequest("path");
+
+  @Test
+  public void getMethod_shouldReturnDelete() {
+    assertThat(deleteRequest.getMethod()).isEqualTo(WsRequest.Method.DELETE);
+  }
+
+
+  @Test
+  public void addVerbToBuilder_shouldReturnNonNullResult() {
+    assertThat(deleteRequest.addVerbToBuilder()).isNotNull();
+  }
+}
diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/GetRequestTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/GetRequestTest.java
new file mode 100644 (file)
index 0000000..2f5c660
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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 org.sonarqube.ws.client;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class GetRequestTest {
+
+  private GetRequest getRequest = new GetRequest("path");
+
+  @Test
+  public void getMethod_shouldReturnGet() {
+    assertThat(getRequest.getMethod()).isEqualTo(WsRequest.Method.GET);
+  }
+
+  @Test
+  public void addVerbToBuilder_shouldReturnNonNullResult() {
+    assertThat(getRequest.addVerbToBuilder()).isNotNull();
+  }
+
+}
index 6898c537894cb7a7d216b7dd316c7ed3afc8fc60..bb6d9040f26b96b87be116c73ec5d58a387e1feb 100644 (file)
@@ -140,10 +140,10 @@ public class ServiceTester<T extends BaseService> extends ExternalResource {
   @CheckForNull
   public GetRequest getGetRequest() {
     assertSingleGetCall();
-    return getCalls.iterator().next().getRequest();
+    return (GetRequest) getCalls.iterator().next().getRequest();
   }
 
-  public RequestAssert<GetRequest> assertThat(GetRequest getRequest) {
+  public RequestAssert<?> assertThat(GetRequest getRequest) {
     return new RequestAssert<>(getRequest);
   }
 
@@ -189,7 +189,7 @@ public class ServiceTester<T extends BaseService> extends ExternalResource {
   }
 
   @Immutable
-  public static final class GetCall extends CallWithParser<GetRequest> {
+  public static final class GetCall extends CallWithParser<RequestWithoutPayload<GetRequest>> {
 
     public GetCall(GetRequest getRequest, @Nullable Parser<?> parser) {
       super(getRequest, parser);