MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / enrollViaService

Function enrollViaService

apps/api/tests/api/auth/mfa.routes.test.ts:71–100  ·  view source on GitHub ↗
(
  userId: string
)

Source from the content-addressed store, hash-verified

69 });
70
71const enrollViaService = async (
72 userId: string
73): Promise<{ secretBase32: string; recoveryCodes: string[] }> => {
74 const setup = await mfaService.setup(userId, PASSWORD);
75 const staged = await cacheService.get<{ secretEncrypted: string }>(
76 MFA_CACHE_KEYS.setup(userId)
77 );
78
79 if (staged === null) {
80 throw new Error("setup did not stage a secret");
81 }
82
83 const secretBase32 = decryptString(staged.secretEncrypted);
84
85 await mfaService.verifySetup(userId, totpFor(secretBase32));
86
87 /*
88 * Verifying setup writes the current TOTP step into mfaLastTotpStep
89 * for replay protection. The route tests then immediately try to log
90 * in inside that same 30-second window, which the replay guard would
91 * otherwise reject. Clearing the step is safe — a real user picks
92 * up the same protection on their next verify.
93 */
94 await db
95 .update(users)
96 .set({ mfaLastTotpStep: null })
97 .where(eq(users.id, userId));
98
99 return { secretBase32, recoveryCodes: setup.recoveryCodes };
100};
101
102describe("MFA routes", () => {
103 beforeEach(async () => {

Callers 1

mfa.routes.test.tsFile · 0.85

Calls 6

decryptStringFunction · 0.90
totpForFunction · 0.85
setupMethod · 0.80
verifySetupMethod · 0.80
updateMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected