summaryrefslogtreecommitdiffhomepage
path: root/packages/server/src/authentication/generateAuthenticationOptions.test.ts
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2024-04-12 13:38:30 -0700
committerMatthew Miller <matthew@millerti.me>2024-04-12 13:38:30 -0700
commiteb1988a9cff91988263f39101e6769c39cf27b60 (patch)
treecdbdfbd45f0a5c5a0cf7250a7454ccfb1e954df6 /packages/server/src/authentication/generateAuthenticationOptions.test.ts
parentb2a6e96005660431dc4598eb5d717802b6c238e3 (diff)
Require rpID arg when generating auth options
Diffstat (limited to 'packages/server/src/authentication/generateAuthenticationOptions.test.ts')
-rw-r--r--packages/server/src/authentication/generateAuthenticationOptions.test.ts29
1 files changed, 13 insertions, 16 deletions
diff --git a/packages/server/src/authentication/generateAuthenticationOptions.test.ts b/packages/server/src/authentication/generateAuthenticationOptions.test.ts
index 49d668e..d186372 100644
--- a/packages/server/src/authentication/generateAuthenticationOptions.test.ts
+++ b/packages/server/src/authentication/generateAuthenticationOptions.test.ts
@@ -7,8 +7,11 @@ import { generateAuthenticationOptions } from './generateAuthenticationOptions.t
const challengeString = 'dG90YWxseXJhbmRvbXZhbHVl';
const challengeBuffer = isoBase64URL.toBuffer(challengeString);
+const rpID = 'simplewebauthn.dev';
+
Deno.test('should generate credential request options suitable for sending via JSON', async () => {
const options = await generateAuthenticationOptions({
+ rpID,
allowCredentials: [
{
id: '1234',
@@ -24,6 +27,7 @@ Deno.test('should generate credential request options suitable for sending via J
});
assertEquals(options, {
+ rpId: 'simplewebauthn.dev',
// base64url-encoded
challenge: challengeString,
allowCredentials: [
@@ -41,12 +45,12 @@ Deno.test('should generate credential request options suitable for sending via J
timeout: 1,
userVerification: 'preferred',
extensions: undefined,
- rpId: undefined,
});
});
Deno.test('defaults to 60 seconds if no timeout is specified', async () => {
const options = await generateAuthenticationOptions({
+ rpID,
challenge: challengeBuffer,
allowCredentials: [
{ id: '1234' },
@@ -59,6 +63,7 @@ Deno.test('defaults to 60 seconds if no timeout is specified', async () => {
Deno.test('should set userVerification to "preferred" if not specified', async () => {
const options = await generateAuthenticationOptions({
+ rpID,
challenge: challengeBuffer,
allowCredentials: [
{ id: '1234' },
@@ -70,18 +75,18 @@ Deno.test('should set userVerification to "preferred" if not specified', async (
});
Deno.test('should not set allowCredentials if not specified', async () => {
- const options = await generateAuthenticationOptions({ rpID: 'test' });
+ const options = await generateAuthenticationOptions({ rpID });
assertEquals(options.allowCredentials, undefined);
});
Deno.test('should generate without params', async () => {
- const options = await generateAuthenticationOptions();
+ const options = await generateAuthenticationOptions({ rpID });
const { challenge, ...otherFields } = options;
assertEquals(otherFields, {
allowCredentials: undefined,
extensions: undefined,
- rpId: undefined,
+ rpId: rpID,
timeout: 60000,
userVerification: 'preferred',
});
@@ -90,6 +95,7 @@ Deno.test('should generate without params', async () => {
Deno.test('should set userVerification if specified', async () => {
const options = await generateAuthenticationOptions({
+ rpID,
challenge: challengeBuffer,
allowCredentials: [
{ id: '1234' },
@@ -103,6 +109,7 @@ Deno.test('should set userVerification if specified', async () => {
Deno.test('should set extensions if specified', async () => {
const options = await generateAuthenticationOptions({
+ rpID,
challenge: challengeBuffer,
allowCredentials: [
{ id: '1234' },
@@ -117,6 +124,7 @@ Deno.test('should set extensions if specified', async () => {
Deno.test('should generate a challenge if one is not provided', async () => {
// @ts-ignore 2345
const options = await generateAuthenticationOptions({
+ rpID,
allowCredentials: [
{ id: '1234' },
{ id: '5678' },
@@ -130,6 +138,7 @@ Deno.test('should generate a challenge if one is not provided', async () => {
Deno.test('should treat string challenges as UTF-8 strings', async () => {
const options = await generateAuthenticationOptions({
+ rpID,
challenge: 'こんにちは',
});
@@ -138,15 +147,3 @@ Deno.test('should treat string challenges as UTF-8 strings', async () => {
'44GT44KT44Gr44Gh44Gv',
);
});
-
-Deno.test('should set rpId if specified', async () => {
- const rpID = 'simplewebauthn.dev';
-
- const opts = await generateAuthenticationOptions({
- allowCredentials: [],
- rpID,
- });
-
- assertExists(opts.rpId);
- assertEquals(opts.rpId, rpID);
-});