Skip to content

Commit

Permalink
added api test
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic committed Feb 21, 2022
1 parent 25b22a5 commit fc2e401
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion x-pack/test/fleet_api_integration/apis/epm/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function (providerContext: FtrProviderContext) {
const url = '/api/fleet/epm/packages/endpoint';
await supertest.delete(url).set('kbn-xsrf', 'xxxx').send({ force: true }).expect(200);
await supertest
.post(`${url}-${oldEndpointVersion}`)
.post(`${url}/${oldEndpointVersion}`)
.set('kbn-xsrf', 'xxxx')
.send({ force: true })
.expect(200);
Expand All @@ -52,6 +52,75 @@ export default function (providerContext: FtrProviderContext) {
});
});

describe('package policy upgrade on setup', () => {
let agentPolicyId: string;
before(async function () {
const { body: agentPolicyResponse } = await supertest
.post(`/api/fleet/agent_policies`)
.set('kbn-xsrf', 'xxxx')
.send({
name: 'Test policy',
namespace: 'default',
});
agentPolicyId = agentPolicyResponse.item.id;
});

after(async function () {
await supertest
.post(`/api/fleet/agent_policies/delete`)
.set('kbn-xsrf', 'xxxx')
.send({ agentPolicyId });
});

it('should upgrade package policy on setup if keep policies up to date set to true', async () => {
const oldVersion = '1.9.0';
await supertest
.post(`/api/fleet/epm/packages/system/${oldVersion}`)
.set('kbn-xsrf', 'xxxx')
.send({ force: true })
.expect(200);
await supertest
.put(`/api/fleet/epm/packages/system/${oldVersion}`)
.set('kbn-xsrf', 'xxxx')
.send({ keepPoliciesUpToDate: true })
.expect(200);
await supertest
.post('/api/fleet/package_policies')
.set('kbn-xsrf', 'xxxx')
.send({
name: 'system-1',
namespace: 'default',
policy_id: agentPolicyId,
package: { name: 'system', version: oldVersion },
inputs: [],
})
.expect(200);

let { body } = await supertest
.get(`/api/fleet/epm/packages/system/${oldVersion}`)
.expect(200);
const latestVersion = body.item.latestVersion;
log.info(`System package latest version: ${latestVersion}`);
// make sure we're actually doing an upgrade
expect(latestVersion).not.eql(oldVersion);

({ body } = await supertest
.post(`/api/fleet/epm/packages/system/${latestVersion}`)
.set('kbn-xsrf', 'xxxx')
.expect(200));

await supertest.post(`/api/fleet/setup`).set('kbn-xsrf', 'xxxx').expect(200);

({ body } = await supertest
.get('/api/fleet/package_policies')
.set('kbn-xsrf', 'xxxx')
.expect(200));
expect(body.items.find((pkg: any) => pkg.name === 'system-1').package.version).to.equal(
latestVersion
);
});
});

it('does not fail when package is no longer compatible in registry', async () => {
await supertest
.post(`/api/fleet/epm/packages/deprecated/0.1.0`)
Expand Down

0 comments on commit fc2e401

Please sign in to comment.