diff --git a/internal/pkg/api/handleCheckin_test.go b/internal/pkg/api/handleCheckin_test.go index f39926eaf..cc5652f2d 100644 --- a/internal/pkg/api/handleCheckin_test.go +++ b/internal/pkg/api/handleCheckin_test.go @@ -973,6 +973,23 @@ func TestValidateCheckinRequest(t *testing.T) { }, expValid: validatedCheckin{}, }, + { + name: "local metadata has fips attribute", + req: &http.Request{ + Body: io.NopCloser(strings.NewReader(`{"status": "online", "message": "test message", "local_metadata": {"elastic": {"agent": {"id": "testid", "fips": true}}}}`)), + }, + expErr: nil, + cfg: &config.Server{ + Limits: config.ServerLimits{ + CheckinLimit: config.Limit{ + MaxBody: 0, + }, + }, + }, + expValid: validatedCheckin{ + rawMeta: []byte(`{"elastic": {"agent": {"id": "testid", "fips": true}}}`), + }, + }, } for _, tc := range tests { @@ -981,9 +998,10 @@ func TestValidateCheckinRequest(t *testing.T) { assert.NoError(t, err) wr := httptest.NewRecorder() logger := testlog.SetLogger(t) - valid, err := checkin.validateRequest(logger, wr, tc.req, time.Time{}, nil) + valid, err := checkin.validateRequest(logger, wr, tc.req, time.Time{}, &model.Agent{LocalMetadata: json.RawMessage(`{}`)}) if tc.expErr == nil { assert.NoError(t, err) + assert.Equal(t, tc.expValid.rawMeta, valid.rawMeta) } else { // Asserting error messages prior to ErrorAs becuase ErrorAs modifies // the target error. If we assert error messages after calling ErrorAs @@ -991,7 +1009,6 @@ func TestValidateCheckinRequest(t *testing.T) { assert.Equal(t, tc.expErr.Error(), err.Error()) assert.ErrorAs(t, err, &tc.expErr) } - assert.Equal(t, tc.expValid, valid) }) } } diff --git a/internal/pkg/api/handleEnroll_test.go b/internal/pkg/api/handleEnroll_test.go index d5075b37a..498902699 100644 --- a/internal/pkg/api/handleEnroll_test.go +++ b/internal/pkg/api/handleEnroll_test.go @@ -15,6 +15,10 @@ import ( "strings" "testing" + "github.com/rs/zerolog" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/elastic/fleet-server/v7/internal/pkg/apikey" "github.com/elastic/fleet-server/v7/internal/pkg/bulk" "github.com/elastic/fleet-server/v7/internal/pkg/cache" @@ -24,9 +28,6 @@ import ( "github.com/elastic/fleet-server/v7/internal/pkg/model" "github.com/elastic/fleet-server/v7/internal/pkg/rollback" ftesting "github.com/elastic/fleet-server/v7/internal/pkg/testing" - "github.com/rs/zerolog" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" ) func TestRemoveDuplicateStr(t *testing.T) { @@ -569,7 +570,15 @@ func TestEnrollerT_retrieveStaticTokenEnrollmentToken(t *testing.T) { } func TestValidateEnrollRequest(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.Nil(t, req) + 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.Nil(t, req) + }) + t.Run("fips attribute in local metadata", func(t *testing.T) { + req, err := validateRequest(context.Background(), strings.NewReader(`{"type": "PERMANENT", "metadata": {"local": {"elastic": {"agent": {"fips": true, "snapshot": false}}}}}`)) + assert.NoError(t, err) + assert.Equal(t, PERMANENT, req.Type) + assert.Equal(t, json.RawMessage(`{"elastic": {"agent": {"fips": true, "snapshot": false}}}`), req.Metadata.Local) + }) } diff --git a/internal/pkg/checkin/bulk_test.go b/internal/pkg/checkin/bulk_test.go index 8597c2306..1772f5eef 100644 --- a/internal/pkg/checkin/bulk_test.go +++ b/internal/pkg/checkin/bulk_test.go @@ -107,6 +107,17 @@ func TestBulkSimple(t *testing.T) { "", nil, }, + { + "has meta with fips attribute", + "metaCaseID", + "online", + "message", + []byte(`{"fips":true,"snapshot":false}`), + nil, + nil, + "", + nil, + }, { "Singled field case", "singleFieldId",