-
Notifications
You must be signed in to change notification settings - Fork 12
Bind testing server to 0.0.0.0 #172
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,16 @@ | |
import io.trino.aws.proxy.server.remote.PathStyleRemoteS3Facade; | ||
import io.trino.aws.proxy.server.testing.TestingRemoteS3Facade; | ||
import io.trino.aws.proxy.server.testing.TestingTrinoAwsProxyServer.Builder; | ||
import io.trino.aws.proxy.server.testing.TestingUtil.ForTesting; | ||
import io.trino.aws.proxy.server.testing.harness.BuilderFilter; | ||
import io.trino.aws.proxy.server.testing.harness.TrinoAwsProxyTest; | ||
import io.trino.aws.proxy.spi.credentials.Credentials; | ||
import jakarta.servlet.http.HttpServlet; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
import software.amazon.awssdk.services.s3.model.S3Exception; | ||
|
||
|
@@ -39,13 +43,13 @@ | |
import java.util.Optional; | ||
|
||
import static com.google.common.collect.ImmutableMap.toImmutableMap; | ||
import static io.trino.aws.proxy.server.testing.TestingUtil.clientBuilder; | ||
import static io.trino.aws.proxy.server.testing.TestingUtil.createTestingHttpServer; | ||
import static io.trino.aws.proxy.server.testing.TestingUtil.getFileFromStorage; | ||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
import static java.util.Objects.requireNonNull; | ||
import static java.util.function.Function.identity; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
|
@@ -95,12 +99,21 @@ public Builder filter(Builder builder) | |
} | ||
|
||
@Inject | ||
public TestProxiedErrorResponses(S3Client internalClient, TestingRemoteS3Facade delegatingFacade, @ForErrorResponseTest TestingHttpServer httpErrorResponseServer) | ||
public TestProxiedErrorResponses(TestingRemoteS3Facade delegatingFacade, @ForErrorResponseTest TestingHttpServer httpErrorResponseServer, @ForTesting Credentials testingCredentials) | ||
{ | ||
this.internalClient = requireNonNull(internalClient, "internal client is null"); | ||
internalClient = clientBuilder(httpErrorResponseServer.getBaseUrl()) | ||
.forcePathStyle(true) | ||
.credentialsProvider(() -> AwsSessionCredentials.create(testingCredentials.emulated().accessKey(), testingCredentials.emulated().secretKey(), testingCredentials.emulated().session().orElse(""))) | ||
.build(); | ||
delegatingFacade.setDelegate(new PathStyleRemoteS3Facade((_, _) -> httpErrorResponseServer.getBaseUrl().getHost(), false, Optional.of(httpErrorResponseServer.getBaseUrl().getPort()))); | ||
} | ||
|
||
@AfterEach | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the constructor invoked once per test? It's not obvious from the test whether it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... if its |
||
public void shutdown() | ||
{ | ||
internalClient.close(); | ||
} | ||
|
||
@Test | ||
public void test() | ||
{ | ||
|
@@ -121,13 +134,13 @@ private static class HttpErrorResponseServlet | |
extends HttpServlet | ||
{ | ||
private static final String RESPONSE_TEMPLATE = """ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Error> | ||
<Code>%s</Code> | ||
<Message>Error Message</Message> | ||
<Resource>%s</Resource> | ||
<RequestId>123</RequestId> | ||
</Error>"""; | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Error> | ||
<Code>%s</Code> | ||
<Message>Error Message</Message> | ||
<Resource>%s</Resource> | ||
<RequestId>123</RequestId> | ||
</Error>"""; | ||
|
||
private static final Map<String, HttpStatus> PATH_STATUS_CODE_MAPPING = STATUS_CODES.stream().collect(toImmutableMap(status -> "/status/%d".formatted(status.code()), identity())); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this state, this doesn't test anything, right?
The point was to test that aws-proxy propagates errors from the remote S3 correctly.
What this is doing currently is bypassing the aws-proxy and calling
httpErrorResponseServer
with an S3 clientThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Derp - I messed it up I think. Feel free to submit a fixup PR. I probably didn't understand the test.