Skip to content

Commit

Permalink
add functional tests for licensing plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Nov 29, 2019
1 parent 61d8a72 commit 2166b3d
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 6 deletions.
1 change: 1 addition & 0 deletions x-pack/scripts/functional_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ require('@kbn/test').runTestsCli([
require.resolve('../test/ui_capabilities/security_only/config'),
require.resolve('../test/ui_capabilities/spaces_only/config'),
require.resolve('../test/upgrade_assistant_integration/config'),
require.resolve('../test/licensing_plugin/config'),
]);
134 changes: 134 additions & 0 deletions x-pack/test/licensing_plugin/apis/changes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import expect from '@kbn/expect';
import { FtrProviderContext } from '../services';
import { SecurityService } from '../../common/services';
import { PublicLicenseJSON } from '../../../plugins/licensing/server';

const delay = (ms: number) => new Promise(res => setTimeout(res, ms));

export default function({ getService, getPageObjects }: FtrProviderContext) {
const supertest = getService('supertest');
const esSupertestWithoutAuth = getService('esSupertestWithoutAuth');
const security: SecurityService = getService('security');
const PageObjects = getPageObjects(['common', 'security']);

const scenario = {
async setup() {
await security.role.create('license_manager-role', {
elasticsearch: {
cluster: ['all'],
},
kibana: [
{
base: ['all'],
spaces: ['*'],
},
],
});

await security.user.create('license_manager_user', {
password: 'license_manager_user-password',
roles: ['license_manager-role'],
full_name: 'license_manager user',
});

// ensure we're logged out so we can login as the appropriate users
await PageObjects.security.logout();
await PageObjects.security.login('license_manager_user', 'license_manager_user-password');
},

async teardown() {
await security.role.delete('license_manager-role');
},

async startBasic() {
const response = await esSupertestWithoutAuth
.post('/_license/start_basic?acknowledge=true')
.auth('license_manager_user', 'license_manager_user-password')
.expect(200);

expect(response.body.basic_was_started).to.be(true);
},

async startTrial() {
const response = await esSupertestWithoutAuth
.post('/_license/start_trial?acknowledge=true')
.auth('license_manager_user', 'license_manager_user-password')
.expect(200);

expect(response.body.trial_was_started).to.be(true);
},

async deleteLicense() {
const response = await esSupertestWithoutAuth
.delete('/_license')
.auth('license_manager_user', 'license_manager_user-password')
.expect(200);

expect(response.body.acknowledged).to.be(true);
},

async getLicense(): Promise<PublicLicenseJSON> {
// > --xpack.licensing.pollingFrequency set in test config
// to wait for Kibana server to re-fetch the license from Elasticsearch
await delay(1000);

const { body } = await supertest.get('/api/licensing/info').expect(200);
return body;
},
};

describe('changes in license types', () => {
after(async () => {
await scenario.startBasic();
});

it('provides changes in license types', async () => {
await scenario.setup();
const initialLicense = await scenario.getLicense();
expect(initialLicense.license?.type).to.be('basic');
// security enabled explicitly in test config
expect(initialLicense.features?.security).to.eql({
isAvailable: true,
isEnabled: true,
});

const refetchedLicense = await scenario.getLicense();
expect(refetchedLicense.license?.type).to.be('basic');
expect(refetchedLicense.signature).to.be(initialLicense.signature);

// server allows to request trial only once.
// other attempts will throw 403
await scenario.startTrial();
const trialLicense = await scenario.getLicense();
expect(trialLicense.license?.type).to.be('trial');
expect(trialLicense.signature).to.not.be(initialLicense.signature);
expect(trialLicense.features?.security).to.eql({
isAvailable: true,
isEnabled: true,
});

await scenario.startBasic();
const basicLicense = await scenario.getLicense();
expect(basicLicense.license?.type).to.be('basic');
expect(basicLicense.signature).not.to.be(initialLicense.signature);
expect(trialLicense.features?.security).to.eql({
isAvailable: true,
isEnabled: true,
});

await scenario.deleteLicense();
const inactiveLicense = await scenario.getLicense();
expect(inactiveLicense.signature).to.not.be(initialLicense.signature);
expect(inactiveLicense).to.not.have.property('license');
expect(inactiveLicense.features?.security).to.eql({
isAvailable: false,
isEnabled: true,
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
import { FtrProviderContext } from '../services';

export default function({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { FtrProviderContext } from '../../ftr_provider_context';
import { FtrProviderContext } from '../services';

export default function licensingIntegrationTests({ loadTestFile }: FtrProviderContext) {
describe('Licensing', () => {
export default function({ loadTestFile }: FtrProviderContext) {
describe('Licensing plugin', function() {
loadTestFile(require.resolve('./info'));
loadTestFile(require.resolve('./header'));

// MUST BE LAST! CHANGES LICENSE TYPE!
loadTestFile(require.resolve('./changes'));
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
import { FtrProviderContext } from '../services';

export default function({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
Expand All @@ -19,10 +19,11 @@ export default function({ getService }: FtrProviderContext) {
expect(response.body).property('license');
expect(response.body).property('signature');
});

it('returns a correct license type', async () => {
const response = await supertest.get('/api/licensing/info').expect(200);

expect(response.body.license.type).to.be('trial');
expect(response.body.license.type).to.be('basic');
});
});
});
Expand Down
54 changes: 54 additions & 0 deletions x-pack/test/licensing_plugin/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { FtrConfigProviderContext } from '@kbn/test/types/ftr';
import { services, pageObjects } from './services';

const license = 'basic';

export default async function({ readConfigFile }: FtrConfigProviderContext) {
const functionalTestsConfig = await readConfigFile(require.resolve('../functional/config.js'));

const servers = {
...functionalTestsConfig.get('servers'),
elasticsearch: {
...functionalTestsConfig.get('servers.elasticsearch'),
},
kibana: {
...functionalTestsConfig.get('servers.kibana'),
},
};

return {
testFiles: [require.resolve('./apis')],
servers,
services,
pageObjects,
junit: {
reportName: 'License plugin API Integration Tests',
},

esTestCluster: {
...functionalTestsConfig.get('esTestCluster'),
license,
serverArgs: [
...functionalTestsConfig.get('esTestCluster.serverArgs'),
'xpack.security.enabled=true',
],
},

kbnTestServer: {
...functionalTestsConfig.get('kbnTestServer'),
serverArgs: [
...functionalTestsConfig.get('kbnTestServer.serverArgs'),
'--xpack.licensing.pollingFrequency=300',
],
},

apps: {
...functionalTestsConfig.get('apps'),
},
};
}
20 changes: 20 additions & 0 deletions x-pack/test/licensing_plugin/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { GenericFtrProviderContext } from '@kbn/test/types/ftr';

import { services as functionalTestServices } from '../functional/services';
import { services as kibanaApiIntegrationServices } from '../api_integration/services';
import { pageObjects } from '../functional/page_objects';

export const services = {
...functionalTestServices,
supertest: kibanaApiIntegrationServices.supertest,
esSupertestWithoutAuth: kibanaApiIntegrationServices.esSupertestWithoutAuth,
};

export { pageObjects };

export type FtrProviderContext = GenericFtrProviderContext<typeof services, typeof pageObjects>;

0 comments on commit 2166b3d

Please sign in to comment.