mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-25 06:56:38 +00:00
Make MongoShell ready message handler backwards compatible (#606)
* Make MongShell message handler backwards compatible * Fix test title and add one more test case
This commit is contained in:
parent
bd9bdad78a
commit
1b9070605e
26512
package-lock.json
generated
26512
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -6,11 +6,11 @@ import * as ViewModels from "../../Contracts/ViewModels";
|
|||||||
import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants";
|
import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants";
|
||||||
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
||||||
import { userContext } from "../../UserContext";
|
import { userContext } from "../../UserContext";
|
||||||
import { isInvalidParentFrameOrigin } from "../../Utils/MessageValidation";
|
import { isInvalidParentFrameOrigin, isReadyMessage } from "../../Utils/MessageValidation";
|
||||||
import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils";
|
import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils";
|
||||||
import Explorer from "../Explorer";
|
import Explorer from "../Explorer";
|
||||||
import template from "./MongoShellTab.html";
|
|
||||||
import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent";
|
import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent";
|
||||||
|
import template from "./MongoShellTab.html";
|
||||||
import TabsBase from "./TabsBase";
|
import TabsBase from "./TabsBase";
|
||||||
|
|
||||||
export default class MongoShellTab extends TabsBase {
|
export default class MongoShellTab extends TabsBase {
|
||||||
@ -85,10 +85,7 @@ export default class MongoShellTab extends TabsBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private handleReadyMessage(event: MessageEvent, shellIframe: HTMLIFrameElement) {
|
private handleReadyMessage(event: MessageEvent, shellIframe: HTMLIFrameElement) {
|
||||||
if (typeof event.data["kind"] !== "string") {
|
if (!isReadyMessage(event)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.data.kind !== "ready") {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,26 +1,44 @@
|
|||||||
import { isInvalidParentFrameOrigin } from "./MessageValidation";
|
import { isInvalidParentFrameOrigin, isReadyMessage } from "./MessageValidation";
|
||||||
|
|
||||||
test.each`
|
describe("isInvalidParentFrameOrigin", () => {
|
||||||
domain | expected
|
test.each`
|
||||||
${"https://cosmos.azure.com"} | ${false}
|
domain | expected
|
||||||
${"https://cosmos.azure.us"} | ${false}
|
${"https://cosmos.azure.com"} | ${false}
|
||||||
${"https://cosmos.azure.cn"} | ${false}
|
${"https://cosmos.azure.us"} | ${false}
|
||||||
${"https://portal.azure.com"} | ${false}
|
${"https://cosmos.azure.cn"} | ${false}
|
||||||
${"https://portal.azure.us"} | ${false}
|
${"https://portal.azure.com"} | ${false}
|
||||||
${"https://portal.azure.cn"} | ${false}
|
${"https://portal.azure.us"} | ${false}
|
||||||
${"https://portal.microsoftazure.de"} | ${false}
|
${"https://portal.azure.cn"} | ${false}
|
||||||
${"https://subdomain.portal.azure.com"} | ${false}
|
${"https://portal.microsoftazure.de"} | ${false}
|
||||||
${"https://subdomain.portal.azure.us"} | ${false}
|
${"https://subdomain.portal.azure.com"} | ${false}
|
||||||
${"https://subdomain.portal.azure.cn"} | ${false}
|
${"https://subdomain.portal.azure.us"} | ${false}
|
||||||
${"https://main.documentdb.ext.azure.com"} | ${false}
|
${"https://subdomain.portal.azure.cn"} | ${false}
|
||||||
${"https://main.documentdb.ext.azure.us"} | ${false}
|
${"https://main.documentdb.ext.azure.com"} | ${false}
|
||||||
${"https://main.documentdb.ext.azure.cn"} | ${false}
|
${"https://main.documentdb.ext.azure.us"} | ${false}
|
||||||
${"https://main.documentdb.ext.microsoftazure.de"} | ${false}
|
${"https://main.documentdb.ext.azure.cn"} | ${false}
|
||||||
${"https://random.domain"} | ${true}
|
${"https://main.documentdb.ext.microsoftazure.de"} | ${false}
|
||||||
${"https://malicious.cloudapp.azure.com"} | ${true}
|
${"https://random.domain"} | ${true}
|
||||||
${"https://malicious.germanycentral.cloudapp.microsoftazure.de"} | ${true}
|
${"https://malicious.cloudapp.azure.com"} | ${true}
|
||||||
${"https://maliciousazure.com"} | ${true}
|
${"https://malicious.germanycentral.cloudapp.microsoftazure.de"} | ${true}
|
||||||
${"https://maliciousportalsazure.com"} | ${true}
|
${"https://maliciousazure.com"} | ${true}
|
||||||
`("returns $expected when called with $domain", ({ domain, expected }) => {
|
${"https://maliciousportalsazure.com"} | ${true}
|
||||||
expect(isInvalidParentFrameOrigin({ origin: domain } as MessageEvent)).toBe(expected);
|
`("returns $expected when called with $domain", ({ domain, expected }) => {
|
||||||
|
expect(isInvalidParentFrameOrigin({ origin: domain } as MessageEvent)).toBe(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("isReadyMessage", () => {
|
||||||
|
test.each`
|
||||||
|
event | expected
|
||||||
|
${{ data: { kind: "ready" } }} | ${true}
|
||||||
|
${{ data: { data: "ready" } }} | ${true}
|
||||||
|
${{ data: { data: "ready", kind: "ready" } }} | ${true}
|
||||||
|
${{ data: { kind: "not-ready" } }} | ${false}
|
||||||
|
${{ data: { data: "not-ready" } }} | ${false}
|
||||||
|
${{ data: { data: "not-ready", kind: "not-ready" } }} | ${false}
|
||||||
|
${{ data: {} }} | ${false}
|
||||||
|
${{}} | ${false}
|
||||||
|
`("returns $expected when called with $event", ({ event, expected }) => {
|
||||||
|
expect(isReadyMessage(event as MessageEvent)).toBe(expected);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -20,3 +20,15 @@ function isValidOrigin(allowedOrigins: string[], event: MessageEvent): boolean {
|
|||||||
console.error(`Invalid parent frame origin detected: ${eventOrigin}`);
|
console.error(`Invalid parent frame origin detected: ${eventOrigin}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isReadyMessage(event: MessageEvent): boolean {
|
||||||
|
if (!event?.data?.kind && !event?.data?.data) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.data.kind !== "ready" && event.data.data !== "ready") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user