Skip to content

Commit

Permalink
Cannot update integrations on a managed policy
Browse files Browse the repository at this point in the history
  • Loading branch information
John Schulz committed Feb 9, 2021
1 parent 66ba36a commit 45f420c
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion x-pack/test/fleet_api_integration/apis/package_policy/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 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';

Expand All @@ -21,6 +21,7 @@ export default function (providerContext: FtrProviderContext) {
describe('Package Policy - update', async function () {
skipIfNoDockerRegistry(providerContext);
let agentPolicyId: string;
let managedAgentPolicyId: string;
let packagePolicyId: string;
let packagePolicyId2: string;

Expand All @@ -35,8 +36,30 @@ export default function (providerContext: FtrProviderContext) {
name: 'Test policy',
namespace: 'default',
});

agentPolicyId = agentPolicyResponse.item.id;

const { body: managedAgentPolicyResponse } = await supertest
.post(`/api/fleet/agent_policies`)
.set('kbn-xsrf', 'xxxx')
.send({
name: 'Test managed policy',
namespace: 'default',
is_managed: true,
});

// if one already exists, re-use that
const managedExists = managedAgentPolicyResponse.statusCode === 409;
if (managedExists) {
const errorRegex = /^agent policy \'(?<id>[\w,\-]+)\' already exists/i;
const result = errorRegex.exec(managedAgentPolicyResponse.message);
if (result?.groups?.id) {
managedAgentPolicyId = result.groups.id;
}
} else {
managedAgentPolicyId = managedAgentPolicyResponse.item.id;
}

const { body: packagePolicyResponse } = await supertest
.post(`/api/fleet/package_policies`)
.set('kbn-xsrf', 'xxxx')
Expand Down Expand Up @@ -83,6 +106,29 @@ export default function (providerContext: FtrProviderContext) {
.send({ agentPolicyId });
});

it('should fail on managed agent policies', async function () {
const { body } = await supertest
.put(`/api/fleet/package_policies/${packagePolicyId}`)
.set('kbn-xsrf', 'xxxx')
.send({
name: 'filetest-1',
description: '',
namespace: 'updated_namespace',
policy_id: managedAgentPolicyId,
enabled: true,
output_id: '',
inputs: [],
package: {
name: 'filetest',
title: 'For File Tests',
version: '0.1.0',
},
})
.expect(400);

expect(body.message).to.contain('Cannot update integrations of managed policy');
});

it('should work with valid values', async function () {
await supertest
.put(`/api/fleet/package_policies/${packagePolicyId}`)
Expand Down

0 comments on commit 45f420c

Please sign in to comment.