Skip to content

Commit

Permalink
test(e2e): logout return to
Browse files Browse the repository at this point in the history
  • Loading branch information
Benehiko committed Jun 26, 2023
1 parent 21c8b9f commit a275c3a
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 171 deletions.
49 changes: 29 additions & 20 deletions test/e2e/cypress/integration/profiles/email/logout/success.spec.ts
Expand Up @@ -21,12 +21,15 @@ context("Testing logout flows", () => {
},
].forEach(({ route, profile, app, settings }) => {
describe(`for app ${app}`, () => {
const email = gen.email()
const password = gen.password()
let email: string
let password: string

before(() => {
cy.proxy(app)

email = gen.email()
password = gen.password()

cy.useConfigProfile(profile)
cy.registerApi({
email,
Expand Down Expand Up @@ -57,30 +60,36 @@ context("Testing logout flows", () => {
cy.noSession()
cy.url().should("include", "/login")
})
})

it("should be able to sign out at 2fa page", () => {
cy.sessionRequires2fa()
cy.getSession({ expectAal: "aal1" })
it("should be able to sign out at 2fa page", () => {
cy.useLookupSecrets(true)
cy.sessionRequires2fa()
cy.getSession({ expectAal: "aal1" })
cy.getCookie("ory_kratos_session").should("not.be.null")

// add 2fa to account
cy.visit(settings)
cy.get(appPrefix(app) + 'button[name="lookup_secret_regenerate"]').click()
cy.get('button[name="lookup_secret_confirm"]').click()
cy.expectSettingsSaved()
// add 2fa to account
cy.visit(settings)
cy.get(
appPrefix(app) + 'button[name="lookup_secret_regenerate"]',
).click()
cy.get('button[name="lookup_secret_confirm"]').click()
cy.expectSettingsSaved()

cy.logout()
cy.visit(route + "?return_to=https://www.ory.sh")
cy.logout()
cy.visit(route + "?return_to=https://www.ory.sh")

cy.reauth({
expect: { email },
type: { email: email, password: password },
})
cy.get('[name="identifier"]').clear().type(email)

cy.get("href*=/logout").should("have.", "https://www.ory.sh")
cy.get("href*=/logout").click()
cy.reauth({
expect: { email, success: false },
type: { password: password },
})

cy.get("a[href*='logout']").click()

cy.location("host").should("eq", "www.ory.sh")
cy.location("host").should("eq", "www.ory.sh")
cy.useLookupSecrets(false)
})
})
})
})
296 changes: 148 additions & 148 deletions test/e2e/cypress/integration/profiles/mfa/mix.spec.ts
Expand Up @@ -10,171 +10,171 @@ context("2FA with various methods", () => {
beforeEach(() => {
cy.task("resetCRI", {})
})
;[
{
login: react.login,
settings: react.settings,
base: react.base,
app: "react" as "react",
profile: "spa",
},
{
login: express.login,
settings: express.settings,
base: express.base,
app: "express" as "express",
profile: "mfa",
},
].forEach(({ settings, login, profile, app, base }) => {
describe(`for app ${app}`, () => {
before(() => {
cy.useConfigProfile(profile)
cy.proxy(app)
})
let email = gen.email()
let password = gen.password()
;[
{
login: react.login,
settings: react.settings,
base: react.base,
app: "react" as "react",
profile: "spa",
},
{
login: express.login,
settings: express.settings,
base: express.base,
app: "express" as "express",
profile: "mfa",
},
].forEach(({ settings, login, profile, app, base }) => {
describe(`for app ${app}`, () => {
before(() => {
cy.useConfigProfile(profile)
cy.proxy(app)
})
let email = gen.email()
let password = gen.password()

beforeEach(() => {
cy.clearAllCookies()
email = gen.email()
password = gen.password()
cy.registerApi({
email,
password,
fields: { "traits.website": website },
})
cy.clearAllCookies()
cy.login({ email, password, cookieUrl: base })
cy.longPrivilegedSessionTime()
cy.task("sendCRI", {
query: "WebAuthn.disable",
opts: {},
})
beforeEach(() => {
cy.clearAllCookies()
email = gen.email()
password = gen.password()
cy.registerApi({
email,
password,
fields: { "traits.website": website },
})
cy.clearAllCookies()
cy.login({ email, password, cookieUrl: base })
cy.longPrivilegedSessionTime()
cy.task("sendCRI", {
query: "WebAuthn.disable",
opts: {},
})
})

it("should set up an use all mfa combinations", () => {
cy.visit(settings)
it("should set up an use all mfa combinations", () => {
cy.visit(settings)
cy.task("sendCRI", {
query: "WebAuthn.enable",
opts: {},
}).then(() => {
cy.task("sendCRI", {
query: "WebAuthn.enable",
opts: {},
}).then(() => {
cy.task("sendCRI", {
query: "WebAuthn.addVirtualAuthenticator",
opts: {
options: {
protocol: "ctap2",
transport: "usb",
hasResidentKey: true,
hasUserVerification: true,
isUserVerified: true,
},
query: "WebAuthn.addVirtualAuthenticator",
opts: {
options: {
protocol: "ctap2",
transport: "usb",
hasResidentKey: true,
hasUserVerification: true,
isUserVerified: true,
},
}).then(() => {
cy.getSession({
expectAal: "aal1",
expectMethods: ["password"],
})
},
}).then(() => {
cy.getSession({
expectAal: "aal1",
expectMethods: ["password"],
})

cy.visit(settings)
// Set up TOTP
let secret: string
cy.get(
appPrefix(app) + '[data-testid="node/text/totp_secret_key/text"]',
).then(($e) => {
secret = $e.text().trim()
})
cy.get('[name="totp_code"]').then(($e) => {
cy.wrap($e).type(authenticator.generate(secret))
})
cy.get('[name="method"][value="totp"]').click()
cy.expectSettingsSaved()
cy.getSession({
expectAal: "aal2",
expectMethods: ["password", "totp"],
})
cy.visit(settings)
// Set up TOTP
let secret: string
cy.get(
appPrefix(app) + '[data-testid="node/text/totp_secret_key/text"]',
).then(($e) => {
secret = $e.text().trim()
})
cy.get('[name="totp_code"]').then(($e) => {
cy.wrap($e).type(authenticator.generate(secret))
})
cy.get('[name="method"][value="totp"]').click()
cy.expectSettingsSaved()
cy.getSession({
expectAal: "aal2",
expectMethods: ["password", "totp"],
})

// Set up lookup secrets
cy.visit(settings)
cy.get('[name="lookup_secret_regenerate"]').click()
let codes: string[]
cy.getLookupSecrets().then((c) => {
codes = c
})
cy.get('[name="lookup_secret_confirm"]').click()
cy.expectSettingsSaved()
cy.getSession({
expectAal: "aal2",
expectMethods: ["password", "totp", "lookup_secret"],
})
// Set up lookup secrets
cy.visit(settings)
cy.get('[name="lookup_secret_regenerate"]').click()
let codes: string[]
cy.getLookupSecrets().then((c) => {
codes = c
})
cy.get('[name="lookup_secret_confirm"]').click()
cy.expectSettingsSaved()
cy.getSession({
expectAal: "aal2",
expectMethods: ["password", "totp", "lookup_secret"],
})

// Set up WebAuthn
cy.visit(settings)
cy.get('[name="webauthn_register_displayname"]').type("my-key")
// We need a workaround here. So first we click, then we submit
cy.clickWebAuthButton("register")
cy.expectSettingsSaved()
cy.getSession({
expectAal: "aal2",
expectMethods: ["password", "totp", "webauthn", "lookup_secret"],
})
// Set up WebAuthn
cy.visit(settings)
cy.get('[name="webauthn_register_displayname"]').type("my-key")
// We need a workaround here. So first we click, then we submit
cy.clickWebAuthButton("register")
cy.expectSettingsSaved()
cy.getSession({
expectAal: "aal2",
expectMethods: ["password", "totp", "webauthn", "lookup_secret"],
})

cy.visit(login + "?aal=aal2&refresh=true")
cy.get('[name="totp_code"]').then(($e) => {
cy.wrap($e).type(authenticator.generate(secret))
})
cy.visit(login + "?aal=aal2&refresh=true")
cy.get('[name="totp_code"]').then(($e) => {
cy.wrap($e).type(authenticator.generate(secret))
})

cy.get('[name="method"][value="totp"]').click()
cy.location("pathname").should("not.include", "/login")
cy.get('[name="method"][value="totp"]').click()
cy.location("pathname").should("not.include", "/login")

cy.getSession({
expectAal: "aal2",
expectMethods: [
"password",
"totp",
"webauthn",
"lookup_secret",
"totp",
],
})
cy.getSession({
expectAal: "aal2",
expectMethods: [
"password",
"totp",
"webauthn",
"lookup_secret",
"totp",
],
})

// Use TOTP
cy.visit(login + "?aal=aal2&refresh=true")
cy.clickWebAuthButton("login")
cy.getSession({
expectAal: "aal2",
expectMethods: [
"password",
"totp",
"webauthn",
"lookup_secret",
"totp",
"webauthn",
],
})
// Use TOTP
cy.visit(login + "?aal=aal2&refresh=true")
cy.clickWebAuthButton("login")
cy.getSession({
expectAal: "aal2",
expectMethods: [
"password",
"totp",
"webauthn",
"lookup_secret",
"totp",
"webauthn",
],
})

// Use lookup
cy.visit(login + "?aal=aal2&refresh=true")
cy.get('[name="lookup_secret"]').then(($e) => {
cy.wrap($e).type(codes[1])
})
cy.get('[name="method"][value="lookup_secret"]').click()
cy.location("pathname").should("not.include", "/login")
// Use lookup
cy.visit(login + "?aal=aal2&refresh=true")
cy.get('[name="lookup_secret"]').then(($e) => {
cy.wrap($e).type(codes[1])
})
cy.get('[name="method"][value="lookup_secret"]').click()
cy.location("pathname").should("not.include", "/login")

cy.getSession({
expectAal: "aal2",
expectMethods: [
"password",
"totp",
"webauthn",
"lookup_secret",
"totp",
"webauthn",
"lookup_secret",
],
})
cy.getSession({
expectAal: "aal2",
expectMethods: [
"password",
"totp",
"webauthn",
"lookup_secret",
"totp",
"webauthn",
"lookup_secret",
],
})
})
})
})
})
})
})

0 comments on commit a275c3a

Please sign in to comment.