Skip to content

Commit

Permalink
refactor(sample-test): dynamic config test org env with management api
Browse files Browse the repository at this point in the history
OKTA-482291
<<<Jenkins Check-In of Tested SHA: d52948a for [email protected]>>>
Artifact: okta-auth-js
Files changed count: 73
PR Link: "#1149"
  • Loading branch information
shuowu authored and eng-prod-CI-bot-okta committed Mar 23, 2022
1 parent e156023 commit f06eac1
Show file tree
Hide file tree
Showing 70 changed files with 988 additions and 621 deletions.
15 changes: 8 additions & 7 deletions .bacon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ test_suites:
script_name: e2e-express-embedded-sign-in-widget
criteria: MERGE
queue_name: small
- name: e2e-react-oie
script_path: ../okta-auth-js/scripts
sort_order: '14'
timeout: '10'
script_name: e2e-react-oie
criteria: MERGE
queue_name: small
# disable due to request cors issue
# - name: e2e-react-oie
# script_path: ../okta-auth-js/scripts
# sort_order: '14'
# timeout: '10'
# script_name: e2e-react-oie
# criteria: MERGE
# queue_name: small
- name: publish
script_path: ../okta-auth-js/scripts
sort_order: '15'
Expand Down
27 changes: 1 addition & 26 deletions env/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
*/

const dotenv = require('dotenv');
const yaml = require('js-yaml');
const fs = require('fs');
const path = require('path');

const TESTENV_FILE = 'testenv';
const TESTENV_YAML = 'testenv.yml';

function setEnvironmentVars(envConfig) {
Object.keys(envConfig).forEach((k) => {
Expand Down Expand Up @@ -47,29 +45,6 @@ function setEnvironmentVarsFromTestEnv(currDir) {
setEnvironmentVars(envConfig);
}

function setEnvironmentVarsFromTestEnvYaml(name, currDir) {
const testEnvPath = getPath(TESTENV_YAML, currDir);
if (!testEnvPath) {
return;
}
const doc = yaml.load(fs.readFileSync(testEnvPath, 'utf8'));
if (!doc) {
console.log(`Can't load testenv.yml`);
return;
}

if (doc.default) {
console.log(`Loading environment variables from testenv.yml: "default"`);
setEnvironmentVars(doc.default);
}

if (doc[name]) {
console.log(`Loading environment variables from testenv.yml: "${name}"`);
setEnvironmentVars(doc[name]);
}
}

module.exports = {
setEnvironmentVarsFromTestEnv,
setEnvironmentVarsFromTestEnvYaml
setEnvironmentVarsFromTestEnv
};
3 changes: 1 addition & 2 deletions env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"main": "index.js",
"private": true,
"dependencies": {
"dotenv": "^8.2.0",
"js-yaml": "^4.1.0"
"dotenv": "^8.2.0"
}
}
9 changes: 8 additions & 1 deletion samples/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,38 @@ const templateDefaults = {
const samples = [
{
name: '@okta/samples.static-spa',
appType: 'browser',
template: 'static-spa',
generateType: GENERATE_TYPE_FULL,
specs: ['spa-app'],
features: []
},
{
name: '@okta/samples.webpack-spa',
appType: 'browser',
template: 'webpack-spa',
generateType: GENERATE_TYPE_FULL,
specs: ['spa-app'],
features: []
},
{
name: '@okta/samples.express-web-no-oidc',
appType: 'web',
template: 'express-web',
generateType: GENERATE_TYPE_FULL,
specs: ['web-app'],
oidc: false
},
{
name: '@okta/samples.express-web-with-oidc',
appType: 'web',
template: 'express-web',
generateType: GENERATE_TYPE_FULL,
specs: ['web-app']
},
{
name: '@okta/samples.express-embedded-auth-with-sdk',
appType: 'web',
template: 'express-embedded-auth-with-sdk',
generateType: GENERATE_TYPE_OVERWRITE,
specs: ['express-embedded-auth-with-sdk'],
Expand All @@ -88,17 +93,18 @@ const samples = [
'self-service-registration-custom-attribute',
'self-service-registration-activation-token',
'mfa-password-and-email',
'mfa-password-and-email-magic-link',
'mfa-password-and-sms',
'social-login-mfa',
'social-idp',
'totp-signup',
'totp-signin',
],
useEnv: true,
express: true,
},
{
name: '@okta/samples.express-embedded-sign-in-widget',
appType: 'web',
template: 'express-embedded-sign-in-widget',
generateType: GENERATE_TYPE_OVERWRITE,
specs: [],
Expand All @@ -110,6 +116,7 @@ const samples = [
},
{
name: '@okta/test.app.react-oie',
appType: 'browser',
features: [
'progressive-profiling-view-profile'
],
Expand Down
27 changes: 1 addition & 26 deletions samples/generated/express-embedded-auth-with-sdk/env/okta-env.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
</p>

<div class="row">
<button id="register-button" class="ui primary basic button" onclick="location.href='/register'">Register</button>
<button id="account-unlock-button" class="ui primary basic button" onclick="location.href='/unlock-account'">Unlock Account</button>
<button id="login-button" class="ui primary basic button" onclick="location.href='/login'">Login</button>
<button id="register-button" name="signup" class="ui primary basic button" onclick="location.href='/register'">Register</button>
<button id="account-unlock-button" name="unlock-account" class="ui primary basic button" onclick="location.href='/unlock-account'">Unlock Account</button>
<button id="login-button" name="signin" class="ui primary basic button" onclick="location.href='/login'">Login</button>
</div>
{{/isLoggedIn}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="menu">
{{#isLoggedIn}}
<form method="POST" action="/logout">
<button id="logout-button" data-se="logout" class="item">
<button id="logout-button" name="signout" class="item">
Logout
</button>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

{{#canSkip}}
<form class="ui form" action="{{skipAction}}" method="POST">
<button id="skip-button" class="ui fluid submit button" type="submit">
<button id="skip-button" name="skip" class="ui fluid submit button" type="submit">
Skip
</button>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

{{#canSkip}}
<form class="ui form" action="{{skipAction}}" method="POST">
<button id="skip-button" class="ui fluid submit button" type="submit">
<button id="skip-button" name="skip" class="ui fluid submit button" type="submit">
Skip
</button>
</form>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions samples/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ WEB_CLIENT_ID=123xxxx
WEB_CLIENT_SECRET=sOmeSecretString
```

## Reproduce test locally

Most cucumber tests setup org configs dynamiclly via management api and tear down the created app/polices/user after each test. It might make it difficult to repro the test with the exact org config after a failure, here are some approaches to persist the created org config during a test:

* Comment out the org context deletion part in `./steps/after.ts`. **Note:** the changes should not be commited.

* Add a break point at the end of `Given` step, so configs can be grabbed from the test org, then you can target to the generated test app for local manual debugging. See the `sample: test feature` section in `launch.json`.

* Use `await browser.debug()` to pause the test process.

## Commands

If running from the workspace directory: `yarn workspace @okta/test.e2e.samples start`
Expand Down
18 changes: 11 additions & 7 deletions samples/test/features/basic-auth.feature
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Feature: Direct Auth Basic Login with Password Factor

Background:
Given an APP Sign On Policy that defines Password as required and the only factor for login
# And the list of Authenticators only contains Email and Password
# And User Enumeration Prevention is set to ENABLED in Security > General
And a User named "Mary" exists, and this user has already setup email and password factors
Given an App
And a Policy that defines "Authentication"
And with a Policy Rule that defines "Password as the only factor"
And a user named "Mary"

Scenario: Mary logs in with a Password
Given Mary navigates to Login with Username and Password
Given she has an account with "active" state in the org
And Mary navigates to Login with Username and Password
When she fills in her username
And she fills in her correct password
And she submits the Login form
Expand All @@ -22,14 +23,17 @@ Feature: Direct Auth Basic Login with Password Factor
Then she is redirected to the Self Service Password Reset View

Scenario: Mary doesn't know her username
Given Mary navigates to Login with Username and Password
Given she does not have account in the org
And the app is assigned to "Everyone" group
And Mary navigates to Login with Username and Password
When she fills in her incorrect username
And she fills in her password
And she submits the Login form
Then she should see a message on the Login form "There is no account with the Username Mory."

Scenario: Mary doesn't know her password
Given Mary navigates to the Basic Login View
Given she has an account with "active" state in the org
And Mary navigates to the Basic Login View
When she fills in her correct username
And she fills in her incorrect password
And she submits the Login form with blank fields
Expand Down
9 changes: 5 additions & 4 deletions samples/test/features/embedded-widget-basic-auth.feature
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Feature: Basic Login with Embedded Sign In Widget

Background:
Given a SPA, WEB APP or MOBILE Policy that defines Password as required and the only factor for login
#AND the list of Authenticators contains Email and Password
And a user named "Mary"
And Mary has an account in the org
Given an App
And a Policy that defines "Authentication"
And with a Policy Rule that defines "Password as the only factor"
And a user named "Mary"
And she has an account with "active" state in the org

Scenario: Mary logs in with a Password
When she clicks the login button
Expand Down
22 changes: 22 additions & 0 deletions samples/test/features/mfa-password-and-email-magic-link.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Feature: Multi-Factor Authentication with Password and Email Magic Link

Background:
Given an App
And the app has Email Verification callback uri defined
And a Policy that defines "Authentication"
And with a Policy Rule that defines "Password + Another Factor"
And a user named "Mary"
And she has an account with "active" state in the org

Scenario: 2FA Login with Email Magic Link on the same browser
Given Mary navigates to the Basic Login View
And she has inserted her username
And she has inserted her password
And her password is correct
When she clicks Login
Then she is presented with an option to select Email to verify
When She selects Email from the list
And She selects "Receive a Code"
And she clicks the Email magic link
Then she is redirected to the Root View
And an application session is created
20 changes: 5 additions & 15 deletions samples/test/features/mfa-password-and-email.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
Feature: Multi-Factor Authentication with Password and Email

Background:
Given a SPA, WEB APP or MOBILE Policy that defines MFA with Password and Email as required
And a User named "Mary" created in the admin interface with a Password only
Given an App
And a Policy that defines "Authentication"
And with a Policy Rule that defines "Password + Another Factor"
And a user named "Mary"
And she has an account with "active" state in the org

Scenario: Mary enters a wrong verification code
Given Mary navigates to the Basic Login View
Expand All @@ -28,16 +31,3 @@ Feature: Multi-Factor Authentication with Password and Email
And She selects "Verify"
Then she is redirected to the Root View
And an application session is created

Scenario: 2FA Login with Email Magic Link on the same browser
Given Mary navigates to the Basic Login View
And she has inserted her username
And she has inserted her password
And her password is correct
When she clicks Login
Then she is presented with an option to select Email to verify
When She selects Email from the list
And She selects "Receive a Code"
And she clicks the Email magic link
Then she is redirected to the Root View
And an application session is created
Loading

0 comments on commit f06eac1

Please sign in to comment.