Browse Source

RPC: don't cap page size in unsafe mode (#6329)

pull/6344/head
gotjoshua 4 years ago
committed by GitHub
parent
commit
f563bd4ff1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 9 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +3
    -1
      rpc/core/env.go
  3. +14
    -8
      rpc/core/env_test.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -52,6 +52,7 @@ Friendly reminder: We have a [bug bounty program](https://hackerone.com/tendermi
### FEATURES ### FEATURES
- [config] Add `--mode` flag and config variable. See [ADR-52](https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-052-tendermint-mode.md) @dongsam - [config] Add `--mode` flag and config variable. See [ADR-52](https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-052-tendermint-mode.md) @dongsam
- [rpc] /#6329 Don't cap page size in unsafe mode (@gotjoshua, @cmwaters)
### IMPROVEMENTS ### IMPROVEMENTS


+ 3
- 1
rpc/core/env.go View File

@ -126,7 +126,9 @@ func validatePerPage(perPagePtr *int) int {
perPage := *perPagePtr perPage := *perPagePtr
if perPage < 1 { if perPage < 1 {
return defaultPerPage return defaultPerPage
} else if perPage > maxPerPage {
// in unsafe mode there is no max on the page size but in safe mode
// we cap it to maxPerPage
} else if perPage > maxPerPage && !env.Config.Unsafe {
return maxPerPage return maxPerPage
} }
return perPage return perPage


+ 14
- 8
rpc/core/env_test.go View File

@ -58,17 +58,16 @@ func TestPaginationPage(t *testing.T) {
func TestPaginationPerPage(t *testing.T) { func TestPaginationPerPage(t *testing.T) {
cases := []struct { cases := []struct {
totalCount int
perPage int perPage int
newPerPage int newPerPage int
}{ }{
{5, 0, defaultPerPage},
{5, 1, 1},
{5, 2, 2},
{5, defaultPerPage, defaultPerPage},
{5, maxPerPage - 1, maxPerPage - 1},
{5, maxPerPage, maxPerPage},
{5, maxPerPage + 1, maxPerPage},
{0, defaultPerPage},
{1, 1},
{2, 2},
{defaultPerPage, defaultPerPage},
{maxPerPage - 1, maxPerPage - 1},
{maxPerPage, maxPerPage},
{maxPerPage + 1, maxPerPage},
} }
for _, c := range cases { for _, c := range cases {
@ -79,4 +78,11 @@ func TestPaginationPerPage(t *testing.T) {
// nil case // nil case
p := validatePerPage(nil) p := validatePerPage(nil)
assert.Equal(t, defaultPerPage, p) assert.Equal(t, defaultPerPage, p)
// test in unsafe mode
env.Config.Unsafe = true
perPage := 1000
p = validatePerPage(&perPage)
assert.Equal(t, perPage, p)
env.Config.Unsafe = false
} }

Loading…
Cancel
Save