Skip to content

Commit

Permalink
Fix e2e sample test failures for SSR (#1381)
Browse files Browse the repository at this point in the history
OKTA-574495 Fixes e2e tests
  • Loading branch information
denysoblohin-okta authored Feb 16, 2023
1 parent c3a982f commit 4ddcc2c
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 21 deletions.
6 changes: 2 additions & 4 deletions samples/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,14 @@ const samples = [
// group sms related specs together, so they do not run in parallel
// this spec takes time to finish, run it first
[
// fix affected tests: https://oktainc.atlassian.net/browse/OKTA-574495
// 'self-service-registration',
'self-service-registration',
'mfa-password-and-sms',
],
'root-page',
'basic-auth',
'identifier-first-auth',
'self-service-password-recovery',
// fix affected tests: https://oktainc.atlassian.net/browse/OKTA-574495
// 'self-service-registration-custom-attribute',
'self-service-registration-custom-attribute',
'self-service-registration-activation-token',
'mfa-password-and-email',
'mfa-password-and-email-magic-link',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ router.post('/verify-authenticator/okta_email', async (req, res, next) => {
});

// Handle enroll authenticator -- email
router.get('/enroll-authenticator/okta_email/enrollment-data', (req, res) => {
const {
idx: { nextStep: { inputs } }
} = req.getFlowStates();
const { options } = inputs[0];
renderPage({
req, res,
render: () => renderTemplate(req, res, 'select-authenticator', {
options,
action: '/enroll-authenticator/okta_email/enrollment-data',
canSkip: false,
})
});
});

router.get('/enroll-authenticator/okta_email', (req, res) => {
renderPage({
req, res,
Expand All @@ -117,6 +132,12 @@ router.get('/enroll-authenticator/okta_email', (req, res) => {
});
});

router.post('/enroll-authenticator/okta_email/enrollment-data', async (req, res, next) => {
const authClient = getAuthClient(req);
const transaction = await authClient.idx.proceed({ authenticator: 'okta_email' });
handleTransaction({ req, res, next, authClient, transaction });
});

router.post('/enroll-authenticator/okta_email', async (req, res, next) => {
const { verificationCode } = req.body;
const authClient = getAuthClient(req);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = function renderTemplate(req, res, template, options = {}) {
} = {}
} = {}
} = req.getFlowStates();
const hasContextualDataForAuthenticator = contextualData?.qrcode || contextualData?.sharedSecret;
const authenticatorEnrollmentsJSON = authenticatorEnrollments ? JSON.stringify(authenticatorEnrollments) : null;
const activationData = contextualData ? JSON.stringify(contextualData.activationData) : null;
const challengeData = contextualData ? JSON.stringify(contextualData.challengeData) : null;
Expand All @@ -38,6 +39,7 @@ module.exports = function renderTemplate(req, res, template, options = {}) {
cancelAction: getFormActionPath(req, '/cancel'),
selectStepAction: getFormActionPath(req, options.selectStepAction),
contextualData,
hasContextualDataForAuthenticator,
activationData,
challengeData,
authenticatorEnrollments: authenticatorEnrollmentsJSON,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{{>formMessages}}
</div>

{{#contextualData}}
{{#hasContextualDataForAuthenticator}}
<div class="ui segments">
<div class="ui segment">
{{#contextualData.qrcode}}
Expand All @@ -34,7 +34,7 @@
{{/contextualData.sharedSecret}}
</div>
</div>
{{/contextualData}}
{{/hasContextualDataForAuthenticator}}

<div class="row">
<form id="challenge-authenticator-form" class="ui large form" action="{{action}}" method="POST">
Expand Down
41 changes: 28 additions & 13 deletions samples/test/features/self-service-registration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Background:
And the app has Email Verification callback uri defined
And a Policy that defines "Profile Enrollment"
And with a Policy Rule that defines "collecting default attributes"
And a Policy that defines "MFA Enrollment" with properties
| okta_password | REQUIRED |
| okta_email | REQUIRED |
| phone_number | OPTIONAL |
And with a Policy Rule that defines "MFA Enrollment Challenge"
And a user named "Mary"
And she does not have account in the org

Expand All @@ -16,15 +21,18 @@ Scenario: Mary signs up for an account with Password, setups up required Email f
And she fills out her Email
And she submits the form
Then she is redirected to the "Select Authenticator" page
When she selects the "Email" factor
And she submits the form
Then she sees a page to input a code for email authenticator enrollment
When she inputs the correct code from her "Email"
And she submits the form
Then she is redirected to the "Select Authenticator" page
When she selects the "Password" factor
And she submits the form
Then she sees the set new password form
And she fills out her Password
And she confirms her Password
And she submits the form
Then she sees a page to input a code for email authenticator enrollment
When she inputs the correct code from her "Email"
And she submits the form
Then she is redirected to the "Select Authenticator" page
When she selects "Skip" on SMS
Then she is redirected to the "Root" page
Expand All @@ -39,15 +47,18 @@ Scenario: Mary signs up for an account with Password, setups up required Email f
And she fills out her Email
And she submits the form
Then she is redirected to the "Select Authenticator" page
When she selects the "Email" factor
And she submits the form
Then she sees a page to input a code for email authenticator enrollment
When she inputs the correct code from her "Email"
And she submits the form
Then she is redirected to the "Select Authenticator" page
When she selects the "Password" factor
And she submits the form
Then she sees the set new password form
And she fills out her Password
And she confirms her Password
And she submits the form
Then she sees a page to input a code for email authenticator enrollment
When she inputs the correct code from her "Email"
And she submits the form
Then she is redirected to the "Select Authenticator" page
When she selects the "Phone" factor
And she submits the form
Expand All @@ -57,8 +68,6 @@ Scenario: Mary signs up for an account with Password, setups up required Email f
Then the screen changes to receive an input for a code
When she inputs the correct code from her "SMS"
And she submits the form
Then she is redirected to the "Select Authenticator" page
When she selects "Skip"
Then she is redirected to the "Root" page
And she sees a table with her profile info
And the cell for the value of "email" is shown and contains her "email"
Expand All @@ -81,15 +90,18 @@ Scenario: Mary signs up for an account with Password, sets up required Email fac
And she fills out her Email
And she submits the form
Then she is redirected to the "Select Authenticator" page
When she selects the "Email" factor
And she submits the form
Then she sees a page to input a code for email authenticator enrollment
When she inputs the correct code from her "Email"
And she submits the form
Then she is redirected to the "Select Authenticator" page
When she selects the "Password" factor
And she submits the form
Then she sees the set new password form
And she fills out her Password
And she confirms her Password
And she submits the form
Then she sees a page to input a code for email authenticator enrollment
When she inputs the correct code from her "Email"
And she submits the form
Then she is redirected to the "Select Authenticator" page
When she selects the "Phone" factor
And she submits the form
Expand All @@ -106,14 +118,17 @@ Scenario: Mary signs up for an account with Password, setups up required Email f
And she fills out her Email
And she submits the form
Then she is redirected to the "Select Authenticator" page
When she selects the "Email" factor
And she submits the form
Then she sees a page to input a code for email authenticator enrollment
When she clicks the Email magic link for email verification
Then she is redirected to the "Select Authenticator" page
When she selects the "Password" factor
And she submits the form
Then she sees the set new password form
And she fills out her Password
And she confirms her Password
And she submits the form
Then she sees a page to input a code for email authenticator enrollment
When she clicks the Email magic link for email verification
Then she is redirected to the "Select Authenticator" page
When she selects "Skip" on SMS
Then she is redirected to the "Root" page
Expand Down
6 changes: 4 additions & 2 deletions samples/test/support/management-api/a18nClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export default class A18nClient {

const match = response?.content?.match(/Enter a code instead: (?<code>\d+)/)
|| response?.content?.match(/enter this code: <b>(?<code>\d+)<\/b>/)
|| response?.content?.match(/please contact your system administrator immediately.[\s\S]\s*(?<code>\d+)/);
|| response?.content?.match(/please contact your system administrator immediately.[\s\S]\s*(?<code>\d+)/)
|| response?.content?.match(/enter the verification code: <strong>(?<code>\d+)<\/strong>/);
const code = match?.groups?.code;
if (!code) {
throw new Error('Unable to retrieve code from email.');
Expand Down Expand Up @@ -107,7 +108,8 @@ export default class A18nClient {
--retryAttemptsRemaining;
}

const match = response?.content?.match(/<a id="email-activation-button" href="(?<url>\S+)"/);
const match = response?.content?.match(/<a id="email-activation-button" href="(?<url>\S+)"/)
|| response?.content?.match(/<a id="registration-activation-link" href="(?<url>\S+)"/);
const url = match?.groups?.url;
if (!url) {
throw new Error('Unable to retrieve magic link from email.');
Expand Down
1 change: 1 addition & 0 deletions test/e2e/features/step-definitions/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ When(
'she verifies her sms',
{ timeout: 30*1000 },
async function (this: ActionContext) {
await OktaLogin.receiveCodeViaSms();
const code = await this.a18nClient.getSMSCode(this.credentials.profileId);
await OktaLogin.enterCode(code);
await OktaLogin.clickVerify();
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/pageobjects/OktaLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class OktaLogin {

get signinFormTitle() { return $('.okta-form-title.o-form-head'); }
get verifyWithEmailCodeButton() { return $('form[data-se="o-form"] button.enter-auth-code-instead-link'); }
get receiveCodeViaSmsButton() { return $('form[data-se="o-form"] input[type=submit]'); }
get code() {
if (process.env.ORG_OIE_ENABLED) {
return this.OIEsigninPassword;
Expand Down Expand Up @@ -145,6 +146,13 @@ class OktaLogin {
(await this.verifyWithEmailCodeButton).click();
}

async receiveCodeViaSms() {
await browser.waitUntil(async () => {
return (await this.receiveCodeViaSmsButton).isDisplayed();
}, 5000, 'wait for receive a code via sms btn');
(await this.receiveCodeViaSmsButton).click();
}

async enterCode(code) {
await browser.waitUntil(async () => {
return (await this.code).isDisplayed();
Expand Down

0 comments on commit 4ddcc2c

Please sign in to comment.