Skip to content

Commit 2166b3d

Browse files
committed
add functional tests for licensing plugin
1 parent 61d8a72 commit 2166b3d

7 files changed

Lines changed: 219 additions & 6 deletions

File tree

x-pack/scripts/functional_tests.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ require('@kbn/test').runTestsCli([
3434
require.resolve('../test/ui_capabilities/security_only/config'),
3535
require.resolve('../test/ui_capabilities/spaces_only/config'),
3636
require.resolve('../test/upgrade_assistant_integration/config'),
37+
require.resolve('../test/licensing_plugin/config'),
3738
]);
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
import expect from '@kbn/expect';
7+
import { FtrProviderContext } from '../services';
8+
import { SecurityService } from '../../common/services';
9+
import { PublicLicenseJSON } from '../../../plugins/licensing/server';
10+
11+
const delay = (ms: number) => new Promise(res => setTimeout(res, ms));
12+
13+
export default function({ getService, getPageObjects }: FtrProviderContext) {
14+
const supertest = getService('supertest');
15+
const esSupertestWithoutAuth = getService('esSupertestWithoutAuth');
16+
const security: SecurityService = getService('security');
17+
const PageObjects = getPageObjects(['common', 'security']);
18+
19+
const scenario = {
20+
async setup() {
21+
await security.role.create('license_manager-role', {
22+
elasticsearch: {
23+
cluster: ['all'],
24+
},
25+
kibana: [
26+
{
27+
base: ['all'],
28+
spaces: ['*'],
29+
},
30+
],
31+
});
32+
33+
await security.user.create('license_manager_user', {
34+
password: 'license_manager_user-password',
35+
roles: ['license_manager-role'],
36+
full_name: 'license_manager user',
37+
});
38+
39+
// ensure we're logged out so we can login as the appropriate users
40+
await PageObjects.security.logout();
41+
await PageObjects.security.login('license_manager_user', 'license_manager_user-password');
42+
},
43+
44+
async teardown() {
45+
await security.role.delete('license_manager-role');
46+
},
47+
48+
async startBasic() {
49+
const response = await esSupertestWithoutAuth
50+
.post('/_license/start_basic?acknowledge=true')
51+
.auth('license_manager_user', 'license_manager_user-password')
52+
.expect(200);
53+
54+
expect(response.body.basic_was_started).to.be(true);
55+
},
56+
57+
async startTrial() {
58+
const response = await esSupertestWithoutAuth
59+
.post('/_license/start_trial?acknowledge=true')
60+
.auth('license_manager_user', 'license_manager_user-password')
61+
.expect(200);
62+
63+
expect(response.body.trial_was_started).to.be(true);
64+
},
65+
66+
async deleteLicense() {
67+
const response = await esSupertestWithoutAuth
68+
.delete('/_license')
69+
.auth('license_manager_user', 'license_manager_user-password')
70+
.expect(200);
71+
72+
expect(response.body.acknowledged).to.be(true);
73+
},
74+
75+
async getLicense(): Promise<PublicLicenseJSON> {
76+
// > --xpack.licensing.pollingFrequency set in test config
77+
// to wait for Kibana server to re-fetch the license from Elasticsearch
78+
await delay(1000);
79+
80+
const { body } = await supertest.get('/api/licensing/info').expect(200);
81+
return body;
82+
},
83+
};
84+
85+
describe('changes in license types', () => {
86+
after(async () => {
87+
await scenario.startBasic();
88+
});
89+
90+
it('provides changes in license types', async () => {
91+
await scenario.setup();
92+
const initialLicense = await scenario.getLicense();
93+
expect(initialLicense.license?.type).to.be('basic');
94+
// security enabled explicitly in test config
95+
expect(initialLicense.features?.security).to.eql({
96+
isAvailable: true,
97+
isEnabled: true,
98+
});
99+
100+
const refetchedLicense = await scenario.getLicense();
101+
expect(refetchedLicense.license?.type).to.be('basic');
102+
expect(refetchedLicense.signature).to.be(initialLicense.signature);
103+
104+
// server allows to request trial only once.
105+
// other attempts will throw 403
106+
await scenario.startTrial();
107+
const trialLicense = await scenario.getLicense();
108+
expect(trialLicense.license?.type).to.be('trial');
109+
expect(trialLicense.signature).to.not.be(initialLicense.signature);
110+
expect(trialLicense.features?.security).to.eql({
111+
isAvailable: true,
112+
isEnabled: true,
113+
});
114+
115+
await scenario.startBasic();
116+
const basicLicense = await scenario.getLicense();
117+
expect(basicLicense.license?.type).to.be('basic');
118+
expect(basicLicense.signature).not.to.be(initialLicense.signature);
119+
expect(trialLicense.features?.security).to.eql({
120+
isAvailable: true,
121+
isEnabled: true,
122+
});
123+
124+
await scenario.deleteLicense();
125+
const inactiveLicense = await scenario.getLicense();
126+
expect(inactiveLicense.signature).to.not.be(initialLicense.signature);
127+
expect(inactiveLicense).to.not.have.property('license');
128+
expect(inactiveLicense.features?.security).to.eql({
129+
isAvailable: false,
130+
isEnabled: true,
131+
});
132+
});
133+
});
134+
}

x-pack/test/api_integration/apis/licensing/header.ts renamed to x-pack/test/licensing_plugin/apis/header.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import expect from '@kbn/expect';
8-
import { FtrProviderContext } from '../../ftr_provider_context';
8+
import { FtrProviderContext } from '../services';
99

1010
export default function({ getService }: FtrProviderContext) {
1111
const supertest = getService('supertest');

x-pack/test/api_integration/apis/licensing/index.ts renamed to x-pack/test/licensing_plugin/apis/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { FtrProviderContext } from '../../ftr_provider_context';
7+
import { FtrProviderContext } from '../services';
88

9-
export default function licensingIntegrationTests({ loadTestFile }: FtrProviderContext) {
10-
describe('Licensing', () => {
9+
export default function({ loadTestFile }: FtrProviderContext) {
10+
describe('Licensing plugin', function() {
1111
loadTestFile(require.resolve('./info'));
1212
loadTestFile(require.resolve('./header'));
13+
14+
// MUST BE LAST! CHANGES LICENSE TYPE!
15+
loadTestFile(require.resolve('./changes'));
1316
});
1417
}

x-pack/test/api_integration/apis/licensing/info.ts renamed to x-pack/test/licensing_plugin/apis/info.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import expect from '@kbn/expect';
8-
import { FtrProviderContext } from '../../ftr_provider_context';
8+
import { FtrProviderContext } from '../services';
99

1010
export default function({ getService }: FtrProviderContext) {
1111
const supertest = getService('supertest');
@@ -19,10 +19,11 @@ export default function({ getService }: FtrProviderContext) {
1919
expect(response.body).property('license');
2020
expect(response.body).property('signature');
2121
});
22+
2223
it('returns a correct license type', async () => {
2324
const response = await supertest.get('/api/licensing/info').expect(200);
2425

25-
expect(response.body.license.type).to.be('trial');
26+
expect(response.body.license.type).to.be('basic');
2627
});
2728
});
2829
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
import { FtrConfigProviderContext } from '@kbn/test/types/ftr';
7+
import { services, pageObjects } from './services';
8+
9+
const license = 'basic';
10+
11+
export default async function({ readConfigFile }: FtrConfigProviderContext) {
12+
const functionalTestsConfig = await readConfigFile(require.resolve('../functional/config.js'));
13+
14+
const servers = {
15+
...functionalTestsConfig.get('servers'),
16+
elasticsearch: {
17+
...functionalTestsConfig.get('servers.elasticsearch'),
18+
},
19+
kibana: {
20+
...functionalTestsConfig.get('servers.kibana'),
21+
},
22+
};
23+
24+
return {
25+
testFiles: [require.resolve('./apis')],
26+
servers,
27+
services,
28+
pageObjects,
29+
junit: {
30+
reportName: 'License plugin API Integration Tests',
31+
},
32+
33+
esTestCluster: {
34+
...functionalTestsConfig.get('esTestCluster'),
35+
license,
36+
serverArgs: [
37+
...functionalTestsConfig.get('esTestCluster.serverArgs'),
38+
'xpack.security.enabled=true',
39+
],
40+
},
41+
42+
kbnTestServer: {
43+
...functionalTestsConfig.get('kbnTestServer'),
44+
serverArgs: [
45+
...functionalTestsConfig.get('kbnTestServer.serverArgs'),
46+
'--xpack.licensing.pollingFrequency=300',
47+
],
48+
},
49+
50+
apps: {
51+
...functionalTestsConfig.get('apps'),
52+
},
53+
};
54+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
import { GenericFtrProviderContext } from '@kbn/test/types/ftr';
7+
8+
import { services as functionalTestServices } from '../functional/services';
9+
import { services as kibanaApiIntegrationServices } from '../api_integration/services';
10+
import { pageObjects } from '../functional/page_objects';
11+
12+
export const services = {
13+
...functionalTestServices,
14+
supertest: kibanaApiIntegrationServices.supertest,
15+
esSupertestWithoutAuth: kibanaApiIntegrationServices.esSupertestWithoutAuth,
16+
};
17+
18+
export { pageObjects };
19+
20+
export type FtrProviderContext = GenericFtrProviderContext<typeof services, typeof pageObjects>;

0 commit comments

Comments
 (0)