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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: bug-fix

# Change summary; a 80ish characters long description of the change.
summary: Include the base error for json decode error responses

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
#description:

# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
component: fleet-server

# PR URL; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
pr: https://github.com/elastic/fleet-server/pull/5069

# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
#issue: https://github.com/owner/repo/1234
6 changes: 5 additions & 1 deletion internal/pkg/api/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ type BadRequestErr struct {
}

func (e *BadRequestErr) Error() string {
return fmt.Sprintf("Bad request: %s", e.msg)
s := fmt.Sprintf("Bad request: %s", e.msg)
if e.nextErr != nil {
s += ": " + e.nextErr.Error()
}
return s
}

func (e *BadRequestErr) Unwrap() error {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/api/handleAck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ func TestValidateAckRequest(t *testing.T) {
cfg: &config.Server{
Limits: config.ServerLimits{},
},
expErr: &BadRequestErr{msg: "unable to decode ack request"},
expErr: &BadRequestErr{msg: "unable to decode ack request", nextErr: errors.New("invalid character 'o' in literal null (expecting 'u')")},
expAck: nil,
},
}
Expand Down
10 changes: 6 additions & 4 deletions internal/pkg/api/handleAudit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@

import (
"context"
"errors"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"

"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/elastic/fleet-server/v7/internal/pkg/config"
"github.com/elastic/fleet-server/v7/internal/pkg/dl"
"github.com/elastic/fleet-server/v7/internal/pkg/model"
ftesting "github.com/elastic/fleet-server/v7/internal/pkg/testing"
testlog "github.com/elastic/fleet-server/v7/internal/pkg/testing/log"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

func Test_Audit_validateUnenrollRequst(t *testing.T) {
Expand Down Expand Up @@ -47,7 +49,7 @@
},
cfg: &config.Server{},
valid: nil,
err: &BadRequestErr{msg: "unable to decode audit/unenroll request"},
err: &BadRequestErr{msg: "unable to decode audit/unenroll request", nextErr: errors.New("invalid character '}' looking for beginning of value")},
}, {
name: "bad reason",
req: &http.Request{
Expand All @@ -69,7 +71,7 @@
},
},
valid: nil,
err: &BadRequestErr{msg: "unable to decode audit/unenroll request"},
err: &BadRequestErr{msg: "unable to decode audit/unenroll request", nextErr: errors.New("http: request body too large")},
}}

for _, tc := range tests {
Expand Down Expand Up @@ -98,7 +100,7 @@
bulker.On("Update", mock.Anything, dl.FleetAgents, agent.Id, mock.Anything, mock.Anything, mock.Anything).Return(nil)
audit := AuditT{bulk: bulker}
logger := testlog.SetLogger(t)
err := audit.markUnenroll(context.Background(), logger, &AuditUnenrollRequest{Reason: Uninstall, Timestamp: time.Now().UTC()}, agent)

Check failure on line 103 in internal/pkg/api/handleAudit_test.go

View workflow job for this annotation

GitHub Actions / lint (linux)

context.Background() could be replaced by t.Context() in Test_Audit_markUnenroll (usetesting)
require.NoError(t, err)
bulker.AssertExpectations(t)
}
Expand Down
5 changes: 3 additions & 2 deletions internal/pkg/api/handleCheckin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"compress/flate"
"context"
"encoding/json"
"errors"
"io"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -991,7 +992,7 @@ func TestValidateCheckinRequest(t *testing.T) {
req: &http.Request{
Body: io.NopCloser(strings.NewReader(`{"invalidJson":}`)),
},
expErr: &BadRequestErr{msg: "unable to decode checkin request"},
expErr: &BadRequestErr{msg: "unable to decode checkin request", nextErr: errors.New("invalid character '}' looking for beginning of value")},
cfg: &config.Server{
Limits: config.ServerLimits{
CheckinLimit: config.Limit{
Expand Down Expand Up @@ -1021,7 +1022,7 @@ func TestValidateCheckinRequest(t *testing.T) {
req: &http.Request{
Body: io.NopCloser(strings.NewReader(`{"validJson": "test", "status": "test", "poll_timeout": "not a timeout", "message": "test message"}`)),
},
expErr: &BadRequestErr{msg: "poll_timeout cannot be parsed as duration"},
expErr: &BadRequestErr{msg: "poll_timeout cannot be parsed as duration", nextErr: errors.New("time: invalid duration \"not a timeout\"")},
cfg: &config.Server{
Limits: config.ServerLimits{
CheckinLimit: config.Limit{
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/api/handleEnroll_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ func TestEnrollerT_retrieveStaticTokenEnrollmentToken(t *testing.T) {
func TestValidateEnrollRequest(t *testing.T) {
t.Run("invalid json", func(t *testing.T) {
req, err := validateRequest(context.Background(), strings.NewReader("not a json"))
assert.Equal(t, "Bad request: unable to decode enroll request", err.Error())
assert.Equal(t, "Bad request: unable to decode enroll request: invalid character 'o' in literal null (expecting 'u')", err.Error())
assert.Nil(t, req)
})
t.Run("fips attribute in local metadata", func(t *testing.T) {
Expand Down
Loading