mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-10 04:32:34 +09:00
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
import {createAuthHarness, createTestAccount} from '@app/api/auth/tests/AuthTestUtils';
|
|
import {
|
|
createTotpSecret,
|
|
decodeBase64URL,
|
|
generateTotpCode,
|
|
type WebAuthnRegistrationOptions,
|
|
} from '@app/api/auth/tests/WebAuthnTestUtils';
|
|
import type {ApiTestHarness} from '@app/api/test/ApiTestHarness';
|
|
import {createBuilder} from '@app/api/test/TestRequestBuilder';
|
|
import {afterAll, beforeAll, beforeEach, describe, expect, it} from 'vitest';
|
|
|
|
describe('WebAuthn registration user handle', () => {
|
|
let harness: ApiTestHarness;
|
|
beforeAll(async () => {
|
|
harness = await createAuthHarness();
|
|
});
|
|
beforeEach(async () => {
|
|
await harness.reset();
|
|
});
|
|
afterAll(async () => {
|
|
await harness?.shutdown();
|
|
});
|
|
it('ensures registration options include the stable user identifier', async () => {
|
|
const account = await createTestAccount(harness);
|
|
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();
|
|
const handle = decodeBase64URL(regOptions.user.id).toString();
|
|
expect(handle).toBe(account.userId);
|
|
});
|
|
});
|