Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): Remove mockserver dependency #1022

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,5 @@
<version>3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-junit-rule-no-dependencies</artifactId>
<version>5.14.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockserver.model.Header.header;
import static org.mockserver.model.HttpForward.forward;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;

import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequestFactory;
Expand Down Expand Up @@ -59,10 +55,6 @@
import org.junit.BeforeClass;
import org.junit.Test;

import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.HttpForward.Scheme;
import org.mockserver.socket.PortFactory;

public class ApacheHttp2TransportIT {
private static FirebaseApp app;
private static final GoogleCredentials MOCK_CREDENTIALS = new MockGoogleCredentials("test_token");
Expand All @@ -79,9 +71,6 @@ public class ApacheHttp2TransportIT {
private static Socket fillerSocket;
private static int port;

private static ClientAndServer mockProxy;
private static ClientAndServer mockServer;

@BeforeClass
public static void setUpClass() throws IOException {
// Start server socket with a backlog queue of 1 and a automatically assigned
Expand Down Expand Up @@ -109,14 +98,6 @@ public void cleanup() {
app.delete();
}

if (mockProxy != null && mockProxy.isRunning()) {
mockProxy.close();
}

if (mockServer != null && mockServer.isRunning()) {
mockServer.close();
}

System.clearProperty("http.proxyHost");
System.clearProperty("http.proxyPort");
System.clearProperty("https.proxyHost");
Expand Down Expand Up @@ -311,62 +292,6 @@ public void testVerifyProxyIsRespected() {
}
}

@Test(timeout = 10_000L)
public void testProxyMockHttp() throws Exception {
// Start MockServer
mockProxy = ClientAndServer.startClientAndServer(PortFactory.findFreePort());
mockServer = ClientAndServer.startClientAndServer(PortFactory.findFreePort());

System.setProperty("http.proxyHost", "localhost");
System.setProperty("http.proxyPort", mockProxy.getPort().toString());

// Configure proxy to receieve requests and forward them to a mock destination
// server
mockProxy
.when(
request())
.forward(
forward()
.withHost("localhost")
.withPort(mockServer.getPort())
.withScheme(Scheme.HTTP));

// Configure server to listen and respond
mockServer
.when(
request())
.respond(
response()
.withStatusCode(200)
.withBody("Expected server response"));

// Send a request through the proxy
app = FirebaseApp.initializeApp(FirebaseOptions.builder()
.setCredentials(MOCK_CREDENTIALS)
.setWriteTimeout(100)
.build(), "test-app");
ErrorHandlingHttpClient<FirebaseException> httpClient = getHttpClient(true, app);
HttpRequestInfo request = HttpRequestInfo.buildGetRequest("http://www.google.com");
IncomingHttpResponse response = httpClient.send(request);

// Verify that the proxy received request with destination host
mockProxy.verify(
request()
.withMethod("GET")
.withPath("/")
.withHeader(header("Host", "www.google.com")));

// Verify the forwarded request is received by the server
mockServer.verify(
request()
.withMethod("GET")
.withPath("/"));

// Verify response
assertEquals(200, response.getStatusCode());
assertEquals(response.getContent(), "Expected server response");
}

private static ErrorHandlingHttpClient<FirebaseException> getHttpClient(boolean authorized,
FirebaseApp app) {
HttpRequestFactory requestFactory;
Expand Down