mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-10-13 15:28:05 +01:00
* Upgrade packages to enable npm i with node 18 * Fix crypto and querystring issue * Fix webpack errors during npm start * Upgrade monaco editor. Fix alias in webconfig * Remove deprecated file-loader. Upgrade webpack to latest. * Fix format * Upgrade webpack, eslint and typescript * Update p-retry and fluentui packages * Revert monaco package upgrade * Fix notebook compile errors * Fix lint errors * Update jest snapshots * Fix unit tests * Update node version to 18 * Fix compile error * Fix compile error * Fix format * Turn off warning overlay for webpack devServer * Fix format * Re-add monaco webpack plugin and upgrade monaco-editor * Update package-lock.json * Fix build issue * Move MonacoWebpackPlugin to previous place in webpack.config.js * update package-lock.json * Fix package-lock.json * Update package-lock.json * Fix export ChoiceItem not found warning for self serve. Remove warning turn off in webpack config. * Update checkout and setup actions in for ci tests * Disable Gallery callout * Fix disable gallery header * Totally disable New gallery callout * Upgrade all github actions to latest
56 lines
3.6 KiB
TypeScript
56 lines
3.6 KiB
TypeScript
import { AuthType } from "../AuthType";
|
|
import * as Constants from "../Common/Constants";
|
|
import { updateUserContext } from "../UserContext";
|
|
import * as AuthorizationUtils from "./AuthorizationUtils";
|
|
jest.mock("../Explorer/Explorer");
|
|
|
|
describe("AuthorizationUtils", () => {
|
|
describe("getAuthorizationHeader()", () => {
|
|
it("should return authorization header if authentication type is AAD", () => {
|
|
updateUserContext({
|
|
authType: AuthType.AAD,
|
|
authorizationToken: "some-token",
|
|
});
|
|
|
|
expect(AuthorizationUtils.getAuthorizationHeader().header).toBe(Constants.HttpHeaders.authorization);
|
|
expect(AuthorizationUtils.getAuthorizationHeader().token).toBe("some-token");
|
|
});
|
|
|
|
it("should return guest access header if authentication type is EncryptedToken", () => {
|
|
updateUserContext({
|
|
authType: AuthType.EncryptedToken,
|
|
accessToken: "some-token",
|
|
});
|
|
|
|
expect(AuthorizationUtils.getAuthorizationHeader().header).toBe(Constants.HttpHeaders.guestAccessToken);
|
|
expect(AuthorizationUtils.getAuthorizationHeader().token).toBe("some-token");
|
|
});
|
|
});
|
|
|
|
describe("decryptJWTToken()", () => {
|
|
it("should throw an error if token is undefined", () => {
|
|
expect(() => AuthorizationUtils.decryptJWTToken(undefined)).toThrow();
|
|
});
|
|
|
|
it("should throw an error if token is empty", () => {
|
|
expect(() => AuthorizationUtils.decryptJWTToken("")).toThrow();
|
|
});
|
|
|
|
it("should throw an error if token is malformed", () => {
|
|
expect(() =>
|
|
AuthorizationUtils.decryptJWTToken(
|
|
"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImFQY3R3X29kdlJPb0VOZzNWb09sSWgydGlFcyIsImtpZCI6ImFQY3R3X29kdlJPb0VOZzNWb09sSWgydGlFcyJ9.",
|
|
),
|
|
).toThrow();
|
|
});
|
|
|
|
it("should return decrypted token payload", () => {
|
|
expect(
|
|
AuthorizationUtils.decryptJWTToken(
|
|
"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImFQY3R3X29kdlJPb0VOZzNWb09sSWgydGlFcyIsImtpZCI6ImFQY3R3X29kdlJPb0VOZzNWb09sSWgydGlFcyJ9.eyJhdWQiOiJodHRwczovL3dvcmtzcGFjZWFydGlmYWN0cy5wcm9qZWN0YXJjYWRpYS5uZXQiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC83MmY5ODhiZi04NmYxLTQxYWYtOTFhYi0yZDdjZDAxMWRiNDcvIiwiaWF0IjoxNTcxOTUwMjIwLCJuYmYiOjE1NzE5NTAyMjAsImV4cCI6MTU3MTk1NDEyMCwiYWNyIjoiMSIsImFpbyI6IkFWUUFxLzhOQUFBQVJ5c1pWWW1qV3lqeG1zU3VpdUdGbUZLSEwxKytFM2JBK0xhck5mMUVYUnZ1MFB6bDlERWFaMVNMdi8vSXlscG5hanFwZG1aSjFaSXNZUEN0UzJrY1lJbWdTVjFvUitsM2VlNWZlT1JZRjZvPSIsImFtciI6WyJyc2EiLCJtZmEiXSwiYXBwaWQiOiIyMDNm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