Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- A `DELETE` of a missing software answered `404` but still recorded a
delete event and notified the webhooks.
- The event recorded by an analysis `PATCH` had no actor.
- `?from` and `?to` refused RFC 3339 values with a zone offset.
- Catalogs, bundles and webhooks wrote no event to the audit trail.
- A webhook `POST` with the url of an existing one answered `500` instead
of `409`.
Expand Down
4 changes: 2 additions & 2 deletions internal/handlers/general/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func Clauses(ctx *fiber.Ctx, stmt *gorm.DB, filterField, searchField string) (*g
}

if from := ctx.Query("from", ""); from != "" {
at, err := time.Parse("2006-01-02T15:04:05Z", from)
at, err := time.Parse(time.RFC3339, from)
if err != nil {
return nil, common.ErrInvalidDateTime
}
Expand All @@ -58,7 +58,7 @@ func Clauses(ctx *fiber.Ctx, stmt *gorm.DB, filterField, searchField string) (*g
}

if to := ctx.Query("to", ""); to != "" {
at, err := time.Parse("2006-01-02T15:04:05Z", to)
at, err := time.Parse(time.RFC3339, to)
if err != nil {
return nil, common.ErrInvalidDateTime
}
Expand Down
36 changes: 36 additions & 0 deletions logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,30 @@ func TestLogsEndpoints(t *testing.T) {
assert.Equal(t, 20, len(data))
},
},
{
description: `GET with "from" query param carrying a zone offset`,
query: "GET /v1/logs?from=2010-03-01T11:56:23%2B02:00",

expectedCode: 200,
expectedContentType: "application/json",
validateFunc: func(t *testing.T, response map[string]any) {
data := assertListResponse(t, response)

assert.Equal(t, 20, len(data))
},
},
{
description: `GET with "from" query param carrying fractional seconds`,
query: "GET /v1/logs?from=2010-03-01T09:56:23.000000Z",

expectedCode: 200,
expectedContentType: "application/json",
validateFunc: func(t *testing.T, response map[string]any) {
data := assertListResponse(t, response)

assert.Equal(t, 20, len(data))
},
},
{
description: `GET with invalid "from" query param`,
query: "GET /v1/logs?from=3",
Expand All @@ -200,6 +224,18 @@ func TestLogsEndpoints(t *testing.T) {
assert.Equal(t, 6, len(data))
},
},
{
description: `GET with "to" query param carrying a zone offset`,
query: "GET /v1/logs?to=2010-03-01T11:56:23%2B02:00",

expectedCode: 200,
expectedContentType: "application/json",
validateFunc: func(t *testing.T, response map[string]any) {
data := response["data"].([]any)

assert.Equal(t, 6, len(data))
},
},
{
description: `GET with invalid "to" query param`,
query: "GET /v1/logs?to=3",
Expand Down
Loading