import expect from '@kbn/expect' ; import { FtrProviderContext } from '../../../common/ftr_provider_context' ; export default function apiTest ( { getService } ) { const registry = getService ( 'registry' ) ; const noAccessUser = getService ( 'legacySupertestAsNoAccessUser' ) ; const readUser = getService ( 'legacySupertestAsApmReadUser' ) ; const writeUser = getService ( 'legacySupertestAsApmWriteUser' ) ; type SupertestAsUser = typeof noAccessUser | typeof readUser | typeof writeUser ; function getJobs ( user ) { return user . get ( `/internal/apm/settings/anomaly-detection/jobs` ) . set ( 'kbn-xsrf' , 'foo' ) ; } function createJobs ( user , environments ) { return user . post ( `/internal/apm/settings/anomaly-detection/jobs` ) . send ( { environments } ) . set ( 'kbn-xsrf' , 'foo' ) ; } async function expectForbidden ( user ) { const { body : getJobsBody } = await getJobs ( user ) ; expect ( getJobsBody . statusCode ) . to . be ( 403 ) ; expect ( getJobsBody . error ) . to . be ( 'Forbidden' ) ; const { body : createJobsBody } = await createJobs ( user , [ 'production' , 'staging' ] ) ; expect ( createJobsBody . statusCode ) . to . be ( 403 ) ; expect ( getJobsBody . error ) . to . be ( 'Forbidden' ) ; } registry . when ( 'ML jobs return a 403 for' , { config : 'basic' , archives : [ ] } , ( ) => { it ( 'user without access' , async ( ) => { await expectForbidden ( noAccessUser ) ; } ) ; it ( 'read user' , async ( ) => { await expectForbidden ( readUser ) ; } ) ; it ( 'write user' , async ( ) => { await expectForbidden ( writeUser ) ; } ) ; } ) ; }