DEV: Add general pretender for passkey challenge (#25432)

* DEV: Add general pretender for passkey challenge

* Limit a test to Chrome because of Firefox ESR flakiness
This commit is contained in:
Penar Musaraj 2024-01-29 22:13:59 +01:00 committed by GitHub
parent d29fefd73a
commit 2558543794
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 15 additions and 103 deletions

View File

@ -2,13 +2,7 @@ import { click, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Create Account Fields - From Login Form", function (needs) {
needs.pretender((server, helper) => {
server.get(`/session/passkey/challenge.json`, () =>
helper.response({ challenge: "smth" })
);
});
acceptance("Create Account Fields - From Login Form", function () {
test("autofills email field with login form value", async function (assert) {
await visit("/");
await click("header .login-button");

View File

@ -16,10 +16,6 @@ acceptance("Forgot password", function (needs) {
user_found: userFound,
});
});
server.get(`/session/passkey/challenge.json`, () =>
helper.response({ challenge: "smth" })
);
});
test("requesting password reset", async function (assert) {
@ -96,10 +92,6 @@ acceptance(
server.post("/session/forgot_password", () => {
return helper.response({});
});
server.get(`/session/passkey/challenge.json`, () =>
helper.response({ challenge: "smth" })
);
});
test("requesting password reset", async function (assert) {

View File

@ -8,9 +8,7 @@ import {
query,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Groups", function (needs) {
needs.settings({ enable_passkeys: false });
acceptance("Groups", function () {
test("Browsing Groups", async function (assert) {
await visit("/g?username=eviltrout");
assert.strictEqual(count(".group-box"), 1, "it displays user's groups");

View File

@ -2,13 +2,7 @@ import { currentRouteName, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Login redirect - anonymous", function (needs) {
needs.pretender((server, helper) => {
server.get(`/session/passkey/challenge.json`, () =>
helper.response({ challenge: "smth" })
);
});
acceptance("Login redirect - anonymous", function () {
test("redirects login to default homepage", async function (assert) {
await visit("/login");
assert.strictEqual(
@ -24,12 +18,6 @@ acceptance("Login redirect - categories default", function (needs) {
top_menu: "categories|latest|top|hot",
});
needs.pretender((server, helper) => {
server.get(`/session/passkey/challenge.json`, () =>
helper.response({ challenge: "smth" })
);
});
test("when site setting is categories", async function (assert) {
await visit("/login");
assert.strictEqual(

View File

@ -9,12 +9,6 @@ import {
acceptance("Login Required", function (needs) {
needs.settings({ login_required: true });
needs.pretender((server, helper) => {
server.get(`/session/passkey/challenge.json`, () =>
helper.response({ challenge: "smth" })
);
});
test("redirect", async function (assert) {
await visit("/latest");
assert.strictEqual(

View File

@ -5,12 +5,6 @@ import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
acceptance("Signing In - Mobile", function (needs) {
needs.mobileView();
needs.pretender((server, helper) => {
server.get(`/session/passkey/challenge.json`, () =>
helper.response({ challenge: "smth" })
);
});
test("sign in", async function (assert) {
await visit("/");
await click("header .login-button");

View File

@ -1,15 +1,11 @@
import { click, fillIn, tab, visit } from "@ember/test-helpers";
import { test } from "qunit";
import sinon from "sinon";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { acceptance, chromeTest } from "discourse/tests/helpers/qunit-helpers";
import I18n from "discourse-i18n";
acceptance("Modal - Login", function (needs) {
needs.settings({
enable_passkeys: false,
});
test("You can tab to the login button", async function (assert) {
acceptance("Modal - Login", function () {
chromeTest("You can tab to the login button", async function (assert) {
await visit("/");
await click("header .login-button");
// you have to press the tab key twice to get to the login button
@ -33,10 +29,6 @@ acceptance("Modal - Login - With 2FA", function (needs) {
totp_enabled: true,
})
);
server.get(`/session/passkey/challenge.json`, () =>
helper.response({ challenge: "smth" })
);
});
test("You can tab to 2FA login button", async function (assert) {
@ -53,13 +45,7 @@ acceptance("Modal - Login - With 2FA", function (needs) {
});
});
acceptance("Modal - Login - With Passkeys enabled", function (needs) {
needs.pretender((server, helper) => {
server.get(`/session/passkey/challenge.json`, () =>
helper.response({ challenge: "smth" })
);
});
acceptance("Modal - Login - With Passkeys enabled", function () {
test("Includes passkeys button and conditional UI", async function (assert) {
await visit("/");
await click("header .login-button");
@ -89,14 +75,6 @@ acceptance("Modal - Login - With Passkeys disabled", function (needs) {
acceptance("Modal - Login - Passkeys on mobile", function (needs) {
needs.mobileView();
needs.pretender((server, helper) => {
server.get(`/session/passkey/challenge.json`, () =>
helper.response({
challenge: "some-challenge",
})
);
});
test("Includes passkeys button and conditional UI", async function (assert) {
await visit("/");
await click("header .login-button");

View File

@ -7,7 +7,6 @@ acceptance("Login with email - hide email address taken", function (needs) {
needs.settings({
enable_local_logins_via_email: true,
hide_email_address_taken: true,
enable_passkeys: false,
});
needs.pretender((server, helper) => {

View File

@ -10,9 +10,6 @@ acceptance("Login with email - no social logins", function (needs) {
needs.settings({ enable_local_logins_via_email: true });
needs.pretender((server, helper) => {
server.post("/u/email-login", () => helper.response({ success: "OK" }));
server.get(`/session/passkey/challenge.json`, () =>
helper.response({ challenge: "smth" })
);
});
test("with login with email enabled", async function (assert) {
await visit("/");

View File

@ -6,7 +6,6 @@ acceptance("Login with email disabled", function (needs) {
needs.settings({
enable_local_logins_via_email: false,
enable_facebook_logins: true,
enable_passkeys: false,
});
test("with email button", async function (assert) {

View File

@ -15,7 +15,6 @@ acceptance("Login with email", function (needs) {
needs.settings({
enable_local_logins_via_email: true,
enable_facebook_logins: true,
enable_passkeys: false,
});
let userFound = false;

View File

@ -7,13 +7,7 @@ import {
} from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
acceptance("New Message - Anonymous", function (needs) {
needs.pretender((server, helper) => {
server.get(`/session/passkey/challenge.json`, () =>
helper.response({ challenge: "smth" })
);
});
acceptance("New Message - Anonymous", function () {
test("accessing new-message route when logged out", async function (assert) {
await visit(
"/new-message?username=charlie&title=message%20title&body=message%20body"

View File

@ -3,13 +3,7 @@ import { test } from "qunit";
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
acceptance("New Topic - Anonymous", function (needs) {
needs.pretender((server, helper) => {
server.get(`/session/passkey/challenge.json`, () =>
helper.response({ challenge: "smth" })
);
});
acceptance("New Topic - Anonymous", function () {
test("accessing new-topic route when logged out", async function (assert) {
await visit("/new-topic?title=topic%20title&body=topic%20body");

View File

@ -6,13 +6,7 @@ import {
query,
} from "discourse/tests/helpers/qunit-helpers";
acceptance("Signing In", function (needs) {
needs.pretender((server, helper) => {
server.get(`/session/passkey/challenge.json`, () =>
helper.response({ challenge: "smth" })
);
});
acceptance("Signing In", function () {
test("sign in", async function (assert) {
await visit("/");
await click("header .login-button");

View File

@ -2,13 +2,7 @@ import { currentRouteName, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
acceptance("Static pages", function (needs) {
needs.pretender((server, helper) => {
server.get(`/session/passkey/challenge.json`, () =>
helper.response({ challenge: "smth" })
);
});
acceptance("Static pages", function () {
test("/faq", async function (assert) {
await visit("/faq");
assert.true(

View File

@ -1298,6 +1298,10 @@ export function applyDefaultHandlers(pretender) {
);
pretender.get("/c/:id/visible_groups.json", () => response({ groups: [] }));
pretender.get("/session/passkey/challenge.json", () =>
response({ challenge: "123" })
);
}
export function resetPretender() {