-
Notifications
You must be signed in to change notification settings - Fork 450
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
api: Limit request body size to 10MB #5246
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
82e0646
Add limit for request body size to 10MB and add tests
algochoi eb91eb5
Fix lint errors in exported constant comment
algochoi 0dd5216
Update test/scripts/e2e_subs/e2e-app-simulate.sh
algochoi 4ea8fdc
fix TEMPDIR
algochoi 0da0a6c
Merge branch 'master' into limit-api-body
algochoi File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 | ||
---|---|---|---|---|
|
@@ -25,6 +25,7 @@ import ( | |||
"io" | ||||
"net/http" | ||||
"net/http/httptest" | ||||
"strings" | ||||
"testing" | ||||
"time" | ||||
|
||||
|
@@ -1263,6 +1264,11 @@ func TestTealDisassemble(t *testing.T) { | |||
// Test bad program. | ||||
badProgram := []byte{1, 99} | ||||
tealDisassembleTest(t, badProgram, 400, "invalid opcode", true) | ||||
|
||||
// Create a program with MaxTealSourceBytes+1 bytes | ||||
// This should fail inside the handler when reading the bytes from the request body. | ||||
largeProgram := []byte(strings.Repeat("a", v2.MaxTealSourceBytes+1)) | ||||
tealDisassembleTest(t, largeProgram, 400, "http: request body too large", true) | ||||
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. These tests are affected by a smaller size limit (200KB instead of 10MB) defined by
|
||||
} | ||||
|
||||
func tealDryrunTest( | ||||
|
@@ -1309,6 +1315,12 @@ func tealDryrunTest( | |||
messages := *response.Txns[0].AppCallMessages | ||||
require.GreaterOrEqual(t, len(messages), 1) | ||||
require.Equal(t, expResult, messages[len(messages)-1]) | ||||
} else if rec.Code == 400 { | ||||
var response model.ErrorResponse | ||||
data := rec.Body.Bytes() | ||||
err = protocol.DecodeJSON(data, &response) | ||||
require.NoError(t, err, string(data)) | ||||
require.Contains(t, response.Message, expResult) | ||||
} | ||||
return | ||||
} | ||||
|
@@ -1374,7 +1386,7 @@ func TestTealDryrun(t *testing.T) { | |||
tealDryrunTest(t, &gdr, "msgp", 404, "", false) | ||||
|
||||
gdr.ProtocolVersion = "unk" | ||||
tealDryrunTest(t, &gdr, "json", 400, "", true) | ||||
tealDryrunTest(t, &gdr, "json", 400, "unsupported protocol version", true) | ||||
gdr.ProtocolVersion = "" | ||||
|
||||
ddr := tealDryrunTest(t, &gdr, "json", 200, "PASS", true) | ||||
|
@@ -1387,6 +1399,10 @@ func TestTealDryrun(t *testing.T) { | |||
tealDryrunTest(t, &gdr, "json", 200, "REJECT", true) | ||||
tealDryrunTest(t, &gdr, "msgp", 200, "REJECT", true) | ||||
tealDryrunTest(t, &gdr, "json", 404, "", false) | ||||
|
||||
// This should fail inside the handler when reading the bytes from the request body. | ||||
gdr.ProtocolVersion = strings.Repeat("a", v2.MaxTealDryrunBytes+1) | ||||
tealDryrunTest(t, &gdr, "json", 400, "http: request body too large", true) | ||||
} | ||||
|
||||
func TestAppendParticipationKeys(t *testing.T) { | ||||
|
This file contains 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
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.
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa