Skip to content

Commit 06f8cdd

Browse files
committed
[#38] Fix validations
* Comparison needs to be made with correct size in case size is not specified (defaults to 10).
1 parent 6a139df commit 06f8cdd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

v2/grpc/validations.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ func validatePagination(page *api.Pagination) (from uint32, size uint32, err err
2222
if size > maxPageSize {
2323
return 0, 0, fmt.Errorf("size [%d] exceeds maximum [%d]", size, maxPageSize)
2424
}
25+
if size == 0 {
26+
size = defaultPageSize
27+
}
2528
if from+size > maxHitsSize {
2629
return 0, 0, fmt.Errorf("offset [%d] + size [%d] exceeds maximum [%d]", from, size, maxHitsSize)
2730
}
28-
return from, If(size > 0, size, defaultPageSize), nil
31+
return from, size, nil
2932
}
3033

3134
var allowedTermFilters = [4]string{"source", "destination", "amount", "inputType"}

v2/grpc/validations_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ func TestValidations_validatePagination_largetOffsetPlusPageSize(t *testing.T) {
4141
})
4242
require.NoError(t, err)
4343

44+
_, _, err = validatePagination(&api.Pagination{
45+
Offset: uint32Pointer(9999),
46+
Size: uint32Pointer(1),
47+
})
48+
require.NoError(t, err)
49+
50+
_, _, err = validatePagination(&api.Pagination{
51+
Offset: uint32Pointer(9999),
52+
Size: uint32Pointer(0), // defaults to 10
53+
})
54+
require.ErrorContains(t, err, "exceeds maximum [10000]")
55+
4456
_, _, err = validatePagination(&api.Pagination{
4557
Offset: uint32Pointer(9990),
4658
Size: uint32Pointer(11),

0 commit comments

Comments
 (0)