mirror of
https://github.com/pnpm/pnpm.git
synced 2026-01-06 05:58:20 -05:00
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import { FetchError } from '@pnpm/error'
|
|
|
|
test('FetchError escapes auth tokens', () => {
|
|
const error = new FetchError(
|
|
{ url: 'https://foo.com', authHeaderValue: 'Bearer 00000000000000000000' },
|
|
{ status: 401, statusText: 'Unauthorized' }
|
|
)
|
|
expect(error.message).toBe('GET https://foo.com: Unauthorized - 401')
|
|
expect(error.hint).toBe('An authorization header was used: Bearer 0000[hidden]')
|
|
expect(error.request.authHeaderValue).toBe('Bearer 0000[hidden]')
|
|
})
|
|
|
|
test('FetchError escapes short auth tokens', () => {
|
|
const error = new FetchError(
|
|
{ url: 'https://foo.com', authHeaderValue: 'Bearer 0000000000' },
|
|
{ status: 401, statusText: 'Unauthorized' }
|
|
)
|
|
expect(error.message).toBe('GET https://foo.com: Unauthorized - 401')
|
|
expect(error.hint).toBe('An authorization header was used: Bearer [hidden]')
|
|
expect(error.request.authHeaderValue).toBe('Bearer [hidden]')
|
|
})
|
|
|
|
test('FetchError escapes non-standard auth header', () => {
|
|
const error = new FetchError(
|
|
{ url: 'https://foo.com', authHeaderValue: '0000000000' },
|
|
{ status: 401, statusText: 'Unauthorized' }
|
|
)
|
|
expect(error.message).toBe('GET https://foo.com: Unauthorized - 401')
|
|
expect(error.hint).toBe('An authorization header was used: [hidden]')
|
|
expect(error.request.authHeaderValue).toBe('[hidden]')
|
|
})
|