-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
scenario.ts
118 lines (101 loc) · 4.37 KB
/
scenario.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import expect from '@kbn/expect';
import { PublicLicenseJSON } from '@kbn/licensing-plugin/server';
import { FtrProviderContext } from './services';
import '@kbn/core-provider-plugin/types';
const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
export function createScenario({ getService, getPageObjects }: FtrProviderContext) {
const supertest = getService('supertest');
const esSupertestWithoutAuth = getService('esSupertestWithoutAuth');
const security = 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');
},
// make sure a license is present, otherwise the security is not available anymore.
async teardown() {
await security.role.delete('license_manager-role');
await security.user.delete('license_manager_user');
},
// elasticsearch allows to downgrade a license only once. other attempts will throw 403.
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);
},
// elasticsearch allows to request trial only once. other attempts will throw 403.
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 startEnterprise() {
const response = await esSupertestWithoutAuth
.post('/_license/?acknowledge=true')
.send({
license: {
uid: '00000000-d3ad-7357-c0d3-000000000000',
type: 'enterprise',
issue_date_in_millis: 1577836800000,
start_date_in_millis: 1577836800000,
// expires 2022-12-31
expiry_date_in_millis: 1672531199999,
max_resource_units: 250,
max_nodes: null,
issued_to: 'Elastic Internal Use (development environments)',
issuer: 'Elastic',
signature:
'AAAABQAAAA1gHUVis7hel8b8nNCAAAAAIAo5/x6hrsGh1GqqrJmy4qgmEC7gK0U4zQ6q5ZEMhm4jAAABAKMR+w3KZsMJfG5jNWgZXJLwRmiNqN7k94vKFgRdj1yM+gA9ufhXIn9d01OvFhPjilIqm+fxVjCxXwGKbFRiwtTWnTYjXPuNml+qCFGgUWguWEcVoIW6VU7/lYOqMJ4EB4zOMLe93P267iaDm542aelQrW1OJ69lGGuPBik8v9r1bNZzKBQ99VUr/qoosGDAm0udh2HxWzYoCL5lDML5Niy87xlVCubSSBXdUXzUgdZKKk6pKaMdHswB1gjvEfnwqPxEWAyrV0BCr/T1WehXd7U4p6/zt6sJ6cPh+34AZe9g4+3WPKrZhX4iaSHMDDHn4HNjO72CZ2oi42ZDNnJ37tA=',
},
})
.auth('license_manager_user', 'license_manager_user-password')
.expect(200);
expect(response.body.license_status).to.be('valid');
},
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> {
const { body } = await supertest.get('/api/licensing/info').expect(200);
return body;
},
async waitForPluginToDetectLicenseUpdate() {
// > --xpack.licensing.api_polling_frequency set in test config
// to wait for Kibana server to re-fetch the license from Elasticsearch
await delay(500);
},
};
return scenario;
}