diff options
Diffstat (limited to 'packages/server/src/authentication/generateAuthenticationOptions.test.ts')
-rw-r--r-- | packages/server/src/authentication/generateAuthenticationOptions.test.ts | 92 |
1 files changed, 44 insertions, 48 deletions
diff --git a/packages/server/src/authentication/generateAuthenticationOptions.test.ts b/packages/server/src/authentication/generateAuthenticationOptions.test.ts index 95dc5a1..f8ed0ca 100644 --- a/packages/server/src/authentication/generateAuthenticationOptions.test.ts +++ b/packages/server/src/authentication/generateAuthenticationOptions.test.ts @@ -1,28 +1,24 @@ -import { - assert, - assertEquals, - assertExists, -} from "https://deno.land/std@0.198.0/assert/mod.ts"; +import { assert, assertEquals, assertExists } from 'https://deno.land/std@0.198.0/assert/mod.ts'; -import { isoBase64URL, isoUint8Array } from "../helpers/iso/index.ts"; +import { isoBase64URL, isoUint8Array } from '../helpers/iso/index.ts'; -import { generateAuthenticationOptions } from "./generateAuthenticationOptions.ts"; +import { generateAuthenticationOptions } from './generateAuthenticationOptions.ts'; -const challengeString = "dG90YWxseXJhbmRvbXZhbHVl"; +const challengeString = 'dG90YWxseXJhbmRvbXZhbHVl'; const challengeBuffer = isoBase64URL.toBuffer(challengeString); -Deno.test("should generate credential request options suitable for sending via JSON", async () => { +Deno.test('should generate credential request options suitable for sending via JSON', async () => { const options = await generateAuthenticationOptions({ allowCredentials: [ { - id: isoUint8Array.fromASCIIString("1234"), - type: "public-key", - transports: ["usb", "nfc"], + id: isoUint8Array.fromASCIIString('1234'), + type: 'public-key', + transports: ['usb', 'nfc'], }, { - id: isoUint8Array.fromASCIIString("5678"), - type: "public-key", - transports: ["internal"], + id: isoUint8Array.fromASCIIString('5678'), + type: 'public-key', + transports: ['internal'], }, ], timeout: 1, @@ -34,29 +30,29 @@ Deno.test("should generate credential request options suitable for sending via J challenge: challengeString, allowCredentials: [ { - id: "MTIzNA", - type: "public-key", - transports: ["usb", "nfc"], + id: 'MTIzNA', + type: 'public-key', + transports: ['usb', 'nfc'], }, { - id: "NTY3OA", - type: "public-key", - transports: ["internal"], + id: 'NTY3OA', + type: 'public-key', + transports: ['internal'], }, ], timeout: 1, - userVerification: "preferred", + userVerification: 'preferred', extensions: undefined, rpId: undefined, }); }); -Deno.test("defaults to 60 seconds if no timeout is specified", async () => { +Deno.test('defaults to 60 seconds if no timeout is specified', async () => { const options = await generateAuthenticationOptions({ challenge: challengeBuffer, allowCredentials: [ - { id: isoUint8Array.fromASCIIString("1234"), type: "public-key" }, - { id: isoUint8Array.fromASCIIString("5678"), type: "public-key" }, + { id: isoUint8Array.fromASCIIString('1234'), type: 'public-key' }, + { id: isoUint8Array.fromASCIIString('5678'), type: 'public-key' }, ], }); @@ -67,21 +63,21 @@ Deno.test('should set userVerification to "preferred" if not specified', async ( const options = await generateAuthenticationOptions({ challenge: challengeBuffer, allowCredentials: [ - { id: isoUint8Array.fromASCIIString("1234"), type: "public-key" }, - { id: isoUint8Array.fromASCIIString("5678"), type: "public-key" }, + { id: isoUint8Array.fromASCIIString('1234'), type: 'public-key' }, + { id: isoUint8Array.fromASCIIString('5678'), type: 'public-key' }, ], }); - assertEquals(options.userVerification, "preferred"); + assertEquals(options.userVerification, 'preferred'); }); -Deno.test("should not set allowCredentials if not specified", async () => { - const options = await generateAuthenticationOptions({ rpID: "test" }); +Deno.test('should not set allowCredentials if not specified', async () => { + const options = await generateAuthenticationOptions({ rpID: 'test' }); assertEquals(options.allowCredentials, undefined); }); -Deno.test("should generate without params", async () => { +Deno.test('should generate without params', async () => { const options = await generateAuthenticationOptions(); const { challenge, ...otherFields } = options; assertEquals(otherFields, { @@ -89,42 +85,42 @@ Deno.test("should generate without params", async () => { extensions: undefined, rpId: undefined, timeout: 60000, - userVerification: "preferred", + userVerification: 'preferred', }); - assertEquals(typeof challenge, "string"); + assertEquals(typeof challenge, 'string'); }); -Deno.test("should set userVerification if specified", async () => { +Deno.test('should set userVerification if specified', async () => { const options = await generateAuthenticationOptions({ challenge: challengeBuffer, allowCredentials: [ - { id: isoUint8Array.fromASCIIString("1234"), type: "public-key" }, - { id: isoUint8Array.fromASCIIString("5678"), type: "public-key" }, + { id: isoUint8Array.fromASCIIString('1234'), type: 'public-key' }, + { id: isoUint8Array.fromASCIIString('5678'), type: 'public-key' }, ], - userVerification: "required", + userVerification: 'required', }); - assertEquals(options.userVerification, "required"); + assertEquals(options.userVerification, 'required'); }); -Deno.test("should set extensions if specified", async () => { +Deno.test('should set extensions if specified', async () => { const options = await generateAuthenticationOptions({ challenge: challengeBuffer, allowCredentials: [ - { id: isoUint8Array.fromASCIIString("1234"), type: "public-key" }, - { id: isoUint8Array.fromASCIIString("5678"), type: "public-key" }, + { id: isoUint8Array.fromASCIIString('1234'), type: 'public-key' }, + { id: isoUint8Array.fromASCIIString('5678'), type: 'public-key' }, ], - extensions: { appid: "simplewebauthn" }, + extensions: { appid: 'simplewebauthn' }, }); - assertEquals(options.extensions, { appid: "simplewebauthn" }); + assertEquals(options.extensions, { appid: 'simplewebauthn' }); }); -Deno.test("should generate a challenge if one is not provided", async () => { +Deno.test('should generate a challenge if one is not provided', async () => { const opts = { allowCredentials: [ - { id: isoUint8Array.fromASCIIString("1234"), type: "public-key" }, - { id: isoUint8Array.fromASCIIString("5678"), type: "public-key" }, + { id: isoUint8Array.fromASCIIString('1234'), type: 'public-key' }, + { id: isoUint8Array.fromASCIIString('5678'), type: 'public-key' }, ], }; @@ -136,8 +132,8 @@ Deno.test("should generate a challenge if one is not provided", async () => { assert(isoBase64URL.isBase64url(options.challenge)); }); -Deno.test("should set rpId if specified", async () => { - const rpID = "simplewebauthn.dev"; +Deno.test('should set rpId if specified', async () => { + const rpID = 'simplewebauthn.dev'; const opts = await generateAuthenticationOptions({ allowCredentials: [], |