Skip to content

Commit

Permalink
Assert response is forwarded
Browse files Browse the repository at this point in the history
  • Loading branch information
nquinquenel committed Jan 28, 2025
1 parent ce35b1e commit 87f6e97
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
import java.net.URI;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.List;
import org.eclipse.jetty.http.HttpStatus;
import org.sonarsource.sonarlint.core.test.utils.junit5.SonarLintTest;
import org.sonarsource.sonarlint.core.test.utils.junit5.SonarLintTestHarness;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.mockito.Mockito.when;

class EmbeddedServerMediumTests {
Expand Down Expand Up @@ -179,4 +181,23 @@ void it_should_not_allow_request_if_origin_is_missing(SonarLintTestHarness harne
.containsExactly(HttpStatus.BAD_REQUEST_400, "");
}

@SonarLintTest
void it_should_not_rate_limit_over_time(SonarLintTestHarness harness) throws IOException, InterruptedException {
var fakeClient = harness.newFakeClient().build();
var backend = harness.newBackend().withEmbeddedServer().withClientName("ClientName").start(fakeClient);

var embeddedServerPort = backend.getEmbeddedServerPort();
var request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:" + embeddedServerPort + "/sonarlint/api/status"))
.header("Origin", "https://sonar")
.GET().build();
for (int i = 0; i < 10; i++) {
java.net.http.HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
}
await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> {
var response = java.net.http.HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK_200);
});
}

}

0 comments on commit 87f6e97

Please sign in to comment.