kibana/x-pack/test/fleet_api_integration
John Schulz 0a5e054fdc
[Fleet] Don't upgrade agent(s) in a managed policy (#91303)
## Summary

 - Make sure any agents requesting to be upgraded, are not enrolled in a managed policy.
 - `force: true` will only bypass agent / kibana version checks. It will not bypass managed policy check. To workaround, the enrolled policy should be changed to unmanaged (`is_managed: false`) as we do with enroll, reassign, etc.
 - Took more efficient approach to bulk actions. One `bulkGet` for N agents/policies vs N `get`s  approach used for bulk reassignment of agents. See discussion in https://github.com/elastic/kibana/pull/88688/files#r568941761
 - [x] API
 - [ ] UI
 - [x] tests

### Checklist
- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios


### Manual tests
#### upgrade one
```
curl --location --request POST 'http://localhost:5601/api/fleet/agents/8d9748e0-6d52-11eb-8cbd-47e38cd1c8de/upgrade' --header 'kbn-xsrf: <string>' --header 'Content-Type: application/json' --header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' --data-raw '{
    "version": "8.0.0"
}'
{"statusCode":400,"error":"Bad Request","message":"Cannot upgrade agent 8d9748e0-6d52-11eb-8cbd-47e38cd1c8de in managed policy bf319100-6d50-11eb-8859-15a87f509a99"}
```

```
curl --location --request POST 'http://localhost:5601/api/fleet/agents/8d9748e0-6d52-11eb-8cbd-47e38cd1c8de/upgrade' --header 'kbn-xsrf: <string>' --header 'Content-Type: application/json' --header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' --data-raw '{
    "version": "8.0.0", "force": true
}'
{"statusCode":400,"error":"Bad Request","message":"Cannot upgrade agent 8d9748e0-6d52-11eb-8cbd-47e38cd1c8de in managed policy bf319100-6d50-11eb-8859-15a87f509a99"}
```

#### bulk upgrade
```
curl --location --request POST 'http://localhost:5601/api/fleet/agents/bulk_upgrade' --header 'kbn-xsrf: <string>' --header 'Content-Type: application/json' --header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' --data-raw '{
    "version": "8.0.0",
    "agents": [
        "8d9748e0-6d52-11eb-8cbd-47e38cd1c8de"
    ]
}'
{}
```

```
curl --location --request POST 'http://localhost:5601/api/fleet/agents/bulk_upgrade' --header 'kbn-xsrf: <string>' --header 'Content-Type: application/json' --header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' --data-raw '{
    "version": "8.0.0",
    "agents": [
        "8d9748e0-6d52-11eb-8cbd-47e38cd1c8de"
    ], "force": true
}'
{"statusCode":400,"error":"Bad Request","message":"Cannot update agent in managed policy bf319100-6d50-11eb-8859-15a87f509a99"}```
```
2021-02-15 13:36:39 -05:00
..
apis [Fleet] Don't upgrade agent(s) in a managed policy (#91303) 2021-02-15 13:36:39 -05:00
config.ts Updating package registry snapshot distribution version (#89776) 2021-02-04 08:40:18 -05:00
helpers.ts Elastic License 2.0 (#90099) 2021-02-03 18:12:39 -08:00