import expect from '@kbn/expect' ; import { FtrProviderContext } from './services' ; import { PublicLicenseJSON } from '../../plugins/licensing/server' ; import '../../../test/plugin_functional/plugins/core_provider_plugin/types' ; const delay = ( ms ) => new Promise ( ( res ) => setTimeout ( res , ms ) ) ; export function createScenario ( { getService , getPageObjects } ) { 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' , } ) ; await PageObjects . security . logout ( ) ; await PageObjects . security . login ( 'license_manager_user' , 'license_manager_user-password' ) ; } , async teardown ( ) { await security . role . delete ( 'license_manager-role' ) ; await security . user . delete ( 'license_manager_user' ) ; } , 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 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 , 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 ( ) { const { body } = await supertest . get ( '/api/licensing/info' ) . expect ( 200 ) ; return body ; } , async waitForPluginToDetectLicenseUpdate ( ) { await delay ( 500 ) ; } , } ; return scenario ; }