35 lines
905 B
TypeScript
35 lines
905 B
TypeScript
/** @jest-environment node */
|
|
|
|
import { authOptions } from '@/lib/auth'
|
|
import { prisma } from '@/lib/prisma'
|
|
|
|
jest.mock('@/lib/prisma', () => ({
|
|
prisma: {
|
|
user: {
|
|
findUnique: jest.fn(),
|
|
update: jest.fn(),
|
|
},
|
|
},
|
|
}))
|
|
|
|
jest.mock('@/lib/dingtalk-login', () => ({
|
|
authorizeDingtalkH5UserForNextAuth: jest.fn(),
|
|
}))
|
|
|
|
jest.mock('@/lib/auth-cookie', () => ({
|
|
resolveSecureAuthCookieForCurrentRequest: jest.fn().mockResolvedValue(false),
|
|
}))
|
|
|
|
describe('credentials provider legacy DingTalk password', () => {
|
|
test('固定钉钉自动登录口令不能再用于邮箱密码登录', async () => {
|
|
const provider = authOptions.providers[0] as any
|
|
|
|
await expect(provider.options.authorize({
|
|
email: 'user@example.com',
|
|
password: 'dingtalk_auto_login',
|
|
})).rejects.toThrow('邮箱或密码错误')
|
|
|
|
expect(prisma.user.findUnique).not.toHaveBeenCalled()
|
|
})
|
|
})
|