-
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.
add functional tests for licensing plugin
- Loading branch information
Showing
7 changed files
with
219 additions
and
6 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
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, | ||
}); | ||
}); | ||
}); | ||
} |
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
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'), | ||
}, | ||
}; | ||
} |
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,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>; |