refactor: 统一API鉴权并提升代码健壮性
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user