-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
1,212 additions
and
373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,3 +61,5 @@ users/* | |
docs/packages/javascript-sdk | ||
**/playwright-report | ||
**/playwright/.cache | ||
|
||
.nx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* @forgerock/javascript-sdk | ||
* | ||
* autoscript.ts | ||
* | ||
* Copyright (c) 2020 ForgeRock. All rights reserved. | ||
* This software may be modified and distributed under the terms | ||
* of the MIT license. See the LICENSE file for details. | ||
*/ | ||
// @ts-nocheck | ||
import * as forgerock from '@forgerock/javascript-sdk'; | ||
import { delay as rxDelay, map, mergeMap } from 'rxjs/operators'; | ||
import { from } from 'rxjs'; | ||
|
||
function autoscript() { | ||
const delay = 0; | ||
|
||
const url = new URL(window.location.href); | ||
const amUrl = url.searchParams.get('amUrl') || 'https://auth.example.com:9443/am'; | ||
const realmPath = url.searchParams.get('realmPath') || 'root'; | ||
const un = url.searchParams.get('un') || 'sdkuser'; | ||
const pw = url.searchParams.get('pw') || 'password'; | ||
const tree = url.searchParams.get('tree') || 'QRCodeTest'; | ||
|
||
console.log('Configure the SDK'); | ||
forgerock.Config.set({ | ||
realmPath, | ||
tree, | ||
serverConfig: { | ||
baseUrl: amUrl, | ||
}, | ||
}); | ||
|
||
try { | ||
forgerock.SessionManager.logout(); | ||
} catch (err) { | ||
// Do nothing | ||
} | ||
|
||
console.log('Initiate first step with `undefined`'); | ||
// Wrapping in setTimeout to give the test time to bind listener to console.log | ||
setTimeout(function () { | ||
from(forgerock.FRAuth.next()) | ||
.pipe( | ||
mergeMap((step) => { | ||
console.log('Set values on auth tree callbacks for submission'); | ||
const unCb = step.getCallbackOfType('NameCallback'); | ||
unCb.setName(un); | ||
|
||
const pwCb = step.getCallbackOfType('PasswordCallback'); | ||
pwCb.setPassword(pw); | ||
|
||
return forgerock.FRAuth.next(step); | ||
}), | ||
rxDelay(delay), | ||
mergeMap((step) => { | ||
console.log('Register MFA with QR Code'); | ||
const isQRCodeStep = forgerock.FRQRCode.isQRCodeStep(step); | ||
if (!isQRCodeStep) { | ||
throw new Error('Did not get expected QR Code step'); | ||
} | ||
|
||
const { message, use, uri } = forgerock.FRQRCode.getQRCodeData(step); | ||
if (!message && !use && !uri) { | ||
throw new Error('Was unable to retreive message, use or URI from step'); | ||
} | ||
|
||
console.log(message); | ||
console.log(use); | ||
console.log(uri); | ||
|
||
return forgerock.FRAuth.next(step); | ||
}), | ||
map( | ||
(step) => { | ||
if (step.payload.status === 401) { | ||
throw new Error('Auth_Error'); | ||
} else if (step.payload.tokenId) { | ||
console.log('Basic login with OTP registration step successful'); | ||
document.body.innerHTML = '<p class="Logged_In">Login successful</p>'; | ||
} else { | ||
throw new Error('Something went wrong.'); | ||
} | ||
}, | ||
(step) => step, | ||
), | ||
rxDelay(delay), | ||
mergeMap((step) => { | ||
return forgerock.SessionManager.logout(); | ||
}), | ||
map((response) => { | ||
if (response.ok) { | ||
console.log('Logout successful'); | ||
document.body.innerHTML = '<p class="Logged_Out">Logout successful</p>'; | ||
} else { | ||
throw new Error('Logout_Error'); | ||
} | ||
}), | ||
) | ||
.subscribe({ | ||
error: (err) => { | ||
console.log(`Error: ${err.message}`); | ||
document.body.innerHTML = `<p class="Test_Complete">${err.message}</p>`; | ||
}, | ||
complete: () => { | ||
console.log('Test script complete'); | ||
document.body.innerHTML = `<p class="Test_Complete">Test script complete</p>`; | ||
}, | ||
}); | ||
}, 250); | ||
} | ||
|
||
autoscript(); | ||
export default autoscript; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>E2E Test | ForgeRock JavaScript SDK</title> | ||
|
||
<!-- Needed only for automation with mock server --> | ||
<meta name="referrer" content="unsafe-url" /> | ||
|
||
<link rel="shortcut icon" href="/fr-ico.png" type="image/png" /> | ||
|
||
<style> | ||
@media (prefers-color-scheme: dark) { | ||
html { | ||
background-color: black; | ||
color: white; | ||
} | ||
a { | ||
color: lightblue; | ||
} | ||
a:visited { | ||
color: lavender; | ||
} | ||
a:hover { | ||
color: lightskyblue; | ||
} | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<script src="autoscript.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* @forgerock/javascript-sdk | ||
* | ||
* authn-otp-reg.test.ts | ||
* | ||
* Copyright (c) 2020 ForgeRock. 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 } from '@playwright/test'; | ||
import { setupAndGo } from '../utilities/setup-and-go'; | ||
|
||
test.describe('Test QR Code flows', () => { | ||
test(`Login and register OTP successfully`, async ({ page, browserName }) => { | ||
const { messageArray } = await setupAndGo(page, browserName, 'authn-otp-reg/'); | ||
|
||
// Test assertions | ||
expect( | ||
messageArray.includes( | ||
'Scan the QR code image below with the ForgeRock Authenticator app to register your device with your login.', | ||
), | ||
).toBe(true); | ||
expect(messageArray.includes('otp')).toBe(true); | ||
expect( | ||
messageArray.includes( | ||
'otpauth://totp/ForgeRock:jlowery?secret=QITSTC234FRIU8DD987DW3VPICFY======&issuer=ForgeRock&period=30&digits=6&b=032b75', | ||
), | ||
).toBe(true); | ||
expect(messageArray.includes('Basic login with OTP registration step successful')).toBe(true); | ||
}); | ||
}); |
Oops, something went wrong.