fix(backend): fix tests

This commit is contained in:
kakkokari-gtyih 2026-06-22 17:11:23 +09:00
commit 9d949618ba

View file

@ -6,6 +6,7 @@
import { Inject, Injectable } from '@nestjs/common';
import * as Redis from 'ioredis';
import * as OTPAuth from 'otpauth';
import { createHash } from 'node:crypto';
import { DI } from '@/di-symbols.js';
import type { MiUserProfile, UserProfilesRepository, UsersRepository } from '@/models/_.js';
import { bindThis } from '@/decorators.js';
@ -58,8 +59,11 @@ export class UserAuthService {
// 4. totp.counter() を用い、同じタイムスタンプから基準ステップを取得
const currentStep = totp.counter({ timestamp: now });
const step = currentStep + delta;
const secretFingerprint = createHash('sha256')
.update(profile.twoFactorSecret ?? '')
.digest('base64url');
const usedTokenRedisKey = `2fa:used:${profile.userId}:${step}`;
const usedTokenRedisKey = `2fa:used:${profile.userId}:${secretFingerprint}:${step}`;
// 5. TTL有効期限の設定
const ttl = timeStep * (validationWindow * 2 + 1);