kibana/x-pack/test/fleet_api_integration
John Schulz bda7b2816f
[Fleet] Cannot delete a managed agent policy (#90505)
## Summary
Managed policy cannot be deleted via API or UI

closes https://github.com/elastic/kibana/issues/90448

### 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 testing
<details><summary>UI screenshot</summary>

<img width="1522" alt="Screen Shot 2021-02-05 at 1 56 13 PM" src="https://user-images.githubusercontent.com/57655/107076955-2ce95800-67ba-11eb-8bd4-d2ba3182e516.png">

</details>

<details><summary>API commands</summary>

```
## Create a managed policy
curl --user elastic:changeme -X POST localhost:5601/api/fleet/agent_policies -H 'Content-Type: application/json' -d'{ "name": "User created MANAGED", "namespace": "default", "is_managed": true}' -H 'kbn-xsrf: true'
{"item":{"id":"17ebd160-67ee-11eb-adb2-f16c6e20580c","name":"User created MANAGED","namespace":"default","is_managed":true,"revision":1,"updated_at":"2021-02-05T20:09:46.614Z","updated_by":"elastic"}}

## Cannot delete it
curl --user elastic:changeme -X POST 'http://localhost:5601/api/fleet/agent_policies/delete'   -H 'kbn-xsrf: abc'  -H 'Content-Type: application/json'   --data-raw '{"agentPolicyId": "17ebd160-67ee-11eb-adb2-f16c6e20580c" }'    
{
  "statusCode": 400,
  "error": "Bad Request",
  "message": "Cannot delete managed policy 17ebd160-67ee-11eb-adb2-f16c6e20580c"
}

## Set policy to unmanaged
curl --user elastic:changeme -X PUT localhost:5601/api/fleet/agent_policies/17ebd160-67ee-11eb-adb2-f16c6e20580c -H 'Content-Type: application/json' -d'{ "name": "User created MANAGED", "namespace": "default", "is_managed": false}' -H 'kbn-xsrf: true' 
{
  "item": {
    "id": "17ebd160-67ee-11eb-adb2-f16c6e20580c",
    "name": "User created MANAGED",
    "namespace": "default",
    "is_managed": false,
    "revision": 3,
    "updated_at": "2021-02-05T20:10:45.383Z",
    "updated_by": "elastic",
    "package_policies": []
  }
}

## Can delete
curl --user elastic:changeme -X POST 'http://localhost:5601/api/fleet/agent_policies/delete'   -H 'kbn-xsrf: abc'  -H 'Content-Type: application/json'   --data-raw '{"agentPolicyId": "17ebd160-67ee-11eb-adb2-f16c6e20580c" }'    
{
  "id": "17ebd160-67ee-11eb-adb2-f16c6e20580c",
  "name": "User created MANAGED"
}


```
</details>
2021-02-08 12:13:55 -05:00
..
apis [Fleet] Cannot delete a managed agent policy (#90505) 2021-02-08 12:13:55 -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