mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
Forward policy resolution (#2733)
* Pass through the resoution for the policy * Update tests
This commit is contained in:
parent
51e35e1ba0
commit
1aea7484d4
4 changed files with 8 additions and 4 deletions
|
|
@ -37,7 +37,7 @@ func (svc Service) NewGlobalPolicy(ctx context.Context, queryID uint, resolution
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return svc.ds.NewGlobalPolicy(ctx, queryID, "")
|
||||
return svc.ds.NewGlobalPolicy(ctx, queryID, resolution)
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -364,11 +364,13 @@ func (s *integrationTestSuite) TestGlobalPolicies() {
|
|||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
gpParams := globalPolicyRequest{QueryID: qr.ID}
|
||||
gpParams := globalPolicyRequest{QueryID: qr.ID, Resolution: "some global resolution"}
|
||||
gpResp := globalPolicyResponse{}
|
||||
s.DoJSON("POST", "/api/v1/fleet/global/policies", gpParams, http.StatusOK, &gpResp)
|
||||
require.NotNil(t, gpResp.Policy)
|
||||
assert.Equal(t, qr.ID, gpResp.Policy.QueryID)
|
||||
require.NotNil(t, gpResp.Policy.Resolution)
|
||||
assert.Equal(t, "some global resolution", *gpResp.Policy.Resolution)
|
||||
|
||||
policiesResponse := listGlobalPoliciesResponse{}
|
||||
s.DoJSON("GET", "/api/v1/fleet/global/policies", nil, http.StatusOK, &policiesResponse)
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ func (s *integrationEnterpriseTestSuite) TestTeamPolicies() {
|
|||
qr, err := s.ds.NewQuery(context.Background(), &fleet.Query{Name: "TestQuery2", Description: "Some description", Query: "select * from osquery;", ObserverCanRun: true})
|
||||
require.NoError(t, err)
|
||||
|
||||
tpParams := teamPolicyRequest{QueryID: qr.ID}
|
||||
tpParams := teamPolicyRequest{QueryID: qr.ID, Resolution: "some team resolution"}
|
||||
r := teamPolicyResponse{}
|
||||
s.DoJSON("POST", fmt.Sprintf("/api/v1/fleet/teams/%d/policies", team1.ID), tpParams, http.StatusOK, &r)
|
||||
|
||||
|
|
@ -195,6 +195,8 @@ func (s *integrationEnterpriseTestSuite) TestTeamPolicies() {
|
|||
require.Len(t, ts.Policies, 1)
|
||||
assert.Equal(t, "TestQuery2", ts.Policies[0].QueryName)
|
||||
assert.Equal(t, qr.ID, ts.Policies[0].QueryID)
|
||||
require.NotNil(t, ts.Policies[0].Resolution)
|
||||
assert.Equal(t, "some team resolution", *ts.Policies[0].Resolution)
|
||||
|
||||
deletePolicyParams := deleteTeamPoliciesRequest{IDs: []uint{ts.Policies[0].ID}}
|
||||
deletePolicyResp := deleteTeamPoliciesResponse{}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ func (r teamPolicyResponse) error() error { return r.Err }
|
|||
|
||||
func teamPolicyEndpoint(ctx context.Context, request interface{}, svc fleet.Service) (interface{}, error) {
|
||||
req := request.(*teamPolicyRequest)
|
||||
resp, err := svc.NewTeamPolicy(ctx, req.TeamID, req.QueryID, "")
|
||||
resp, err := svc.NewTeamPolicy(ctx, req.TeamID, req.QueryID, req.Resolution)
|
||||
if err != nil {
|
||||
return teamPolicyResponse{Err: err}, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue