diff --git a/cypress/e2e/login/login.spec.ts b/cypress/e2e/login/login.spec.ts index 1058287010..32a3babced 100644 --- a/cypress/e2e/login/login.spec.ts +++ b/cypress/e2e/login/login.spec.ts @@ -21,6 +21,10 @@ import { SynapseInstance } from "../../plugins/synapsedocker"; describe("Login", () => { let synapse: SynapseInstance; + beforeEach(() => { + cy.stubDefaultServer(); + }); + afterEach(() => { cy.stopSynapse(synapse); }); diff --git a/cypress/e2e/register/register.spec.ts b/cypress/e2e/register/register.spec.ts index 98ef2bd729..dacfe08bf8 100644 --- a/cypress/e2e/register/register.spec.ts +++ b/cypress/e2e/register/register.spec.ts @@ -22,6 +22,7 @@ describe("Registration", () => { let synapse: SynapseInstance; beforeEach(() => { + cy.stubDefaultServer(); cy.visit("/#/register"); cy.startSynapse("consent").then(data => { synapse = data; diff --git a/cypress/fixtures/matrix-org-client-login.json b/cypress/fixtures/matrix-org-client-login.json new file mode 100644 index 0000000000..d7c4fde1e5 --- /dev/null +++ b/cypress/fixtures/matrix-org-client-login.json @@ -0,0 +1,48 @@ +{ + "flows": [ + { + "type": "m.login.sso", + "identity_providers": [ + { + "id": "oidc-github", + "name": "GitHub", + "icon": "mxc://matrix.org/sVesTtrFDTpXRbYfpahuJsKP", + "brand": "github" + }, + { + "id": "oidc-google", + "name": "Google", + "icon": "mxc://matrix.org/ZlnaaZNPxtUuQemvgQzlOlkz", + "brand": "google" + }, + { + "id": "oidc-gitlab", + "name": "GitLab", + "icon": "mxc://matrix.org/MCVOEmFgVieKFshPxmnejWOq", + "brand": "gitlab" + }, + { + "id": "oidc-facebook", + "name": "Facebook", + "icon": "mxc://matrix.org/nsyeLIgzxazZmJadflMAsAWG", + "brand": "facebook" + }, + { + "id": "oidc-apple", + "name": "Apple", + "icon": "mxc://matrix.org/QQKNSOdLiMHtJhzeAObmkFiU", + "brand": "apple" + } + ] + }, + { + "type": "m.login.token" + }, + { + "type": "m.login.password" + }, + { + "type": "m.login.application_service" + } + ] +} diff --git a/cypress/fixtures/matrix-org-client-versions.json b/cypress/fixtures/matrix-org-client-versions.json new file mode 100644 index 0000000000..0e0cfae33d --- /dev/null +++ b/cypress/fixtures/matrix-org-client-versions.json @@ -0,0 +1,39 @@ +{ + "versions": [ + "r0.0.1", + "r0.1.0", + "r0.2.0", + "r0.3.0", + "r0.4.0", + "r0.5.0", + "r0.6.0", + "r0.6.1", + "v1.1", + "v1.2", + "v1.3", + "v1.4" + ], + "unstable_features": { + "org.matrix.label_based_filtering": true, + "org.matrix.e2e_cross_signing": true, + "org.matrix.msc2432": true, + "uk.half-shot.msc2666.mutual_rooms": true, + "io.element.e2ee_forced.public": false, + "io.element.e2ee_forced.private": false, + "io.element.e2ee_forced.trusted_private": false, + "org.matrix.msc3026.busy_presence": false, + "org.matrix.msc2285.stable": true, + "org.matrix.msc3827.stable": true, + "org.matrix.msc2716": false, + "org.matrix.msc3030": false, + "org.matrix.msc3440.stable": true, + "org.matrix.msc3771": true, + "org.matrix.msc3773": false, + "fi.mau.msc2815": false, + "org.matrix.msc3882": false, + "org.matrix.msc3881": false, + "org.matrix.msc3874": false, + "org.matrix.msc3886": false, + "org.matrix.msc3912": false + } + } diff --git a/cypress/fixtures/matrix-org-client-well-known.json b/cypress/fixtures/matrix-org-client-well-known.json new file mode 100644 index 0000000000..ed726e2421 --- /dev/null +++ b/cypress/fixtures/matrix-org-client-well-known.json @@ -0,0 +1,8 @@ +{ + "m.homeserver": { + "base_url": "https://matrix-client.matrix.org" + }, + "m.identity_server": { + "base_url": "https://vector.im" + } +} diff --git a/cypress/fixtures/vector-im-identity-v1.json b/cypress/fixtures/vector-im-identity-v1.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/cypress/fixtures/vector-im-identity-v1.json @@ -0,0 +1 @@ +{} diff --git a/cypress/support/network.ts b/cypress/support/network.ts index 73df049c6c..238c847184 100644 --- a/cypress/support/network.ts +++ b/cypress/support/network.ts @@ -20,10 +20,12 @@ declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace Cypress { interface Chainable { - // Intercept all /_matrix/ networking requests for the logged in user and fail them + // Intercept all /_matrix/ networking requests for the logged-in user and fail them goOffline(): void; // Remove intercept on all /_matrix/ networking requests goOnline(): void; + // Intercept calls to vector.im/matrix.org so a login page can be shown offline + stubDefaultServer(): void; } } } @@ -58,5 +60,29 @@ Cypress.Commands.add("goOnline", (): void => { }); }); +Cypress.Commands.add("stubDefaultServer", (): void => { + cy.log("Stubbing vector.im and matrix.org network calls"); + // We intercept vector.im & matrix.org calls so that tests don't fail when it has issues + cy.intercept("GET", "https://vector.im/_matrix/identity/api/v1", { + fixture: "vector-im-identity-v1.json", + }); + cy.intercept("GET", "https://matrix.org/.well-known/matrix/client", { + fixture: "matrix-org-client-well-known.json", + }); + cy.intercept("GET", "https://matrix-client.matrix.org/_matrix/client/versions", { + fixture: "matrix-org-client-versions.json", + }); + cy.intercept("GET", "https://matrix-client.matrix.org/_matrix/client/r0/login", { + fixture: "matrix-org-client-login.json", + }); + cy.intercept("POST", "https://matrix-client.matrix.org/_matrix/client/r0/register?kind=guest", { + statusCode: 403, + body: { + errcode: "M_FORBIDDEN", + error: "Registration is not enabled on this homeserver.", + }, + }); +}); + // Needed to make this file a module export { };