Skip to content

[FIX] Upgrade Keycloak #3435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions services/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"sharp": "^0.33.3",
"style-loader": "4.0.0",
"ts-jest": "29.2.5",
"typescript": "4.7.4",
"typescript": "5.7.3",
"undici": "6.19.7",
"webpack": "5.95.0",
"webpack-cli": "5.1.4",
Expand All @@ -86,4 +86,4 @@
"jest-junit": {
"output": "./coverage/tests-report.xml"
}
}
}
4 changes: 4 additions & 0 deletions services/common/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ jest.mock("react", () => {
};
});

jest.mock("keycloak-js", () => {
return jest.fn()
});

jest.mock("@mds/common/providers/featureFlags/useFeatureFlag", () => ({
useFeatureFlag: () => ({
isFeatureEnabled: () => true,
Expand Down
2 changes: 1 addition & 1 deletion services/common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"declarationMap": true,
"declarationDir": "dist",
"module": "ESNext",
"moduleResolution": "node",
"moduleResolution": "bundler",
"sourceMap": true,
"allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
"checkJs": true /* Enable error reporting in type-checked JavaScript files. */,
Expand Down
6 changes: 3 additions & 3 deletions services/core-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"filepond-polyfill": "1.0.4",
"hoist-non-react-statics": "3.3.2",
"jest-localstorage-mock": "2.4.26",
"keycloak-js": "20.0.1",
"keycloak-js": "26.2.0",
"leaflet": "1.5.1",
"leaflet.markercluster": "1.4.1",
"leaflet.wms": "0.2.0",
Expand Down Expand Up @@ -130,7 +130,7 @@
"ts-jest": "29.2.5",
"ts-node": "^10.9.1",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"typescript": "4.7.4",
"typescript": "5.7.3",
"undici": "^6.19.7",
"url-loader": "4.1.1",
"webpack": "5.95.0",
Expand Down Expand Up @@ -175,4 +175,4 @@
"browserslist": [
"> 0.1%"
]
}
}
4 changes: 4 additions & 0 deletions services/core-web/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ jest.mock("@mds/common/providers/featureFlags/useFeatureFlag", () => ({
}),
}));

jest.mock("keycloak-js", () => {
return jest.fn()
});

window.scrollTo = jest.fn();
const location = JSON.stringify(window.location);
delete window.location;
Expand Down
54 changes: 13 additions & 41 deletions services/core-web/src/tests/components/Index.spec.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,25 @@
import React from "react";
import { shallow } from "enzyme";
import { render } from "@testing-library/react";
import { Index } from "../../index";
import Loading from "@/components/common/Loading";
import { getKeycloakMock } from "../mocks/keycloakMocks";
import { MessageChannel } from "worker_threads";
window.MessageChannel = MessageChannel;

// import { waitFor } from '@testing-library/react';
jest.mock("@mds/common/keycloak", () => ({
default: {
token: "mocked-token",
},
keycloak: {
init: jest.fn(),
authenticated: Boolean,
login: jest.fn(),
tokenParsed: {
client_roles: []
}
}
}));

const stateSetter = jest.fn();

// allows mock keycloak to have different properties in each test
beforeEach(() => {
jest.resetModules();
});

it("Index: redirects unauthenticated to login", async () => {
getKeycloakMock(true, false);
const component = shallow(<Index />);
jest
.spyOn(React, "useState")
.mockImplementation((stateValue) => [(stateValue = true), stateSetter]);

// TODO: make this work
// await waitFor(() => expect(getByText("MINES DIGITAL SERVICES (MDS) (PUBLIC CLIENT)")).toBeInTheDocument())
// expect(component).toMatchSnapshot();
});

it("Index: shows loading before keycloak is instantiated", () => {
const { container } = render(<Index disableEnvLoading={true} />);
expect(container).toMatchSnapshot();
});

it("Index: token is automatically refreshed while user is active", () => {
getKeycloakMock();
const component = shallow(<Index />);
// modify the buffer time and idle timeout for a faster test -> 2 seconds?
// mock an access token within keycloak -> set expiry for short period -> 5 seconds?
// fire an action that registers as active (contenders: mousemove, keydown, focus)
// it would try to refresh token after 3s (expiry - buffer)
// EXPECT: handleUpdateToken was called
// EXPECT: new token has different expiry
});

it("Index: token is not refreshed when user is not active", () => {
getKeycloakMock();
const component = shallow(<Index />);
// similar to above, but do not fire action
// EXPECT: handleUpdateToken was not called
// EXPECT: token is the same
});
32 changes: 24 additions & 8 deletions services/core-web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"jsx": "react",
"paths": {
"@common/*": ["common/*"],
"@mds/common": ["../common/src"],
"@mds/common/*": ["../common/src/*"],
"@/*": ["src/*"]
"@common/*": [
"common/*"
],
"@mds/common": [
"../common/src"
],
"@mds/common/*": [
"../common/src/*"
],
"@/*": [
"src/*"
]
},
"module": "ESNext",
"moduleResolution": "node",
"moduleResolution": "bundler",
"sourceMap": true,
"allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
Expand All @@ -21,6 +29,14 @@
"noImplicitAny": false /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"include": ["src/**/*", "common/**/*", "../common/src/@Types/**/*"],
"exclude": ["node_modules", "src/**/*.test.ts", "src/**/*.test.tsx"]
}
"include": [
"src/**/*",
"common/**/*",
"../common/src/@Types/**/*"
],
"exclude": [
"node_modules",
"src/**/*.test.ts",
"src/**/*.test.tsx"
]
}
4 changes: 2 additions & 2 deletions services/minespace-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"fork-ts-checker-webpack-plugin": "9.0.2",
"hoist-non-react-statics": "3.3.2",
"jsonwebtoken": "9.0.2",
"keycloak-js": "20.0.1",
"keycloak-js": "26.2.0",
"leaflet": "1.5.1",
"leaflet.markercluster": "1.4.1",
"lodash-es": "4.17.21",
Expand Down Expand Up @@ -104,7 +104,7 @@
"ts-jest": "29.2.5",
"ts-loader": "9.5.1",
"ts-node": "10.9.1",
"typescript": "4.7.4",
"typescript": "5.7.3",
"undici": "6.19.7",
"url-loader": "4.1.1",
"webpack": "5.95.0",
Expand Down
4 changes: 4 additions & 0 deletions services/minespace-web/src/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jest.mock("@mds/common/providers/featureFlags/useFeatureFlag", () => ({
}),
}));

jest.mock("keycloak-js", () => {
return jest.fn();
});

const location = JSON.stringify(window.location);
delete window.location;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
import { KEYCLOAK } from "@mds/common/constants/environment";
import keycloak from "@mds/common/keycloak";
import { signOutFromSSO, signOutFromSiteMinder } from "@/utils/authenticationHelpers";
import {
KEYCLOAK_LOGOUT_REDIRECT_URI,
SITEMINDER_LOGOUT_REDIRECT_URI,
} from "@/constants/environment";

// TODO: FIX SSO MIGRATION TEST
describe("`signOutFromSSO` function", () => {
jest.spyOn(keycloak, "logout");
it.skip("opens a new window with given url", () => {
signOutFromSSO();
expect(keycloak.logout).toHaveBeenCalledWith({
redirectUri: KEYCLOAK_LOGOUT_REDIRECT_URI,
});
});
});
import { signOutFromSiteMinder } from "@/utils/authenticationHelpers";
import { SITEMINDER_LOGOUT_REDIRECT_URI } from "@/constants/environment";

describe("`signOutFromSiteMinder` function", () => {
jest.spyOn(window, "open");
Expand Down
2 changes: 1 addition & 1 deletion services/minespace-web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@/*": ["src/*"]
},
"module": "ESNext",
"moduleResolution": "node",
"moduleResolution": "bundler",
"sourceMap": true,
"allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
// "checkJs": true /* Enable error reporting in type-checked JavaScript files. */,
Expand Down
46 changes: 18 additions & 28 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ __metadata:
style-loader: 4.0.0
ts-jest: 29.2.5
ts-loader: 9.5.1
typescript: 4.7.4
typescript: 5.7.3
undici: 6.19.7
webpack: 5.95.0
webpack-cli: 5.1.4
Expand Down Expand Up @@ -1782,7 +1782,7 @@ __metadata:
jest-junit: 16.0.0
jest-localstorage-mock: 2.4.26
jest-sonar-reporter: 2.0.0
keycloak-js: 20.0.1
keycloak-js: 26.2.0
leaflet: 1.5.1
leaflet.markercluster: 1.4.1
leaflet.wms: 0.2.0
Expand Down Expand Up @@ -1834,7 +1834,7 @@ __metadata:
ts-node: ^10.9.1
tsconfig-paths-webpack-plugin: ^4.1.0
tus-js-client: 3.1.0
typescript: 4.7.4
typescript: 5.7.3
undici: ^6.19.7
url-loader: 4.1.1
uuid: 8.3.1
Expand Down Expand Up @@ -1922,7 +1922,7 @@ __metadata:
jest-localstorage-mock: 2.4.26
jest-sonar-reporter: 2.0.0
jsonwebtoken: 9.0.2
keycloak-js: 20.0.1
keycloak-js: 26.2.0
leaflet: 1.5.1
leaflet.markercluster: 1.4.1
less: 4.2.0
Expand Down Expand Up @@ -1966,7 +1966,7 @@ __metadata:
ts-loader: 9.5.1
ts-node: 10.9.1
tus-js-client: 3.1.0
typescript: 4.7.4
typescript: 5.7.3
undici: 6.19.7
url-loader: 4.1.1
webpack: 5.95.0
Expand Down Expand Up @@ -4787,7 +4787,7 @@ __metadata:
languageName: node
linkType: hard

"base64-js@npm:^1.3.1, base64-js@npm:^1.5.1":
"base64-js@npm:^1.3.1":
version: 1.5.1
resolution: "base64-js@npm:1.5.1"
checksum: 669632eb3745404c2f822a18fc3a0122d2f9a7a13f7fb8b5823ee19d1d2ff9ee5b52c53367176ea4ad093c332fd5ab4bd0ebae5a8e27917a4105a4cfc86b1005
Expand Down Expand Up @@ -12209,13 +12209,6 @@ __metadata:
languageName: node
linkType: hard

"js-sha256@npm:^0.9.0":
version: 0.9.0
resolution: "js-sha256@npm:0.9.0"
checksum: ffad54b3373f81581e245866abfda50a62c483803a28176dd5c28fd2d313e0bdf830e77dac7ff8afd193c53031618920f3d98daf21cbbe80082753ab639c0365
languageName: node
linkType: hard

"js-tokens@npm:^3.0.0 || ^4.0.0, js-tokens@npm:^4.0.0":
version: 4.0.0
resolution: "js-tokens@npm:4.0.0"
Expand Down Expand Up @@ -12490,13 +12483,10 @@ __metadata:
languageName: node
linkType: hard

"keycloak-js@npm:20.0.1":
version: 20.0.1
resolution: "keycloak-js@npm:20.0.1"
dependencies:
base64-js: ^1.5.1
js-sha256: ^0.9.0
checksum: 55e33240eafff3ec695d79099dea6f2a4913e6dde223281229a9223695b079bc5e078940863f899436e7a3bcbb7d56773b73a2eba47113b45f4917cfac2cc22f
"keycloak-js@npm:26.2.0":
version: 26.2.0
resolution: "keycloak-js@npm:26.2.0"
checksum: d990c329c6c348e48fcc4a0b82c1f87c187084ec740cc6e5856e58c374d555232821d76dd4907aedb09a8b60442dd0b16f302d45cadefa05e14ec66569cc6ec8
languageName: node
linkType: hard

Expand Down Expand Up @@ -20187,23 +20177,23 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:4.7.4":
version: 4.7.4
resolution: "typescript@npm:4.7.4"
"typescript@npm:5.7.3":
version: 5.7.3
resolution: "typescript@npm:5.7.3"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 5750181b1cd7e6482c4195825547e70f944114fb47e58e4aa7553e62f11b3f3173766aef9c281783edfd881f7b8299cf35e3ca8caebe73d8464528c907a164df
checksum: 6c38b1e989918e576f0307e6ee013522ea480dfce5f3ca85c9b2d8adb1edeffd37f4f30cd68de0c38a44563d12ba922bdb7e36aa2dac9c51de5d561e6e9a2e9c
languageName: node
linkType: hard

"typescript@patch:typescript@4.7.4#~builtin<compat/typescript>":
version: 4.7.4
resolution: "typescript@patch:typescript@npm%3A4.7.4#~builtin<compat/typescript>::version=4.7.4&hash=701156"
"typescript@patch:typescript@5.7.3#~builtin<compat/typescript>":
version: 5.7.3
resolution: "typescript@patch:typescript@npm%3A5.7.3#~builtin<compat/typescript>::version=5.7.3&hash=701156"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 9096d8f6c16cb80ef3bf96fcbbd055bf1c4a43bd14f3b7be45a9fbe7ada46ec977f604d5feed3263b4f2aa7d4c7477ce5f9cd87de0d6feedec69a983f3a4f93e
checksum: 633cd749d6cd7bc842c6b6245847173bba99742a60776fae3c0fbcc0d1733cd51a733995e5f4dadd8afb0e64e57d3c7dbbeae953a072ee303940eca69e22f311
languageName: node
linkType: hard

Expand Down
Loading