-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't send POLICY_CHANGE actions retrieved from index to agent. (#1963)
* Don't send POLICY_CHANGE actions retrieved from index to agent. The fleet-server should not send any policy change actions that are written to the actions index to an agent on checkin. The server will remove these actions in the convert method and emit a warning message. The ack token that is used is not altered in this case. Policy change actions are dynamically generated by the fleet-server when it detects that the agent is not running an up to date version of the policy. * move filtering to its own method * Fix linter, tests, fix file name (cherry picked from commit b51bf97) # Conflicts: # CHANGELOG.next.asciidoc
- Loading branch information
1 parent
24f5a29
commit 1562a94
Showing
4 changed files
with
126 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
//go:build !integration | ||
// +build !integration | ||
|
||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/elastic/fleet-server/v7/internal/pkg/model" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConvertActions(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
actions []model.Action | ||
resp []ActionResp | ||
token string | ||
}{{ | ||
name: "empty actions", | ||
actions: nil, | ||
resp: []ActionResp{}, | ||
token: "", | ||
}, { | ||
name: "single action", | ||
actions: []model.Action{{ActionID: "1234"}}, | ||
resp: []ActionResp{{ | ||
AgentID: "agent-id", | ||
ID: "1234", | ||
Data: json.RawMessage(nil), | ||
}}, | ||
token: "", | ||
}, { | ||
name: "multiple actions", | ||
actions: []model.Action{ | ||
{ActionID: "1234"}, | ||
{ActionID: "5678"}, | ||
}, | ||
resp: []ActionResp{{ | ||
AgentID: "agent-id", | ||
ID: "1234", | ||
Data: json.RawMessage(nil), | ||
}, { | ||
AgentID: "agent-id", | ||
ID: "5678", | ||
Data: json.RawMessage(nil), | ||
}}, | ||
token: "", | ||
}} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
resp, token := convertActions("agent-id", tc.actions) | ||
assert.Equal(t, tc.resp, resp) | ||
assert.Equal(t, tc.token, token) | ||
}) | ||
} | ||
} | ||
|
||
func TestFilterActions(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
actions []model.Action | ||
resp []model.Action | ||
}{{ | ||
name: "empty list", | ||
actions: []model.Action{}, | ||
resp: []model.Action{}, | ||
}, { | ||
name: "nothing filtered", | ||
actions: []model.Action{{ | ||
ActionID: "1234", | ||
}, { | ||
ActionID: "5678", | ||
}}, | ||
resp: []model.Action{{ | ||
ActionID: "1234", | ||
}, { | ||
ActionID: "5678", | ||
}}, | ||
}, { | ||
name: "filter POLICY_CHANGE action", | ||
actions: []model.Action{{ | ||
ActionID: "1234", | ||
Type: TypePolicyChange, | ||
}, { | ||
ActionID: "5678", | ||
}}, | ||
resp: []model.Action{{ | ||
ActionID: "5678", | ||
}}, | ||
}} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
resp := filterActions("agent-id", tc.actions) | ||
assert.Equal(t, tc.resp, resp) | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.