char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
e21152dc9
char/aliceai-t5-moe
1import { CORS_PROXY } from '$lib/constants' ; 2import { sanitizeHeaders } from '$lib/utils/api-headers' ; 3import { describe , expect , it } from 'vitest' ; 4 5describe ( 'sanitizeHeaders' , () => { 6it ( 'returns empty object for undefined input' , () => { 7expect ( sanitizeHeaders ()). toEqual ({}); 8}); 9 10it ( 'passes through non-sensitive headers' , () => { 11const headers = new Headers ({ accept :'text/html' , 'content-type' :'application/json' }); 12 13expect ( sanitizeHeaders ( headers )). toEqual ({ 14accept :'text/html' , 15'content-type' :'application/json' 16}); 17}); 18 19it ( 'redacts known sensitive headers' , () => { 20const headers = new Headers ({ 21authorization :'Bearer secret' , 22'content-type' :'application/json' , 23'x-api-key' :'key-123' 24}); 25const result = sanitizeHeaders ( headers ); 26 27expect ( result . authorization ). toBe ( '[redacted]' ); 28expect ( result [ 'x-api-key' ]). toBe ( '[redacted]' ); 29expect ( result [ 'content-type' ]). toBe ( 'application/json' ); 30}); 31 32it ( 'partially redacts headers specified in partialRedactHeaders' , () => { 33const headers = new Headers ({ 'mcp-session-id' :'session-12345' }); 34const partial = new Map ([[ 'mcp-session-id' , 5 ]]); 35 36expect ( sanitizeHeaders ( headers , undefined , partial )[ 'mcp-session-id' ]). toBe ( '....12345' ); 37}); 38 39it ( 'fully redacts mcp-session-id when no partialRedactHeaders is given' , () => { 40const headers = new Headers ({ 'mcp-session-id' :'session-12345' }); 41 42expect ( sanitizeHeaders ( headers )[ 'mcp-session-id' ]). toBe ( '[redacted]' ); 43}); 44 45it ( 'redacts extra headers provided by the caller' , () => { 46const headers = new Headers ({ 47'content-type' :'application/json' , 48'x-vendor-key' :'vendor-secret' 49}); 50const result = sanitizeHeaders ( headers , [ 'x-vendor-key' ]); 51 52expect ( result [ 'x-vendor-key' ]). toBe ( '[redacted]' ); 53expect ( result [ 'content-type' ]). toBe ( 'application/json' ); 54}); 55 56it ( 'handles case-insensitive extra header names' , () => { 57const headers = new Headers ({ 'X-Custom-Token' :'token-value' }); 58const result = sanitizeHeaders ( headers , [ 'X-CUSTOM-TOKEN' ]); 59 60expect ( result [ 'x-custom-token' ]). toBe ( '[redacted]' ); 61}); 62 63it ( 'redacts proxied sensitive and custom target headers' , () => { 64const proxiedAuthorization = ` ${ CORS_PROXY . HEADER_PREFIX } authorization` ; 65const proxiedSessionId = ` ${ CORS_PROXY . HEADER_PREFIX } mcp-session-id` ; 66const proxiedVendorKey = ` ${ CORS_PROXY . HEADER_PREFIX } x-vendor-key` ; 67const headers = new Headers ({ 68[ proxiedAuthorization ] :'Bearer secret' , 69[ proxiedSessionId ] :'session-12345' , 70[ proxiedVendorKey ] :'vendor-secret' 71}); 72const partial = new Map ([[ 'mcp-session-id' , 5 ]]); 73const result = sanitizeHeaders ( headers , [ 'x-vendor-key' ], partial ); 74 75expect ( result [ proxiedAuthorization ]). toBe ( '[redacted]' ); 76expect ( result [ proxiedSessionId ]). toBe ( '....12345' ); 77expect ( result [ proxiedVendorKey ]). toBe ( '[redacted]' ); 78}); 79});