import expect from '@kbn/expect' ; import { FtrProviderContext } from '../../ftr_provider_context' ; import { createUserAndRole , deleteUserAndRole , ROLES , } from '../../../common/services/security_solution' ; import { IndexedHostsAndAlertsResponse } from '../../../../plugins/security_solution/common/endpoint/index_data' ; export default ( { getPageObjects , getService } ) => { const PageObjects = getPageObjects ( [ 'security' , 'endpoint' , 'detections' , 'hosts' ] ) ; const testSubjects = getService ( 'testSubjects' ) ; const endpointTestResources = getService ( 'endpointTestResources' ) ; const policyTestResources = getService ( 'policyTestResources' ) ; describe ( 'Endpoint permissions:' , ( ) => { let indexedData ; before ( async ( ) => { const endpointPackage = await policyTestResources . getEndpointPackage ( ) ; await endpointTestResources . setMetadataTransformFrequency ( '1s' , endpointPackage . version ) ; indexedData = await endpointTestResources . loadEndpointData ( ) ; await PageObjects . security . forceLogout ( ) ; } ) ; after ( async ( ) => { await endpointTestResources . unloadEndpointData ( indexedData ) ; } ) ; for ( const role of Object . keys ( ROLES ) as Array < keyof typeof ROLES > ) { describe ( `when running with user/role [${ role }]` , ( ) => { before ( async ( ) => { await createUserAndRole ( getService , ROLES [ role ] ) ; await PageObjects . security . login ( role , 'changeme' ) ; } ) ; after ( async ( ) => { await PageObjects . security . forceLogout ( ) ; await deleteUserAndRole ( getService , ROLES [ role ] ) ; } ) ; it ( 'should NOT allow access to endpoint management pages' , async ( ) => { await PageObjects . endpoint . navigateToEndpointList ( ) ; await testSubjects . existOrFail ( 'noIngestPermissions' ) ; } ) ; it ( 'should display endpoint data on Host Details' , async ( ) => { const endpoint = indexedData . hosts [ 0 ] ; await PageObjects . hosts . navigateToHostDetails ( endpoint . host . name ) ; const endpointSummary = await PageObjects . hosts . hostDetailsEndpointOverviewData ( ) ; expect ( endpointSummary [ 'Endpoint integration policy' ] ) . to . be ( endpoint . Endpoint . policy . applied . name ) ; expect ( endpointSummary [ 'Endpoint version' ] ) . to . be ( endpoint . agent . version ) ; expect ( endpointSummary [ 'Policy status' ] ) . not . be ( '—' ) ; expect ( endpointSummary [ 'Agent status' ] ) . not . to . be ( '—' ) ; } ) ; it . skip ( 'should display endpoint data on Alert Details' , async ( ) => { await PageObjects . detections . navigateToAlerts ( ) ; await PageObjects . detections . openFirstAlertDetailsForHostName ( indexedData . hosts [ 0 ] . host . name ) ; const hostAgentStatus = await testSubjects . getVisibleText ( 'rowHostStatus' ) ; expect ( hostAgentStatus ) . to . eql ( 'Healthy' ) ; } ) ; } ) ; } } ) ; } ;