Files
FileHost/server/utils/login-captcha.test.ts
T
O96u ff20f97522 release: v1.2.1 — login captcha, docs site, and bug fixes
Add slider captcha for web login, VitePress documentation on GitHub Pages,
and fixes for gallery delete refresh, pagination jump, and copy-format persistence.
2026-08-29 11:42:18 +08:00

28 lines
950 B
TypeScript

import { describe, expect, it } from 'vitest'
import {
__peekLoginCaptchaTargetForTests,
__resetLoginCaptchaStoreForTests,
confirmLoginCaptcha,
createLoginCaptchaChallenge,
verifyLoginCaptcha
} from './login-captcha'
describe('login-captcha', () => {
it('requires confirm before login verify', () => {
__resetLoginCaptchaStoreForTests()
const { id } = createLoginCaptchaChallenge()
const target = __peekLoginCaptchaTargetForTests(id)!
expect(verifyLoginCaptcha(id, target)).toBe(false)
expect(confirmLoginCaptcha(id, target)).toBe(true)
expect(verifyLoginCaptcha(id, target)).toBe(true)
expect(verifyLoginCaptcha(id, target)).toBe(false)
})
it('rejects position outside tolerance', () => {
__resetLoginCaptchaStoreForTests()
const { id } = createLoginCaptchaChallenge()
const target = __peekLoginCaptchaTargetForTests(id)!
expect(confirmLoginCaptcha(id, target + 10)).toBe(false)
})
})