import util from 'util' ; import { isEqual , isEqualWith } from 'lodash' ; import { FtrProviderContext } from '../../ftr_provider_context' ; export default function ( { getService } ) { const supertest = getService ( 'supertest' ) ; describe ( 'Privileges' , ( ) => { describe ( 'GET /api/security/privileges' , ( ) => { it ( 'should return a privilege map with all known privileges, without actions' , async ( ) => { const expected = { features : { discover : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , visualize : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , dashboard : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , dev_tools : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , advancedSettings : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , indexPatterns : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , savedObjectsManagement : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , savedObjectsTagging : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , graph : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , maps : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , observabilityCases : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , canvas : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , infrastructure : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , logs : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , uptime : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , apm : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , osquery : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , ml : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , siem : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , securitySolutionCases : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , fleet : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , stackAlerts : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , actions : [ 'all' , 'read' , 'minimal_all' , 'minimal_read' ] , } , global : [ 'all' , 'read' ] , space : [ 'all' , 'read' ] , reserved : [ 'fleet-setup' , 'ml_user' , 'ml_admin' , 'ml_apm_user' , 'monitoring' ] , } ; await supertest . get ( '/api/security/privileges' ) . set ( 'kbn-xsrf' , 'xxx' ) . send ( ) . expect ( 200 ) . expect ( ( res ) => { const success = isEqualWith ( res . body , expected , ( value , other , key ) => { if ( Array . isArray ( value ) && Array . isArray ( other ) ) { return isEqual ( value . sort ( ) , other . sort ( ) ) ; } return undefined as any ; } ) ; if ( ! success ) { throw new Error ( `Expected ${ util . inspect ( res . body ) } to equal ${ util . inspect ( expected ) }` ) ; } } ) . expect ( 200 ) ; } ) ; } ) ; } ) ; }