Skip to content

Commit

Permalink
feat: auth0 login in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jblew committed Mar 24, 2022
1 parent bd00701 commit 0452ea6
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
3 changes: 2 additions & 1 deletion e2e-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
/cypress/videos
/cypress/videos
/cypress.env.json
12 changes: 12 additions & 0 deletions e2e-tests/cypress/integration/loggedin.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="cypress" />

describe("Logged in route test", () => {
beforeEach(() => {
(cy as any).login();
cy.visit("/");
});

it("displays Adding patch sample header", () => {
cy.findByText("Adding patch sample", { exact: false }).should("exist");
});
});
13 changes: 10 additions & 3 deletions e2e-tests/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
// config.env.auth0_username = process.env.AUTH0_USERNAME;
// config.env.auth0_password = process.env.AUTH0_PASSWORD;
// config.env.auth0_domain = process.env.AUTH0_DOMAIN;
// config.env.auth0_audience = process.env.AUTH0_AUDIENCE;
// config.env.auth0_scope = process.env.AUTH0_SCOPE;
// config.env.auth0_client_id = process.env.AUTH0_CLIENTID;
// config.env.auth0_client_secret = process.env.AUTH0_CLIENT_SECRET;

return config;
};
29 changes: 29 additions & 0 deletions e2e-tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,32 @@
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

import "@testing-library/cypress/add-commands";

Cypress.Commands.add("login", (overrides = {}) => {
Cypress.log({
name: "loginViaAuth0",
});
const tenantURL = Cypress.env("oidc_issuer_baseurl");
const options = {
method: "POST",
url: `${tenantURL}/oauth/token`,
body: {
grant_type: "password",
username: Cypress.env("auth_username"),
password: Cypress.env("auth_password"),
audience: `${tenantURL}/api/v2/`,
scope: "openid profile email",
client_id: Cypress.env("oidc_client_id"),
client_secret: Cypress.env("oidc_auth_secret"),
},
};
cy.request(options).then((resp) => {
const { id_token } = resp.body;
const reqConf = {
method: "POST",
url: "/api/auth_callback",
body: { id_token }, // Must pass only the access_token. Passing full response from oauth causes the 'missing at_hash error'
};
cy.request(reqConf);
});
});
2 changes: 1 addition & 1 deletion e2e-tests/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'
import "./commands";

// Alternatively you can use CommonJS syntax:
// require('./commands')

0 comments on commit 0452ea6

Please sign in to comment.