Skip to content

Commit

Permalink
Add maxItems:10 for SearchLogQuery
Browse files Browse the repository at this point in the history
Signed-off-by: Priya Wadhwa <priya@chainguard.dev>
  • Loading branch information
priyawadhwa committed Aug 29, 2022
1 parent 36dfbda commit b02320a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
7 changes: 5 additions & 2 deletions openapi.yaml
Expand Up @@ -519,21 +519,24 @@ definitions:
properties:
entryUUIDs:
type: array
minItems: 1
maxItems: 10
items:
type: string
minItems: 1
pattern: '^([0-9a-fA-F]{64}|[0-9a-fA-F]{80})$'
logIndexes:
type: array
minItems: 1
maxItems: 10
items:
type: integer
minimum: 0
entries:
type: array
minItems: 1
maxItems: 10
items:
$ref: '#/definitions/ProposedEntry'
minItems: 1

LogInfo:
type: object
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/entries.go
Expand Up @@ -322,7 +322,7 @@ func SearchLogQueryHandler(params entries.SearchLogQueryParams) middleware.Respo

totalQueries := len(params.Entry.EntryUUIDs) + len(params.Entry.Entries()) + len(params.Entry.LogIndexes)
if totalQueries > maxSearchQueries {
return handleRekorAPIError(params, http.StatusBadRequest, fmt.Errorf(maxSearchQueryLimit, maxSearchQueries), maxSearchQueryLimit, maxSearchQueries)
return handleRekorAPIError(params, http.StatusUnprocessableEntity, fmt.Errorf(maxSearchQueryLimit, maxSearchQueries), fmt.Sprintf(maxSearchQueryLimit, maxSearchQueries))
}

if len(params.Entry.EntryUUIDs) > 0 || len(params.Entry.Entries()) > 0 {
Expand Down
27 changes: 27 additions & 0 deletions pkg/generated/models/search_log_query.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions pkg/generated/restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/e2e_test.go
Expand Up @@ -954,10 +954,10 @@ func TestSearchQueryLimit(t *testing.T) {
if resp.StatusCode != 200 && !test.shouldErr {
t.Fatalf("expected test to pass but it failed")
}
if resp.StatusCode != 400 && test.shouldErr {
if resp.StatusCode != 422 && test.shouldErr {
t.Fatal("expected test to fail but it passed")
}
if test.shouldErr && !strings.Contains(string(c), "more than max allowed") {
if test.shouldErr && !strings.Contains(string(c), "logIndexes in body should have at most 10 items") {
t.Fatal("expected max limit error but didn't get it")
}
})
Expand Down

0 comments on commit b02320a

Please sign in to comment.