Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #1270 from cypress-io/convert-auth0-tests-to-cy-or…
…igin Convert Auth0 tests to use experimentalSessionAndOrigin
- Loading branch information
Showing
10 changed files
with
57 additions
and
95 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 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 |
---|---|---|
@@ -1,53 +1,42 @@ | ||
// @ts-check | ||
///<reference path="../../global.d.ts" /> | ||
|
||
import * as jwt from "jsonwebtoken"; | ||
|
||
Cypress.Commands.add("loginByAuth0Api", (username: string, password?: string) => { | ||
// Note: this function leaves you on a blank page, so you must call cy.visit() | ||
// afterwards, before continuing with your test. | ||
Cypress.Commands.add("loginToAuth0", (username: string, password: string) => { | ||
const log = Cypress.log({ | ||
displayName: "AUTH0 LOGIN", | ||
message: [`🔐 Authenticating | ${username}`], | ||
// @ts-ignore | ||
autoEnd: false, | ||
}); | ||
|
||
const client_id = Cypress.env("auth0_client_id"); | ||
const client_secret = Cypress.env("auth0_client_secret"); | ||
const audience = Cypress.env("auth0_audience"); | ||
const scope = Cypress.env("auth0_scope"); | ||
|
||
log.snapshot("before"); | ||
|
||
cy.request({ | ||
method: "POST", | ||
url: `https://${Cypress.env("auth0_domain")}/oauth/token`, | ||
body: { | ||
grant_type: "password", | ||
username, | ||
password, | ||
audience, | ||
scope, | ||
client_id, | ||
client_secret, | ||
const args = { username, password }; | ||
cy.session( | ||
args, | ||
() => { | ||
// App landing page redirects to Auth0. | ||
cy.visit("/"); | ||
|
||
// Login on Auth0. | ||
cy.origin(Cypress.env("auth0_domain"), { args }, ({ username, password }) => { | ||
cy.get("input#username").type(username); | ||
cy.get("input#password").type(password); | ||
cy.contains("button[value=default]", "Continue").click(); | ||
}); | ||
|
||
// Ensure Auth0 has redirected us back to the RWA. | ||
cy.url().should("equal", "http://localhost:3000/"); | ||
}, | ||
}).then(({ body }) => { | ||
const user: any = jwt.decode(body.id_token); | ||
|
||
const userItem = { | ||
token: body.access_token, | ||
user: { | ||
sub: user.sub, | ||
nickname: user.nickname, | ||
picture: user.name, | ||
email: user.email, | ||
{ | ||
validate: () => { | ||
// Validate presence of access token in localStorage. | ||
cy.wrap(localStorage).invoke("getItem", "authAccessToken").should("exist"); | ||
}, | ||
}; | ||
|
||
window.localStorage.setItem("auth0Cypress", JSON.stringify(userItem)); | ||
|
||
log.snapshot("after"); | ||
log.end(); | ||
}); | ||
} | ||
); | ||
|
||
cy.visit("/"); | ||
log.snapshot("after"); | ||
log.end(); | ||
}); |
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
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