|
| 1 | +/* |
| 2 | +Copyright 2022 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import { strict as assert } from "assert"; |
| 18 | + |
| 19 | +import { ElementSession } from "../session"; |
| 20 | +import { logout } from "../usecases/logout"; |
| 21 | +import { applyConfigChange } from "../util"; |
| 22 | + |
| 23 | +export async function ssoCustomisationScenarios(session: ElementSession): Promise<void> { |
| 24 | + console.log(" injecting logout customisations for SSO scenarios:"); |
| 25 | + |
| 26 | + await session.delay(1000); // wait for dialogs to close |
| 27 | + await applyConfigChange(session, { |
| 28 | + // we redirect to config.json because it's a predictable page that isn't Element |
| 29 | + // itself. We could use example.org, matrix.org, or something else, however this |
| 30 | + // puts dependency of external infrastructure on our tests. In the same vein, we |
| 31 | + // don't really want to figure out how to ship a `test-landing.html` page when |
| 32 | + // running with an uncontrolled Element (via `./run.sh --app-url http://localhost:8080`). |
| 33 | + // Using the config.json is just as fine, and we can search for strategic names. |
| 34 | + 'logout_redirect_url': '/config.json', |
| 35 | + }); |
| 36 | + |
| 37 | + await logoutCanCauseRedirect(session); |
| 38 | +} |
| 39 | + |
| 40 | +async function logoutCanCauseRedirect(session: ElementSession): Promise<void> { |
| 41 | + await logout(session, false); // we'll check the login page ourselves, so don't assert |
| 42 | + |
| 43 | + session.log.step("waits for redirect to config.json (as external page)"); |
| 44 | + const foundLoginUrl = await session.poll(async () => { |
| 45 | + const url = session.page.url(); |
| 46 | + return url === session.url('/config.json'); |
| 47 | + }); |
| 48 | + assert(foundLoginUrl); |
| 49 | + session.log.done(); |
| 50 | +} |
0 commit comments