Fix CORS issue using Mongo Shell from new origin (#1422)

* Fix CORS issue using Mongo Shell from new origin

* Add unit tests for getMongoShellOrigin and getMongoShellUrl

* Fix lint errors
This commit is contained in:
Armando Trejo Oliver
2023-04-04 18:19:18 -07:00
committed by GitHub
parent 9d2d0e4754
commit 874cec26fc
5 changed files with 315 additions and 36 deletions

View File

@@ -0,0 +1,73 @@
import { extractFeatures } from "Platform/Hosted/extractFeatures";
import { configContext } from "../../../ConfigContext";
import { updateUserContext } from "../../../UserContext";
import { getMongoShellOrigin } from "./getMongoShellOrigin";
describe("getMongoShellOrigin", () => {
(window as { origin: string }).origin = "window_origin";
beforeEach(() => {
updateUserContext({
features: extractFeatures(
new URLSearchParams({
"feature.enableLegacyMongoShellV1": "false",
"feature.enableLegacyMongoShellV2": "false",
"feature.enableLegacyMongoShellV1Dist": "false",
"feature.enableLegacyMongoShellV2Dist": "false",
})
),
});
});
it("should return BACKEND_ENDPOINT by default", () => {
expect(getMongoShellOrigin()).toBe(configContext.BACKEND_ENDPOINT);
});
it("should return /mongoshell/index.html when enableLegacyMongoShellV1", () => {
updateUserContext({
features: extractFeatures(
new URLSearchParams({
"feature.enableLegacyMongoShellV1": "true",
})
),
});
expect(getMongoShellOrigin()).toBe(window.origin);
});
it("should return /mongoshell/index.html when enableLegacyMongoShellV2===true", () => {
updateUserContext({
features: extractFeatures(
new URLSearchParams({
"feature.enableLegacyMongoShellV2": "true",
})
),
});
expect(getMongoShellOrigin()).toBe(window.origin);
});
it("should return /mongoshell/index.html when enableLegacyMongoShellV1Dist===true", () => {
updateUserContext({
features: extractFeatures(
new URLSearchParams({
"feature.enableLegacyMongoShellV1Dist": "true",
})
),
});
expect(getMongoShellOrigin()).toBe(window.origin);
});
it("should return /mongoshell/index.html when enableLegacyMongoShellV2Dist===true", () => {
updateUserContext({
features: extractFeatures(
new URLSearchParams({
"feature.enableLegacyMongoShellV2Dist": "true",
})
),
});
expect(getMongoShellOrigin()).toBe(window.origin);
});
});