This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 828
Add support for redirecting to external pages after logout #7905
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d9e41b1
Add support for redirecting to external pages after logout
turt2live 4c438c9
Add e2e test and fix Windows instructions
turt2live b794f77
Fix performance gathering stats
turt2live 6e7eac7
Merge branch 'develop' into travis/logout-customisations
turt2live 9277f7a
use logger
turt2live 304b697
Merge branch 'develop' into travis/logout-customisations
turt2live File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { strict as assert } from "assert"; | ||
|
||
import { ElementSession } from "../session"; | ||
import { logout } from "../usecases/logout"; | ||
import { applyConfigChange } from "../util"; | ||
|
||
export async function ssoCustomisationScenarios(session: ElementSession): Promise<void> { | ||
console.log(" injecting logout customisations for SSO scenarios:"); | ||
|
||
await session.delay(1000); // wait for dialogs to close | ||
await applyConfigChange(session, { | ||
// we redirect to config.json because it's a predictable page that isn't Element | ||
// itself. We could use example.org, matrix.org, or something else, however this | ||
// puts dependency of external infrastructure on our tests. In the same vein, we | ||
// don't really want to figure out how to ship a `test-landing.html` page when | ||
// running with an uncontrolled Element (via `./run.sh --app-url http://localhost:8080`). | ||
// Using the config.json is just as fine, and we can search for strategic names. | ||
'logout_redirect_url': '/config.json', | ||
}); | ||
|
||
await logoutCanCauseRedirect(session); | ||
} | ||
|
||
async function logoutCanCauseRedirect(session: ElementSession): Promise<void> { | ||
await logout(session, false); // we'll check the login page ourselves, so don't assert | ||
|
||
session.log.step("waits for redirect to config.json (as external page)"); | ||
const foundLoginUrl = await session.poll(async () => { | ||
const url = session.page.url(); | ||
return url === session.url('/config.json'); | ||
}); | ||
assert(foundLoginUrl); | ||
session.log.done(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { strict as assert } from 'assert'; | ||
|
||
import { ElementSession } from "../session"; | ||
|
||
export async function logout(session: ElementSession, assertLoginPage = true): Promise<void> { | ||
session.log.startGroup("logs out"); | ||
|
||
session.log.step("navigates to user menu"); | ||
const userButton = await session.query('.mx_UserMenu > div.mx_AccessibleButton'); | ||
await userButton.click(); | ||
session.log.done(); | ||
|
||
session.log.step("clicks the 'Sign Out' button"); | ||
const signOutButton = await session.query('.mx_UserMenu_contextMenu .mx_UserMenu_iconSignOut'); | ||
await signOutButton.click(); | ||
session.log.done(); | ||
|
||
if (assertLoginPage) { | ||
const foundLoginUrl = await session.poll(async () => { | ||
const url = session.page.url(); | ||
return url === session.url('/#/login'); | ||
}); | ||
assert(foundLoginUrl); | ||
} | ||
|
||
session.log.endGroup(); | ||
} |
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,6 +1,6 @@ | ||
/* | ||
Copyright 2018 New Vector Ltd | ||
Copyright 2019 The Matrix.org Foundation C.I.C. | ||
Copyright 2019 - 2022 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
|
@@ -40,3 +40,14 @@ export const measureStop = function(session: ElementSession, name: string): Prom | |
window.mxPerformanceMonitor.stop(_name); | ||
}, name); | ||
}; | ||
|
||
// TODO: Proper types on `config` - for some reason won't accept an import of ConfigOptions. | ||
export async function applyConfigChange(session: ElementSession, config: any): Promise<void> { | ||
await session.page.evaluate((_config) => { | ||
// note: we can't *set* the object because the window version is effectively a pointer. | ||
for (const [k, v] of Object.entries(_config)) { | ||
// @ts-ignore - for some reason it's not picking up on global.d.ts types. | ||
window.mxReactSdkConfig[k] = v; | ||
} | ||
}, config); | ||
} | ||
Comment on lines
+44
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know why the types aren't working, but including the types is a worthwhile improvement. Fixing them feels a bit out of scope for this PR (or at least too far out of scope from where it's already at). |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updating the instructions for Windows was just easier to do in this PR than others, sorry.