|
| 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 | +} |
0 commit comments