import expect from '@kbn/expect' ; import { adminTestUser } from '@kbn/test' ; import { FtrProviderContext } from '../../ftr_provider_context' ; export default function ( { getService } ) { const supertest = getService ( 'supertestWithoutAuth' ) ; describe ( 'authorization' , ( ) => { it ( 'fail request without authorization request header' , async ( ) => { await supertest . get ( '/internal/security/me' ) . set ( 'kbn-xsrf' , 'true' ) . expect ( 401 ) ; } ) ; it ( 'accept request with authorization request header' , async ( ) => { const credentials = Buffer . from ( `${ adminTestUser . username }:${ adminTestUser . password }` ) . toString ( 'base64' ) ; const { body : user , headers } = await supertest . get ( '/internal/security/me' ) . set ( 'kbn-xsrf' , 'xxx' ) . set ( 'Authorization' , `Basic ${ credentials }` ) . expect ( 200 ) ; expect ( user . username ) . to . eql ( adminTestUser . username ) ; expect ( user . authentication_provider ) . to . eql ( { type : 'http' , name : '__http__' } ) ; expect ( user . authentication_type ) . to . eql ( 'realm' ) ; expect ( headers [ 'set-cookie' ] ) . to . be ( undefined ) ; } ) ; } ) ; }