mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-09-01 03:08:41 +01:00
a825a7ddc5
* Support sovereign/PPE endpoint zones for connection string login Move the hardcoded account endpoint suffixes out of Constants and into ConfigContext so connection string login works in sovereign clouds and PPE, and widen ConnectionStringParser to accept every configured zone. Surface Portal Backend rejections in the hosted connect form: read the body off the Response that fetchEncryptedToken throws, and offer a firewall help link on a 403. Add an E2E test covering SQL connection string login against an account with public network access disabled. * Harden connection string DNS zone matching Detect PPE accounts from Mongo and Cassandra connection strings, build their document endpoint from the matched zone, match the PPE suffix on a label boundary, and escape every regex metacharacter in config-supplied zones. Drop the sqlx.cosmosdb.azure.com zone, which is not a real SQL zone. * Mock web-vitals globally in test setup ScenarioMonitor subscribes to web-vitals when it is imported, so the onTTFB timer can throw during any suite that outlives it. Mocking it in setupTests.ts keeps that out of individual test files. * Improve connection string login feedback * Preserve connection restriction check order * Flatten connection login error handling --------- Co-authored-by: Asier Isayas <aisayas@microsoft.com>
97 lines
2.7 KiB
TypeScript
97 lines
2.7 KiB
TypeScript
import { initializeIcons } from "@fluentui/react";
|
|
import { configure } from "enzyme";
|
|
import Adapter from "enzyme-adapter-react-16";
|
|
import "jest-canvas-mock";
|
|
import enableHooks from "jest-react-hooks-shallow";
|
|
import { TextDecoder, TextEncoder } from "util";
|
|
import i18n from "./i18n";
|
|
import enResources from "./Localization/en/Resources.json";
|
|
|
|
jest.mock("web-vitals");
|
|
|
|
configure({ adapter: new Adapter() });
|
|
initializeIcons();
|
|
|
|
// Load English translations synchronously so t() returns real values in tests
|
|
i18n.addResourceBundle("en", "Resources", enResources, true, true);
|
|
|
|
if (typeof window.URL.createObjectURL === "undefined") {
|
|
Object.defineProperty(window.URL, "createObjectURL", { value: () => {} });
|
|
}
|
|
|
|
enableHooks(jest, { dontMockByDefault: true });
|
|
|
|
const localStorageMock = (function () {
|
|
let store: { [key: string]: string } = {};
|
|
return {
|
|
getItem: function (key: string) {
|
|
return store[key] || null;
|
|
},
|
|
setItem: function (key: string, value: string) {
|
|
store[key] = value.toString();
|
|
},
|
|
removeItem: function (key: string) {
|
|
delete store[key];
|
|
},
|
|
clear: function () {
|
|
store = {};
|
|
},
|
|
};
|
|
})();
|
|
|
|
Object.defineProperty(window, "localStorage", {
|
|
value: localStorageMock,
|
|
});
|
|
|
|
// TODO Remove when jquery and documentdbclient SDK are removed
|
|
(<any>window).$ = (<any>window).jQuery = require("jquery");
|
|
(<any>global).$ = (<any>global).$.jQuery = require("jquery");
|
|
require("jquery-ui-dist/jquery-ui");
|
|
(<any>global).TextEncoder = TextEncoder;
|
|
(<any>global).TextDecoder = TextDecoder;
|
|
|
|
(<any>global).ResizeObserver = jest.fn().mockImplementation(() => ({
|
|
observe: jest.fn(),
|
|
unobserve: jest.fn(),
|
|
disconnect: jest.fn(),
|
|
}));
|
|
|
|
// The test environment Data Explorer uses does not have crypto.subtle implementation
|
|
(<any>global).crypto.subtle = {};
|
|
|
|
// Mock Performance API for scenario monitoring
|
|
const performanceMock = {
|
|
...(typeof performance !== "undefined" ? performance : {}),
|
|
mark: jest.fn(),
|
|
measure: jest.fn(),
|
|
clearMarks: jest.fn(),
|
|
clearMeasures: jest.fn(),
|
|
getEntriesByName: jest.fn().mockReturnValue([]),
|
|
getEntriesByType: jest.fn().mockReturnValue([]),
|
|
now: jest.fn(() => Date.now()),
|
|
timeOrigin: Date.now(),
|
|
};
|
|
|
|
// Assign to both global and window
|
|
Object.defineProperty(global, "performance", {
|
|
writable: true,
|
|
configurable: true,
|
|
value: performanceMock,
|
|
});
|
|
|
|
Object.defineProperty(window, "performance", {
|
|
writable: true,
|
|
configurable: true,
|
|
value: performanceMock,
|
|
});
|
|
|
|
// Mock fetch API - minimal mock to prevent errors
|
|
(<any>global).fetch = jest.fn(() =>
|
|
Promise.resolve({
|
|
ok: true,
|
|
status: 200,
|
|
json: () => Promise.resolve({}),
|
|
text: () => Promise.resolve(""),
|
|
}),
|
|
);
|