Something went wrong. Try again.
A free and open source instant messaging and VoIP platform built for friends, groups, and communities.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586/* * Copyright (C) 2026 Fluxer Contributors * * This file is part of Fluxer. * * Fluxer is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Fluxer is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Fluxer. If not, see <https://www.gnu.org/licenses/>. */
import {createAuthHarness, createTestAccount} from '@fluxer/api/src/auth/tests/AuthTestUtils';import { createRegistrationResponse, createTotpSecret, createWebAuthnDevice, generateTotpCode, type WebAuthnRegistrationOptions,} from '@fluxer/api/src/auth/tests/WebAuthnTestUtils';import type {ApiTestHarness} from '@fluxer/api/src/test/ApiTestHarness';import {createBuilder} from '@fluxer/api/src/test/TestRequestBuilder';import {afterAll, beforeAll, beforeEach, describe, expect, it} from 'vitest';
describe('WebAuthn error localization', () => { let harness: ApiTestHarness;
beforeAll(async () => { harness = await createAuthHarness(); });
beforeEach(async () => { await harness.reset(); });
afterAll(async () => { await harness?.shutdown(); });
it('ensures WebAuthn registration errors return localized messages', async () => { const account = await createTestAccount(harness); const device = createWebAuthnDevice(); const secret = createTotpSecret();
await createBuilder(harness, account.token) .post('/users/@me/mfa/totp/enable') .body({secret, code: generateTotpCode(secret), password: account.password}) .expect(200) .execute();
const regOptions = await createBuilder<WebAuthnRegistrationOptions>(harness, account.token) .post('/users/@me/mfa/webauthn/credentials/registration-options') .body({mfa_method: 'totp', mfa_code: generateTotpCode(secret)}) .execute();
if (regOptions.rp.id) { device.rpId = regOptions.rp.id; }
const badChallenge = `${regOptions.challenge}-tampered`; const registrationResponse = createRegistrationResponse(device, regOptions, 'Localized error');
const errResp = await createBuilder<{code: string; message: string}>(harness, account.token) .post('/users/@me/mfa/webauthn/credentials') .body({ response: registrationResponse, challenge: badChallenge, name: 'Localized error', mfa_method: 'totp', mfa_code: generateTotpCode(secret), }) .expect(400) .execute();
expect(errResp.code).toBe('INVALID_WEBAUTHN_CREDENTIAL'); expect(errResp.message).toBe('Failed to verify WebAuthn credential.'); });});