diff --git a/src/log_pusher.ts b/src/log_pusher.ts index 1522fe4..c6746bc 100644 --- a/src/log_pusher.ts +++ b/src/log_pusher.ts @@ -70,9 +70,11 @@ export class LogPusher { headers: { ...this.#options.headers, ...(this.#options.basicAuth && { - Authorization: Buffer.from( - `${this.#options.basicAuth.username}:${this.#options.basicAuth.password}`, - ).toString('base64'), + Authorization: + 'Basic ' + + Buffer.from( + `${this.#options.basicAuth.username}:${this.#options.basicAuth.password}`, + ).toString('base64'), }), 'Content-Type': 'application/json', }, diff --git a/tests/helpers.ts b/tests/helpers.ts index b74e203..a609ba2 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -12,10 +12,21 @@ interface QueryRangeResponse> { // eslint-disable-next-line @typescript-eslint/no-extraneous-class export class LokiClient { static async getLogs(query: string) { - const url = new URL('loki/api/v1/query', process.env.LOKI_HOST!) + const url = new URL('loki/api/v1/query_range', process.env.LOKI_HOST!) url.searchParams.append('query', query) url.searchParams.append('limit', '10') - return fetch(url).then((response) => response.json() as Promise>) + return fetch(url, { + headers: { + ...(process.env.LOKI_USERNAME && + process.env.LOKI_PASSWORD && { + Authorization: + 'Basic ' + + Buffer.from(`${process.env.LOKI_USERNAME}:${process.env.LOKI_PASSWORD}`).toString( + 'base64', + ), + }), + }, + }).then((response) => response.json() as Promise>) } } diff --git a/tests/unit/log_pusher.spec.ts b/tests/unit/log_pusher.spec.ts index d64d7a0..d0314b8 100644 --- a/tests/unit/log_pusher.spec.ts +++ b/tests/unit/log_pusher.spec.ts @@ -59,7 +59,7 @@ test.group('LogPusher', (group) => { await pusher.push({ level: 30 }) - assert.equal(basicAuthHeader, Buffer.from('user:pass').toString('base64')) + assert.equal(basicAuthHeader, 'Basic ' + Buffer.from('user:pass').toString('base64')) }) test('should not output error when silenceErrors is true', async ({ assert }) => {