This repository was archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 819
Fix integration manager get_open_id_token
action and add E2E tests
#9520
Merged
turt2live
merged 13 commits into
matrix-org:develop
from
justinbot:justinbot/fix-get-openid-token
Nov 15, 2022
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cb75219
Fix missing await
justinbot 2563095
Fix get openID token action requiring room ID and user ID
justinbot 325b4fe
Add e2e test for integration manager get openID token
justinbot e1e18c5
Merge branch 'develop' into justinbot/fix-get-openid-token
justinbot 5607f58
Remove outdated comment
justinbot 0f11ab0
Update test description
justinbot a0dfe50
Merge branch 'develop' into justinbot/fix-get-openid-token
justinbot 32c483d
Merge branch 'develop' into justinbot/fix-get-openid-token
justinbot 0c90afa
Fix type
justinbot 5a7ec9f
Merge branch 'develop' into justinbot/fix-get-openid-token
justinbot 90bf404
Fix types again
justinbot 8924eb2
Merge branch 'develop' into justinbot/fix-get-openid-token
justinbot 7be8dd3
Merge branch 'develop' into justinbot/fix-get-openid-token
t3chguy 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
143 changes: 143 additions & 0 deletions
143
cypress/e2e/integration-manager/get-openid-token.spec.ts
This file contains hidden or 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,143 @@ | ||
/* | ||
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. | ||
*/ | ||
|
||
/// <reference types="cypress" /> | ||
|
||
import { SynapseInstance } from "../../plugins/synapsedocker"; | ||
import { UserCredentials } from "../../support/login"; | ||
|
||
const ROOM_NAME = "Integration Manager Test"; | ||
const USER_DISPLAY_NAME = "Alice"; | ||
|
||
const INTEGRATION_MANAGER_TOKEN = "DefinitelySecret_DoNotUseThisForReal"; | ||
const INTEGRATION_MANAGER_HTML = ` | ||
<html lang="en"> | ||
<head> | ||
<title>Fake Integration Manager</title> | ||
</head> | ||
<body> | ||
<button name="Send" id="send-action">Press to send action</button> | ||
<button name="Close" id="close">Press to close</button> | ||
<p id="message-response">No response</p> | ||
<script> | ||
document.getElementById("send-action").onclick = () => { | ||
window.parent.postMessage( | ||
{ | ||
action: "get_open_id_token", | ||
}, | ||
'*', | ||
); | ||
}; | ||
document.getElementById("close").onclick = () => { | ||
window.parent.postMessage( | ||
{ | ||
action: "close_scalar", | ||
}, | ||
'*', | ||
); | ||
}; | ||
// Listen for a postmessage response | ||
window.addEventListener("message", (event) => { | ||
document.getElementById("message-response").innerText = JSON.stringify(event.data); | ||
}); | ||
</script> | ||
</body> | ||
</html> | ||
`; | ||
|
||
function openIntegrationManager() { | ||
cy.get(".mx_RightPanel_roomSummaryButton").click(); | ||
cy.get(".mx_RoomSummaryCard_appsGroup").within(() => { | ||
cy.contains("Add widgets, bridges & bots").click(); | ||
}); | ||
} | ||
|
||
function sendActionFromIntegrationManager(integrationManagerUrl: string) { | ||
cy.accessIframe(`iframe[src*="${integrationManagerUrl}"]`).within(() => { | ||
cy.get("#send-action").should("exist").click(); | ||
}); | ||
} | ||
|
||
describe("Integration Manager: Get OpenID Token", () => { | ||
let testUser: UserCredentials; | ||
let synapse: SynapseInstance; | ||
let integrationManagerUrl: string; | ||
|
||
beforeEach(() => { | ||
cy.serveHtmlFile(INTEGRATION_MANAGER_HTML).then(url => { | ||
integrationManagerUrl = url; | ||
}); | ||
cy.startSynapse("default").then(data => { | ||
synapse = data; | ||
|
||
cy.initTestUser(synapse, USER_DISPLAY_NAME, () => { | ||
cy.window().then(win => { | ||
win.localStorage.setItem("mx_scalar_token", INTEGRATION_MANAGER_TOKEN); | ||
win.localStorage.setItem(`mx_scalar_token_at_${integrationManagerUrl}`, INTEGRATION_MANAGER_TOKEN); | ||
}); | ||
}).then(user => { | ||
testUser = user; | ||
}); | ||
|
||
cy.setAccountData("m.widgets", { | ||
"m.integration_manager": { | ||
content: { | ||
type: "m.integration_manager", | ||
name: "Integration Manager", | ||
url: integrationManagerUrl, | ||
data: { | ||
api_url: integrationManagerUrl, | ||
}, | ||
}, | ||
id: "integration-manager", | ||
}, | ||
}).as("integrationManager"); | ||
|
||
// Succeed when checking the token is valid | ||
cy.intercept(`${integrationManagerUrl}/account?scalar_token=${INTEGRATION_MANAGER_TOKEN}*`, req => { | ||
req.continue(res => { | ||
return res.send(200, { | ||
user_id: testUser.userId, | ||
}); | ||
}); | ||
}); | ||
|
||
cy.createRoom({ | ||
name: ROOM_NAME, | ||
}).as("roomId"); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
cy.stopSynapse(synapse); | ||
cy.stopWebServers(); | ||
}); | ||
|
||
it("should successfully obtain an openID token", () => { | ||
cy.all([ | ||
cy.get<{}>("@integrationManager"), | ||
]).then(() => { | ||
cy.viewRoomByName(ROOM_NAME); | ||
|
||
openIntegrationManager(); | ||
sendActionFromIntegrationManager(integrationManagerUrl); | ||
|
||
cy.accessIframe(`iframe[src*="${integrationManagerUrl}"]`).within(() => { | ||
cy.get("#message-response").should('include.text', 'access_token'); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.