Fix integration manager get_open_id_token action and add E2E tests (#9520)

* Fix missing await

* Fix get openID token action requiring room ID and user ID

* Add e2e test for integration manager get openID token

* Remove outdated comment

* Update test description

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>

* Fix type

* Fix types again

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Justin Carlson 2022-11-15 12:03:47 -05:00 committed by GitHub
parent 663c7e069e
commit 8e42497e81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 149 additions and 8 deletions

View file

@ -376,7 +376,7 @@ function kickUser(event: MessageEvent<any>, roomId: string, userId: string): voi
});
}
function setWidget(event: MessageEvent<any>, roomId: string): void {
function setWidget(event: MessageEvent<any>, roomId: string | null): void {
const widgetId = event.data.widget_id;
let widgetType = event.data.type;
const widgetUrl = event.data.url;
@ -435,6 +435,7 @@ function setWidget(event: MessageEvent<any>, roomId: string): void {
} else { // Room widget
if (!roomId) {
sendError(event, _t('Missing roomId.'), null);
return;
}
WidgetUtils.setRoomWidget(roomId, widgetId, widgetType, widgetUrl, widgetName, widgetData, widgetAvatarUrl)
.then(() => {
@ -651,7 +652,7 @@ function returnStateEvent(event: MessageEvent<any>, roomId: string, eventType: s
async function getOpenIdToken(event: MessageEvent<any>) {
try {
const tokenObject = MatrixClientPeg.get().getOpenIdToken();
const tokenObject = await MatrixClientPeg.get().getOpenIdToken();
sendResponse(event, tokenObject);
} catch (ex) {
logger.warn("Unable to fetch openId token.", ex);
@ -706,15 +707,15 @@ const onMessage = function(event: MessageEvent<any>): void {
if (!roomId) {
// These APIs don't require roomId
// Get and set user widgets (not associated with a specific room)
// If roomId is specified, it must be validated, so room-based widgets agreed
// handled further down.
if (event.data.action === Action.GetWidgets) {
getWidgets(event, null);
return;
} else if (event.data.action === Action.SetWidget) {
setWidget(event, null);
return;
} else if (event.data.action === Action.GetOpenIdToken) {
getOpenIdToken(event);
return;
} else {
sendError(event, _t('Missing room_id in request'));
return;
@ -776,9 +777,6 @@ const onMessage = function(event: MessageEvent<any>): void {
case Action.SetBotPower:
setBotPower(event, roomId, userId, event.data.level, event.data.ignoreIfGreater);
break;
case Action.GetOpenIdToken:
getOpenIdToken(event);
break;
default:
logger.warn("Unhandled postMessage event with action '" + event.data.action +"'");
break;