26 lines
853 B
TypeScript
26 lines
853 B
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { isValidApiKey } from './auth'
|
|
|
|
describe('isValidApiKey', () => {
|
|
it('returns false when provided key is missing', () => {
|
|
expect(isValidApiKey(undefined, 'a'.repeat(32))).toBe(false)
|
|
expect(isValidApiKey(null, 'a'.repeat(32))).toBe(false)
|
|
})
|
|
|
|
it('returns false when expected key is missing', () => {
|
|
expect(isValidApiKey('a'.repeat(32), undefined)).toBe(false)
|
|
})
|
|
|
|
it('returns false when key lengths differ', () => {
|
|
expect(isValidApiKey('a'.repeat(31), 'a'.repeat(32))).toBe(false)
|
|
})
|
|
|
|
it('returns false when keys have same length but different value', () => {
|
|
expect(isValidApiKey('b'.repeat(32), 'a'.repeat(32))).toBe(false)
|
|
})
|
|
|
|
it('returns true when keys match exactly', () => {
|
|
expect(isValidApiKey('a'.repeat(32), 'a'.repeat(32))).toBe(true)
|
|
})
|
|
})
|