374724a7a3
- pragmarx/google2fa@^9.0 для TOTP RFC 6238.
- AuthController::login изменён: при totp_enabled=true НЕ делает Auth::login,
сохраняет auth.pending_user_id+pending_remember в session, возвращает
requires_2fa=true. /me=401 пока 2FA не пройдена.
- AuthController::verifyTwoFactor: читает pending_user_id, верифицирует TOTP
через Google2FA::verifyKey($secret, $code, window: 1) (окно ±1 = 30s).
Success → Auth::login + regenerate + clear pending + last_login_at.
- VerifyTwoFactorRequest: regex /^\d{6}$/.
- /api/auth/2fa/verify публичный (нет session-auth до verify).
Frontend:
- auth-store::login: при requires_2fa=true user остаётся null (иначе
isAuthenticated=true и guard пустит на /dashboard минуя 2FA).
- auth-store::verifyTwoFactor action.
- api/auth.ts::verifyTwoFactor(code).
- TwoFactorView: onMounted redirect на /login если нет pending state;
submit → verify → /dashboard; на error - clear code + focus first cell.
userEmail из auth.user?.email.
Pest +6 (всего 67/67 за 6.97s, 194 assertions): login для 2FA НЕ создаёт
session + verify success/неверный код/без login/валидация формата +
после verify /me=200.
Vitest +3 (всего 142/142 за 10.75s): login pending vs success state +
verifyTwoFactor success/reject. TwoFactorView spec получил setActivePinia
+ requires2fa=true для bypass onMounted-redirect.
PHPStan baseline +26 Pest TestCall warnings (накопительно).
Регресс: pint+stan passed; vitest 142/142; vite build 908ms;
story:build 21/28 за 31.28s; Pest 67/67 за 6.97s.
CLAUDE.md v1.33->v1.34, реестр Открытых_вопросов v1.42->v1.43.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
54 lines
2.2 KiB
TypeScript
54 lines
2.2 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { mount } from '@vue/test-utils';
|
|
import { createPinia, setActivePinia } from 'pinia';
|
|
import { createVuetify } from 'vuetify';
|
|
import { createRouter, createMemoryHistory } from 'vue-router';
|
|
import TwoFactorView from '../../resources/js/views/auth/TwoFactorView.vue';
|
|
import { useAuthStore } from '../../resources/js/stores/auth';
|
|
|
|
const mountTwoFactor = async () => {
|
|
setActivePinia(createPinia());
|
|
// Эмулируем pending-2FA state — иначе onMounted редиректит на /login.
|
|
const auth = useAuthStore();
|
|
auth.requires2fa = true;
|
|
|
|
const router = createRouter({
|
|
history: createMemoryHistory(),
|
|
routes: [
|
|
{ path: '/2fa', component: TwoFactorView },
|
|
{ path: '/login', component: { template: '<div>stub</div>' } },
|
|
{ path: '/dashboard', component: { template: '<div>stub</div>' } },
|
|
{ path: '/recovery', component: { template: '<div>stub</div>' } },
|
|
],
|
|
});
|
|
await router.push('/2fa');
|
|
await router.isReady();
|
|
return mount(TwoFactorView, {
|
|
global: { plugins: [createVuetify(), router] },
|
|
});
|
|
};
|
|
|
|
describe('TwoFactorView.vue', () => {
|
|
it('монтируется и содержит заголовок', async () => {
|
|
const wrapper = await mountTwoFactor();
|
|
expect(wrapper.text()).toContain('Двухфакторная проверка');
|
|
});
|
|
|
|
it('содержит ровно 6 input-cell для кода', async () => {
|
|
const wrapper = await mountTwoFactor();
|
|
const cells = wrapper.findAll('.code-cell');
|
|
expect(cells).toHaveLength(6);
|
|
// Каждая cell — numeric inputmode + maxlength=1.
|
|
cells.forEach((cell) => {
|
|
expect(cell.attributes('inputmode')).toBe('numeric');
|
|
expect(cell.attributes('maxlength')).toBe('1');
|
|
});
|
|
});
|
|
|
|
it('содержит ссылку на резервный код', async () => {
|
|
const wrapper = await mountTwoFactor();
|
|
const links = wrapper.findAll('a').map((a) => a.text());
|
|
expect(links.some((t) => t.includes('резервный код'))).toBe(true);
|
|
});
|
|
});
|