import expect from '@kbn/expect' ; import { FtrProviderContext } from '../../../api_integration/ftr_provider_context' ; import { skipIfNoDockerRegistry } from '../../helpers' ; import { setupFleetAndAgents } from '../agents/services' ; export default function ( providerContext ) { const { getService } = providerContext ; const supertest = getService ( 'supertest' ) ; const es = getService ( 'es' ) ; const dockerServers = getService ( 'dockerServers' ) ; const mappingsPackage = 'overrides' ; const mappingsPackageVersion = '0.1.0' ; const server = dockerServers . get ( 'registry' ) ; const deletePackage = async ( pkg , version ) => supertest . delete ( `/api/fleet/epm/packages/${ pkg }/${ version }` ) . set ( 'kbn-xsrf' , 'xxxx' ) ; describe ( 'installs packages that include settings and mappings overrides' , async ( ) => { skipIfNoDockerRegistry ( providerContext ) ; setupFleetAndAgents ( providerContext ) ; after ( async ( ) => { if ( server . enabled ) { await deletePackage ( mappingsPackage , mappingsPackageVersion ) ; } } ) ; it ( 'should install the overrides package correctly' , async function ( ) { let { body } = await supertest . post ( `/api/fleet/epm/packages/${ mappingsPackage }/${ mappingsPackageVersion }` ) . set ( 'kbn-xsrf' , 'xxxx' ) . expect ( 200 ) ; const templateName = body . items [ 0 ] . id ; const { body : indexTemplateResponse } = await es . transport . request < any > ( { method : 'GET' , path : `/_index_template/${ templateName }` , } , { meta : true } ) ; const indexTemplate = indexTemplateResponse . index_templates [ 0 ] . index_template ; expect ( indexTemplate . composed_of ) . to . eql ( [ `${ templateName }@mappings` , `${ templateName }@settings` , `${ templateName }@custom` , '.fleet_component_template-1' , ] ) ; ( { body } = await es . transport . request ( { method : 'GET' , path : `/_component_template/${ templateName }@mappings` , } , { meta : true } ) ) ; expect ( body . component_templates [ 0 ] . component_template . template . mappings . dynamic ) . to . be ( false ) ; ( { body } = await es . transport . request ( { method : 'GET' , path : `/_component_template/${ templateName }@settings` , } , { meta : true } ) ) ; expect ( body . component_templates [ 0 ] . component_template . template . settings . index . lifecycle . name ) . to . be ( 'reference' ) ; ( { body } = await es . transport . request ( { method : 'GET' , path : `/_component_template/${ templateName }@custom` , } , { meta : true } ) ) ; const storedTemplate = body . component_templates [ 0 ] . component_template . template . settings ; expect ( storedTemplate ) . to . eql ( { } ) ; ( { body } = await es . transport . request ( { method : 'PUT' , path : `/_component_template/${ templateName }@custom` , body : { template : { settings : { number_of_shards : 3 , index : { lifecycle : { name : 'overridden by user' } , number_of_shards : 123 , } , } , } , } , } ) ) ; ( { body } = await es . transport . request ( { method : 'POST' , path : `/_index_template/_simulate/${ templateName }` , body : { index_patterns : [ `${ templateName }-*` ] , composed_of : [ `${ templateName }@mappings` , `${ templateName }@settings` , `${ templateName }@custom` , ] , } , } , { meta : true } ) ) ; expect ( body ) . to . eql ( { template : { settings : { index : { codec : 'best_compression' , lifecycle : { name : 'overridden by user' , } , mapping : { total_fields : { limit : '10000' , } , } , number_of_shards : '3' , } , } , mappings : { dynamic : 'false' , } , aliases : { } , } , overlapping : [ { name : 'logs' , index_patterns : [ 'logs-*-*' ] , } , ] , } ) ; } ) ; } ) ; }