Skip to content

Commit 8ac12db

Browse files
Stricter validation for required checkin API attributes (elastic#3233)
* Stricter validation for required checkin API attributes * log warning on empty message
1 parent fdeb805 commit 8ac12db

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: bug-fix
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Stricter validation for required checkin API attributes
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
#description:
20+
21+
# Affected component; a word indicating the component this changeset affects.
22+
component:
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
#pr: https://github.com/owner/repo/1234
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
issue: 2420

Diff for: internal/pkg/api/handleCheckin.go

+7
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ func (ct *CheckinT) validateRequest(zlog zerolog.Logger, w http.ResponseWriter,
181181
}
182182
cntCheckin.bodyIn.Add(readCounter.Count())
183183

184+
if req.Status == CheckinRequestStatus("") {
185+
return val, fmt.Errorf("checkin status missing")
186+
}
187+
if len(req.Message) == 0 {
188+
zlog.Warn().Msg("checkin request method is empty.")
189+
}
190+
184191
var pDur time.Duration
185192
var err error
186193
if req.PollTimeout != nil {

Diff for: internal/pkg/server/fleet_integration_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const (
6161
}`
6262
checkinBody = `{
6363
"status": "online",
64-
"message": ""
64+
"message": "checkin ok"
6565
}`
6666
)
6767

@@ -1131,7 +1131,7 @@ func Test_SmokeTest_CheckinPollTimeout(t *testing.T) {
11311131
req, err = http.NewRequestWithContext(ctx, "POST", srv.baseURL()+"/api/fleet/agents/"+agentID+"/checkin", strings.NewReader(fmt.Sprintf(`{
11321132
"ack_token": "%s",
11331133
"status": "online",
1134-
"message": "",
1134+
"message": "checkin ok",
11351135
"poll_timeout": "3m"
11361136
}`, *checkinResponse.AckToken)))
11371137
require.NoError(t, err)
@@ -1159,7 +1159,7 @@ func Test_SmokeTest_CheckinPollTimeout(t *testing.T) {
11591159
req, err = http.NewRequestWithContext(ctx, "POST", srv.baseURL()+"/api/fleet/agents/"+agentID+"/checkin", strings.NewReader(fmt.Sprintf(`{
11601160
"ack_token": "%s",
11611161
"status": "online",
1162-
"message": "",
1162+
"message": "checkin ok",
11631163
"poll_timeout": "10m"
11641164
}`, *checkinResponse.AckToken)))
11651165
require.NoError(t, err)
@@ -1262,7 +1262,7 @@ func Test_SmokeTest_CheckinPollShutdown(t *testing.T) {
12621262
req, err = http.NewRequest("POST", srv.baseURL()+"/api/fleet/agents/"+agentID+"/checkin", strings.NewReader(fmt.Sprintf(`{
12631263
"ack_token": "%s",
12641264
"status": "online",
1265-
"message": "",
1265+
"message": "checkin ok",
12661266
"poll_timeout": "3m"
12671267
}`, *checkinResponse.AckToken)))
12681268
require.NoError(t, err)

Diff for: testing/e2e/api_version/client_api_2023_06_01.go

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ func (tester *ClientAPITester20230601) Checkin(ctx context.Context, apiKey, agen
124124
&api.AgentCheckinParams{UserAgent: "elastic agent " + version.DefaultVersion},
125125
api.AgentCheckinJSONRequestBody{
126126
Status: api.CheckinRequestStatusOnline,
127+
Message: "test checkin",
127128
AckToken: ackToken,
128129
PollTimeout: dur,
129130
},

Diff for: testing/e2e/api_version/client_api_current.go

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func (tester *ClientAPITester) Checkin(ctx context.Context, apiKey, agentID stri
110110
&api.AgentCheckinParams{UserAgent: "elastic agent " + version.DefaultVersion},
111111
api.AgentCheckinJSONRequestBody{
112112
Status: api.CheckinRequestStatusOnline,
113+
Message: "test checkin",
113114
AckToken: ackToken,
114115
PollTimeout: dur,
115116
},

0 commit comments

Comments
 (0)