import expect from '@kbn/expect' ; import { USERS , User , ExpectedResponse } from '../../../common/lib' ; import { FtrProviderContext } from '../services' ; export default function ( { getService } ) { const esArchiver = getService ( 'esArchiver' ) ; const supertest = getService ( 'supertestWithoutAuth' ) ; describe ( 'GET /api/saved_objects_tagging/tags/{id}' , ( ) => { before ( async ( ) => { await esArchiver . load ( 'x-pack/test/saved_object_tagging/common/fixtures/es_archiver/rbac_tags' ) ; } ) ; after ( async ( ) => { await esArchiver . unload ( 'x-pack/test/saved_object_tagging/common/fixtures/es_archiver/rbac_tags' ) ; } ) ; const responses = { authorized : { httpCode : 200 , expectResponse : ( { body } ) => { expect ( body ) . to . eql ( { tag : { id : 'default-space-tag-1' , name : 'tag-1' , description : 'Tag 1 in default space' , color : '#FF00FF' , } , } ) ; } , } , unauthorized : { httpCode : 403 , expectResponse : ( { body } ) => { expect ( body ) . to . eql ( { statusCode : 403 , error : 'Forbidden' , message : 'Unable to get tag' , } ) ; } , } , } ; const expectedResults = { authorized : [ USERS . SUPERUSER , USERS . DEFAULT_SPACE_READ_USER , USERS . DEFAULT_SPACE_SO_MANAGEMENT_WRITE_USER , USERS . DEFAULT_SPACE_SO_TAGGING_READ_USER , USERS . DEFAULT_SPACE_SO_TAGGING_WRITE_USER , USERS . DEFAULT_SPACE_DASHBOARD_READ_USER , USERS . DEFAULT_SPACE_VISUALIZE_READ_USER , USERS . DEFAULT_SPACE_MAPS_READ_USER , ] , unauthorized : [ USERS . NOT_A_KIBANA_USER , USERS . DEFAULT_SPACE_ADVANCED_SETTINGS_READ_USER ] , } ; const createUserTest = ( { username , password , description } , { httpCode , expectResponse } ) => { it ( `returns expected ${ httpCode } response for ${ description ?? username }` , async ( ) => { await supertest . get ( `/api/saved_objects_tagging/tags/default-space-tag-1` ) . auth ( username , password ) . expect ( httpCode ) . then ( expectResponse ) ; } ) ; } ; const createTestSuite = ( ) => { Object . entries ( expectedResults ) . forEach ( ( [ responseId , users ] ) => { const response = responses [ responseId ] ; users . forEach ( ( user ) => { createUserTest ( user , response ) ; } ) ; } ) ; } ; createTestSuite ( ) ; } ) ; }