-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…91150) ## Summary - [x] Integrations cannot be added ~~, unless with a force flag~~ - [x] API - [x] UI - [x] tests - [x] Integrations cannot be removed ~~, unless with a force flag~~ - [x] API - [x] UI - [x] tests closes #90445 refs #89617 ### Cannot add integrations to managed policy <img height="400" alt="Screen Shot 2021-02-08 at 1 56 32 PM" src="https://user-images.githubusercontent.com/57655/107277261-25c48300-6a22-11eb-936a-0a7361667093.png"> ### Cannot delete integrations from managed policy <img alt="Screen Shot 2021-02-08 at 3 05 16 PM" src="https://user-images.githubusercontent.com/57655/107277318-337a0880-6a22-11eb-836f-fc66b510d257.png"> ### 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
- Loading branch information
John Schulz
authored
Feb 11, 2021
1 parent
942f6d0
commit 48803ac
Showing
7 changed files
with
257 additions
and
16 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
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
127 changes: 127 additions & 0 deletions
127
x-pack/test/fleet_api_integration/apis/package_policy/delete.ts
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,127 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import expect from '@kbn/expect'; | ||
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; | ||
import { skipIfNoDockerRegistry } from '../../helpers'; | ||
|
||
export default function (providerContext: FtrProviderContext) { | ||
const { getService } = providerContext; | ||
const supertest = getService('supertest'); | ||
|
||
// use function () {} and not () => {} here | ||
// because `this` has to point to the Mocha context | ||
// see https://mochajs.org/#arrow-functions | ||
|
||
describe('Package Policy - delete', async function () { | ||
skipIfNoDockerRegistry(providerContext); | ||
let agentPolicy: any; | ||
let packagePolicy: any; | ||
|
||
before(async function () { | ||
let agentPolicyResponse = await supertest | ||
.post(`/api/fleet/agent_policies`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.send({ | ||
name: 'Test policy', | ||
namespace: 'default', | ||
is_managed: false, | ||
}); | ||
|
||
// if one already exists, re-use that | ||
if (agentPolicyResponse.body.statusCode === 409) { | ||
const errorRegex = /^agent policy \'(?<id>[\w,\-]+)\' already exists/i; | ||
const result = errorRegex.exec(agentPolicyResponse.body.message); | ||
if (result?.groups?.id) { | ||
agentPolicyResponse = await supertest | ||
.put(`/api/fleet/agent_policies/${result.groups.id}`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.send({ | ||
name: 'Test policy', | ||
namespace: 'default', | ||
is_managed: false, | ||
}); | ||
} | ||
} | ||
agentPolicy = agentPolicyResponse.body.item; | ||
|
||
const { body: packagePolicyResponse } = await supertest | ||
.post(`/api/fleet/package_policies`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.send({ | ||
name: 'filetest-1', | ||
description: '', | ||
namespace: 'default', | ||
policy_id: agentPolicy.id, | ||
enabled: true, | ||
output_id: '', | ||
inputs: [], | ||
package: { | ||
name: 'filetest', | ||
title: 'For File Tests', | ||
version: '0.1.0', | ||
}, | ||
}); | ||
packagePolicy = packagePolicyResponse.item; | ||
}); | ||
|
||
after(async function () { | ||
await supertest | ||
.post(`/api/fleet/agent_policies/delete`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.send({ agentPolicyId: agentPolicy.id }); | ||
|
||
await supertest | ||
.post(`/api/fleet/package_policies/delete`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.send({ packagePolicyIds: [packagePolicy.id] }); | ||
}); | ||
|
||
it('should fail on managed agent policies', async function () { | ||
// update existing policy to managed | ||
await supertest | ||
.put(`/api/fleet/agent_policies/${agentPolicy.id}`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.send({ | ||
name: agentPolicy.name, | ||
namespace: agentPolicy.namespace, | ||
is_managed: true, | ||
}) | ||
.expect(200); | ||
|
||
// try to delete | ||
const { body: results } = await supertest | ||
.post(`/api/fleet/package_policies/delete`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.send({ packagePolicyIds: [packagePolicy.id] }) | ||
.expect(200); | ||
|
||
// delete always succeeds (returns 200) with Array<{success: boolean}> | ||
expect(Array.isArray(results)); | ||
expect(results.length).to.be(1); | ||
expect(results[0].success).to.be(false); | ||
expect(results[0].body.message).to.contain('Cannot remove integrations of managed policy'); | ||
|
||
// revert existing policy to unmanaged | ||
await supertest | ||
.put(`/api/fleet/agent_policies/${agentPolicy.id}`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.send({ | ||
name: agentPolicy.name, | ||
namespace: agentPolicy.namespace, | ||
is_managed: false, | ||
}) | ||
.expect(200); | ||
}); | ||
|
||
it('should work for unmanaged policies', async function () { | ||
await supertest | ||
.post(`/api/fleet/package_policies/delete`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.send({ packagePolicyIds: [packagePolicy.id] }); | ||
}); | ||
}); | ||
} |
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