Skip to content

Commit cb7b20c

Browse files
authored
Merge pull request #501 from ForgeRock/journey-client-tests
Journey client tests
2 parents b6d3630 + 00143a5 commit cb7b20c

File tree

20 files changed

+994
-78
lines changed

20 files changed

+994
-78
lines changed
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
* @forgerock/javascript-sdk
3+
*
4+
* response.webauthn.js
5+
*
6+
* Copyright (c) 2020 - 2025 Ping Identity Corporation. All rights reserved.
7+
* This software may be modified and distributed under the terms
8+
* of the MIT license. See the LICENSE file for details.
9+
*/
10+
11+
/**
12+
* WebAuthn registration initialization response
13+
* Contains MetadataCallback for WebAuthn and HiddenValueCallback for credential
14+
*/
15+
export const webAuthnRegistrationInit = {
16+
authId: 'webauthn-registration-init',
17+
callbacks: [
18+
{
19+
type: 'MetadataCallback',
20+
output: [
21+
{
22+
name: 'data',
23+
value: {
24+
_type: 'WebAuthn',
25+
_action: 'webauthn_registration',
26+
challenge: 'dGVzdC1jaGFsbGVuZ2UtZm9yLXdlYmF1dGhu',
27+
relyingPartyId: 'localhost',
28+
relyingPartyName: 'ForgeRock',
29+
userId: 'dGVzdC11c2VyLWlk',
30+
userName: 'testuser',
31+
displayName: 'Test User',
32+
timeout: 60000,
33+
attestationPreference: 'none',
34+
authenticatorAttachment: 'platform',
35+
requireResidentKey: false,
36+
userVerification: 'preferred',
37+
pubKeyCredParams: [
38+
{ type: 'public-key', alg: -7 },
39+
{ type: 'public-key', alg: -257 },
40+
],
41+
},
42+
},
43+
],
44+
},
45+
{
46+
type: 'HiddenValueCallback',
47+
output: [
48+
{
49+
name: 'value',
50+
value: '',
51+
},
52+
{
53+
name: 'id',
54+
value: 'webAuthnOutcome',
55+
},
56+
],
57+
input: [
58+
{
59+
name: 'IDToken2',
60+
value: '',
61+
},
62+
],
63+
},
64+
],
65+
};
66+
67+
/**
68+
* Returns the recovery codes display response
69+
* This simulates the step after WebAuthn registration where recovery codes are shown
70+
*/
71+
export function getRecoveryCodesDisplay() {
72+
const recoveryCodes = [
73+
'ABC123DEF4',
74+
'GHI567JKL8',
75+
'MNO901PQR2',
76+
'STU345VWX6',
77+
'YZA789BCD0',
78+
'EFG123HIJ4',
79+
'KLM567NOP8',
80+
'QRS901TUV2',
81+
'WXY345ZAB6',
82+
'CDE789FGH0',
83+
];
84+
85+
// Build the recovery codes HTML similar to what AM generates
86+
const codesHtml = recoveryCodes
87+
.map((code) => `"<div class=\\"text-center\\">\\n" +\n "${code}\\n" +\n "</div>\\n" +`)
88+
.join('\n ');
89+
90+
const scriptValue = `/*
91+
* Copyright 2018 ForgeRock AS. All Rights Reserved
92+
*
93+
* Use of this code requires a commercial software license with ForgeRock AS.
94+
* or with one of its affiliates. All use shall be exclusively subject
95+
* to such license between the licensee and ForgeRock AS.
96+
*/
97+
98+
var newLocation = document.getElementById("wrapper");
99+
var oldHtml = newLocation.getElementsByTagName("fieldset")[0].innerHTML;
100+
newLocation.getElementsByTagName("fieldset")[0].innerHTML = "<div class=\\"panel panel-default\\">\\n" +
101+
" <div class=\\"panel-body text-center\\">\\n" +
102+
" <h3>Your Recovery Codes</h3>\\n" +
103+
" <h4>You must make a copy of these recovery codes. They cannot be displayed again.</h4>\\n" +
104+
" </div>\\n" +
105+
${codesHtml}
106+
"<div class=\\"panel-body text-center\\">\\n" +
107+
" <p>Use one of these codes to authenticate if you lose your device, which has been named: <em>New Security Key</em></p>\\n" +
108+
"</div>\\n" +
109+
"</div>" + oldHtml;
110+
document.body.appendChild(newLocation);
111+
`;
112+
113+
return {
114+
authId: 'recovery-codes-display',
115+
callbacks: [
116+
{
117+
type: 'TextOutputCallback',
118+
output: [
119+
{
120+
name: 'message',
121+
value: scriptValue,
122+
},
123+
{
124+
name: 'messageType',
125+
value: '4',
126+
},
127+
],
128+
},
129+
{
130+
type: 'ConfirmationCallback',
131+
output: [
132+
{
133+
name: 'prompt',
134+
value: '',
135+
},
136+
{
137+
name: 'messageType',
138+
value: 0,
139+
},
140+
{
141+
name: 'options',
142+
value: ['I have saved my recovery codes'],
143+
},
144+
{
145+
name: 'optionType',
146+
value: -1,
147+
},
148+
{
149+
name: 'defaultOption',
150+
value: 0,
151+
},
152+
],
153+
input: [
154+
{
155+
name: 'IDToken2',
156+
value: 0,
157+
},
158+
],
159+
},
160+
],
161+
};
162+
}
163+
164+
/**
165+
* Auth success response for WebAuthn flow
166+
*/
167+
export const authSuccess = {
168+
tokenId: 'webauthn-session-token',
169+
successUrl: '/console',
170+
realm: '/',
171+
};

e2e/am-mock-api/src/app/responses.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,3 +1347,89 @@ export const recaptchaEnterpriseCallback = {
13471347
},
13481348
],
13491349
};
1350+
1351+
export const qrCodeCallbacksResponse = {
1352+
authId: 'qrcode-journey-confirmation',
1353+
callbacks: [
1354+
{
1355+
type: 'TextOutputCallback',
1356+
output: [
1357+
{
1358+
name: 'message',
1359+
value:
1360+
'Scan the QR code image below with the ForgeRock Authenticator app to register your device with your login.',
1361+
},
1362+
{
1363+
name: 'messageType',
1364+
value: '0',
1365+
},
1366+
],
1367+
},
1368+
{
1369+
type: 'TextOutputCallback',
1370+
output: [
1371+
{
1372+
name: 'message',
1373+
value:
1374+
// eslint-disable-next-line quotes
1375+
"window.QRCodeReader.createCode({\n id: 'callback_0',\n text: 'otpauth\\x3A\\x2F\\x2Ftotp\\x2FForgeRock\\x3Ajlowery\\x3Fperiod\\x3D30\\x26b\\x3D032b75\\x26digits\\x3D6\\x26secret\\QITSTC234FRIU8DD987DW3VPICFY\\x3D\\x3D\\x3D\\x3D\\x3D\\x3D\\x26issuer\\x3DForgeRock',\n version: '20',\n code: 'L'\n});",
1376+
},
1377+
{
1378+
name: 'messageType',
1379+
value: '4',
1380+
},
1381+
],
1382+
},
1383+
{
1384+
type: 'HiddenValueCallback',
1385+
output: [
1386+
{
1387+
name: 'value',
1388+
value:
1389+
'otpauth://totp/ForgeRock:jlowery?secret=QITSTC234FRIU8DD987DW3VPICFY======&issuer=ForgeRock&period=30&digits=6&b=032b75',
1390+
},
1391+
{
1392+
name: 'id',
1393+
value: 'mfaDeviceRegistration',
1394+
},
1395+
],
1396+
input: [
1397+
{
1398+
name: 'IDToken3',
1399+
value: 'mfaDeviceRegistration',
1400+
},
1401+
],
1402+
},
1403+
{
1404+
type: 'ConfirmationCallback',
1405+
output: [
1406+
{
1407+
name: 'prompt',
1408+
value: '',
1409+
},
1410+
{
1411+
name: 'messageType',
1412+
value: 0,
1413+
},
1414+
{
1415+
name: 'options',
1416+
value: ['Next'],
1417+
},
1418+
{
1419+
name: 'optionType',
1420+
value: -1,
1421+
},
1422+
{
1423+
name: 'defaultOption',
1424+
value: 0,
1425+
},
1426+
],
1427+
input: [
1428+
{
1429+
name: 'IDToken4',
1430+
value: 0,
1431+
},
1432+
],
1433+
},
1434+
],
1435+
};

0 commit comments

Comments
 (0)