Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/real-swans-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@forgerock/davinci-client': minor
---

Add MetadataCollector and error helper on client
5 changes: 5 additions & 0 deletions .changeset/thirty-badgers-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@forgerock/davinci-client': minor
---

Catch FIDO/WebAuthn DOMExeceptions and send them to DaVinci
26 changes: 13 additions & 13 deletions e2e/davinci-app/components/fido.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Ping Identity Corporation. All rights reserved.
* Copyright (c) 2025 - 2026 Ping Identity Corporation. All rights reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand Down Expand Up @@ -32,13 +32,13 @@ export default function fidoComponent(
console.log('fido.register response:', response);
if ('error' in response) {
console.error(response);
}

const error = updater(response);
if (error && 'error' in error) {
console.error(error.error.message);
} else {
const error = updater(response);
if (error && 'error' in error) {
console.error(error.error.message);
} else {
await submitForm();
}
await submitForm();
}
};
} else if (collector.type === 'FidoAuthenticationCollector') {
Expand All @@ -54,13 +54,13 @@ export default function fidoComponent(
console.log('fido.authenticate response:', response);
if ('error' in response) {
console.error(response);
}

const error = updater(response);
if (error && 'error' in error) {
console.error(error.error.message);
} else {
const error = updater(response);
if (error && 'error' in error) {
console.error(error.error.message);
} else {
await submitForm();
}
await submitForm();
}
};
}
Expand Down
36 changes: 36 additions & 0 deletions e2e/davinci-app/components/metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2026 Ping Identity Corporation. All rights reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
import type { MetadataCollector, MetadataError, Updater } from '@forgerock/davinci-client/types';

export default function metadataComponent(
formEl: HTMLFormElement,
updater: Updater<MetadataCollector>,
getMetadataError: (errorDetails: MetadataError) => MetadataError,
submitForm: () => Promise<void>,
) {
const successBtn = document.createElement('button');
successBtn.type = 'button';
successBtn.innerHTML = 'Metadata Success';

const errorBtn = document.createElement('button');
errorBtn.type = 'button';
errorBtn.innerHTML = 'Metadata Error';

formEl.appendChild(successBtn);
formEl.appendChild(errorBtn);

successBtn.onclick = async () => {
updater({ status: 'succeeded' });
await submitForm();
};

errorBtn.onclick = async () => {
const metadataError = getMetadataError({ code: 'ERROR_CODE', message: 'Operation cancelled' });
updater(metadataError);
await submitForm();
};
}
8 changes: 8 additions & 0 deletions e2e/davinci-app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import qrCodeComponent from './components/qr-code.js';
import formImageComponent from './components/form-image.js';
import pollingComponent from './components/polling.js';
import booleanComponent from './components/boolean.js';
import metadataComponent from './components/metadata.js';

const loggerFn = {
error: () => {
Expand Down Expand Up @@ -289,6 +290,13 @@ const urlParams = new URLSearchParams(window.location.search);
davinciClient.update(collector), // Returns an update function for this collector
submitForm,
);
} else if (collector.type === 'MetadataCollector') {
metadataComponent(
formEl, // You can ignore this; it's just for rendering
davinciClient.update(collector), // Returns an update function for this collector
davinciClient.getMetadataError,
submitForm,
);
} else if (collector.type === 'BooleanCollector') {
booleanComponent(formEl, collector, davinciClient.update(collector));
} else if (collector.type === 'ValidatedBooleanCollector') {
Expand Down
2 changes: 1 addition & 1 deletion e2e/davinci-app/server-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const serverConfigs: Record<string, DaVinciConfig> = {
},
},
/**
* Polling
* AutoCollectors: Polling, Metadata
*/
'31a587ce-9aa4-4f36-a09f-78cd8a0a74a0': {
clientId: '31a587ce-9aa4-4f36-a09f-78cd8a0a74a0',
Expand Down
24 changes: 22 additions & 2 deletions e2e/davinci-suites/src/fido.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright (c) 2025 - 2026 Ping Identity Corporation. All rights reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
import { test, expect, CDPSession } from '@playwright/test';
import { asyncEvents } from './utils/async-events.js';

Expand All @@ -10,6 +16,7 @@ test.use({ browserName: 'chromium' }); // ensure CDP/WebAuthn is available

test.beforeEach(async ({ context, page }) => {
cdp = await context.newCDPSession(page);
await expect(cdp).toBeDefined();
await cdp.send('WebAuthn.enable');

// A "platform" authenticator (aka internal) with UV+RK enabled is the usual default for passkeys.
Expand All @@ -27,8 +34,10 @@ test.beforeEach(async ({ context, page }) => {
});

test.afterEach(async () => {
await cdp.send('WebAuthn.removeVirtualAuthenticator', { authenticatorId });
await cdp.send('WebAuthn.disable');
if (authenticatorId) {
await cdp?.send('WebAuthn.removeVirtualAuthenticator', { authenticatorId });
}
await cdp?.send('WebAuthn.disable');
});

test.describe('FIDO/WebAuthn Tests', () => {
Expand All @@ -48,6 +57,10 @@ test.describe('FIDO/WebAuthn Tests', () => {
await page.getByLabel('Password').fill(password);
await page.getByRole('button', { name: 'Sign On' }).click();

if (!cdp || !authenticatorId) {
throw new Error('Missing virtual authenticator');
}

// Register WebAuthn credential
const { credentials: initialCredentials } = await cdp.send('WebAuthn.getCredentials', {
authenticatorId,
Expand Down Expand Up @@ -103,6 +116,13 @@ test.describe('FIDO/WebAuthn Tests', () => {
await page.getByLabel('Password').fill(password);
await page.getByRole('button', { name: 'Sign On' }).click();

await expect(cdp).toBeDefined;
await expect(authenticatorId).toBeDefined();

if (!cdp || !authenticatorId) {
throw new Error('Missing virtual authenticator');
}

// Register WebAuthn credential
const { credentials: initialCredentials } = await cdp.send('WebAuthn.getCredentials', {
authenticatorId,
Expand Down
40 changes: 40 additions & 0 deletions e2e/davinci-suites/src/metadata.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2026 Ping Identity Corporation. All rights reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
import { expect, test } from '@playwright/test';
import { asyncEvents } from './utils/async-events.js';

test.describe('Metadata Collector', () => {
const clientId = '31a587ce-9aa4-4f36-a09f-78cd8a0a74a0';
const davinciPolicy = '7793be21a14dd80c1d26b367e81ea985';

test('should submit with success status when metadata collection succeeds', async ({ page }) => {
const { navigate } = asyncEvents(page);
await navigate(`/?clientId=${clientId}&acr_values=${davinciPolicy}`);

await page.getByRole('button', { name: 'Sign On' }).click();
await expect(page.getByRole('button', { name: 'Metadata Success' })).toBeVisible();

await page.getByRole('button', { name: 'Metadata Success' }).click();

await expect(page.getByRole('heading', { name: 'Message' })).toBeVisible();
await expect(page.getByText('"status":"succeeded"')).toBeVisible();
});

test('should submit with error details when metadata collection fails', async ({ page }) => {
const { navigate } = asyncEvents(page);
await navigate(`/?clientId=${clientId}&acr_values=${davinciPolicy}`);

await page.getByRole('button', { name: 'Sign On' }).click();
await expect(page.getByRole('button', { name: 'Metadata Error' })).toBeVisible();

await page.getByRole('button', { name: 'Metadata Error' }).click();

await expect(page.getByRole('heading', { name: 'Message' })).toBeVisible();
await expect(page.getByText('"code":"ERROR_CODE"')).toBeVisible();
await expect(page.getByText('"message":"Operation cancelled"')).toBeVisible();
});
});
19 changes: 5 additions & 14 deletions e2e/davinci-suites/src/password-policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test.describe('ValidatedPasswordCollector — password policy (Example - Registr
try {
await deleteTestUser(page, email);
} catch (err) {
console.error(`[cleanup] Failed to delete test user ${email}:`, err);
throw new Error(`[cleanup] Failed to delete test user ${email}: ${JSON.stringify(err)}`);
}
}
});
Expand Down Expand Up @@ -146,26 +146,17 @@ test.describe('ValidatedPasswordCollector — password policy (Example - Registr
await page.locator('#userPassword').fill(password);

// Submit the form by calling submit() on the form element
await page.locator('form').evaluate((form: HTMLFormElement) => form.submit());
await page.getByRole('button', { name: 'Submit' }).click({ timeout: 10000 });

// Wait for the page to navigate to the next step
// The heading should change from "Example - Registration 1" to something else
await page.waitForFunction(
() => {
const heading = document.querySelector('h2');
return heading && !heading.textContent?.includes('Example - Registration');
},
{ timeout: 10000 },
);

// Verify we've moved to the next step
const heading = page.locator('h2').first();
await expect(heading).toBeVisible();
await expect(page.getByRole('heading', { name: 'Example - Registration' })).not.toBeVisible();

// If the flow shows a "Continue" button, click through to complete it
const continueBtn = page.getByRole('button', { name: 'Continue' });
if (await continueBtn.isVisible()) {
await continueBtn.click();
}

await expect(page.getByRole('heading', { name: 'Complete' })).toBeVisible();
});
});
Loading
Loading