-
Notifications
You must be signed in to change notification settings - Fork 340
Use HTTP status code 413 for exceedingly large payloads #631
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,6 @@ | |
| package org.apache.polaris.service.dropwizard; | ||
|
|
||
| import static org.apache.polaris.service.context.DefaultRealmContextResolver.REALM_PROPERTY_KEY; | ||
| import static org.apache.polaris.service.dropwizard.throttling.RequestThrottlingErrorResponse.RequestThrottlingErrorType.REQUEST_TOO_LARGE; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
|
|
@@ -87,7 +86,6 @@ | |
| import org.apache.polaris.service.dropwizard.test.PolarisRealm; | ||
| import org.apache.polaris.service.dropwizard.test.SnowmanCredentialsExtension; | ||
| import org.apache.polaris.service.dropwizard.test.TestEnvironmentExtension; | ||
| import org.apache.polaris.service.dropwizard.throttling.RequestThrottlingErrorResponse; | ||
| import org.assertj.core.api.Assertions; | ||
| import org.assertj.core.api.InstanceOfAssertFactories; | ||
| import org.junit.jupiter.api.AfterAll; | ||
|
|
@@ -712,7 +710,10 @@ public void testRequestHeaderTooLarge() { | |
|
|
||
| @Test | ||
| public void testRequestBodyTooLarge() { | ||
| // The size is set to be higher than the limit in polaris-server-integrationtest.yml | ||
| // The behaviour in case of large requests depends on the specific server configuration. | ||
| // This test assumes that the server under test is configured to deny requests larger than | ||
| // 1000000 bytes. The test payload below assumes UTF8 encoding of ASCII charts plus a bit of | ||
| // JSON overhead. | ||
| Entity<PrincipalRole> largeRequest = Entity.json(new PrincipalRole("r".repeat(1000001))); | ||
|
|
||
| try (Response response = | ||
|
|
@@ -724,13 +725,16 @@ public void testRequestBodyTooLarge() { | |
| .header("Authorization", "Bearer " + userToken) | ||
| .header(REALM_PROPERTY_KEY, realm) | ||
| .post(largeRequest)) { | ||
| assertThat(response) | ||
| .returns(Response.Status.BAD_REQUEST.getStatusCode(), Response::getStatus) | ||
| .matches( | ||
| r -> | ||
| r.readEntity(RequestThrottlingErrorResponse.class) | ||
| .errorType() | ||
| .equals(REQUEST_TOO_LARGE)); | ||
| // Note we only validate the status code here because per RFC 9110, the server MAY not provide | ||
| // a response body. The HTTP status line is still expected to be provided. | ||
| assertThat(response.getStatus()) | ||
| .isEqualTo(Response.Status.REQUEST_ENTITY_TOO_LARGE.getStatusCode()); | ||
| } catch (ProcessingException e) { | ||
| // Per RFC 9110 servers MAY close the connection in case of 413 responses, which | ||
| // might cause the client to fail to read the status code (cf. RFC 9112, section 9.6). | ||
| // TODO: servers are expected to close connections gracefully. It might be worth investigating | ||
| // whether "connection closed" exceptions are a client-side bug. | ||
| assertThat(e).hasMessageContaining("Connection was closed"); | ||
|
Comment on lines
+733
to
+737
Contributor
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. This catch makes sense to me. It might be worth filing an issue to see if we can reproduce the disconnect elsewhere |
||
| } | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We don't need to do this here, but I wonder if we could somehow add a check for the limit to this test.