From b729bccce4b8167306398774b6799a8bbcae8053 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 19 Feb 2024 16:16:02 +0000 Subject: [PATCH 1/4] Mock subtle crypto in OIDC test To unblock upgrade to oidc-client-ts Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- package.json | 2 +- test/utils/oidc/authorize-test.ts | 11 +++++++++++ yarn.lock | 10 ++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 7c9e85c55dc..79bcd0d4da0 100644 --- a/package.json +++ b/package.json @@ -170,7 +170,7 @@ "@types/katex": "^0.16.0", "@types/lodash": "^4.14.168", "@types/modernizr": "^3.5.3", - "@types/node": "^16", + "@types/node": "18", "@types/node-fetch": "^2.6.2", "@types/pako": "^2.0.0", "@types/qrcode": "^1.3.5", diff --git a/test/utils/oidc/authorize-test.ts b/test/utils/oidc/authorize-test.ts index 509429ee768..2b95dd15fb7 100644 --- a/test/utils/oidc/authorize-test.ts +++ b/test/utils/oidc/authorize-test.ts @@ -19,6 +19,8 @@ import { completeAuthorizationCodeGrant } from "matrix-js-sdk/src/oidc/authorize import * as randomStringUtils from "matrix-js-sdk/src/randomstring"; import { BearerTokenResponse } from "matrix-js-sdk/src/oidc/validate"; import { mocked } from "jest-mock"; +import { Crypto } from "@peculiar/webcrypto"; +import { getRandomValues } from "node:crypto"; import { completeOidcLogin, startOidcLogin } from "../../../src/utils/oidc/authorize"; import { makeDelegatedAuthConfig } from "../../test-utils/oidc"; @@ -32,6 +34,8 @@ jest.mock("matrix-js-sdk/src/oidc/authorize", () => ({ completeAuthorizationCodeGrant: jest.fn(), })); +const webCrypto = new Crypto(); + describe("OIDC authorization", () => { const issuer = "https://auth.com/"; const homeserverUrl = "https://matrix.org"; @@ -55,6 +59,13 @@ describe("OIDC authorization", () => { jest.spyOn(randomStringUtils, "randomString").mockRestore(); mockPlatformPeg(); + Object.defineProperty(window, "crypto", { + value: { + getRandomValues, + randomUUID: jest.fn().mockReturnValue("not-random-uuid"), + subtle: webCrypto.subtle, + }, + }); }); beforeAll(() => { diff --git a/yarn.lock b/yarn.lock index d8945e1f696..0fb564fee78 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2689,10 +2689,12 @@ dependencies: undici-types "~5.26.4" -"@types/node@^16": - version "16.18.79" - resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.79.tgz#153e25561b271cf87dc1b28d38f98cebd514d788" - integrity sha512-Qd7jdLR5zmnIyMhfDrfPqN5tUCvreVpP3Qrf2oSM+F7SNzlb/MwHISGUkdFHtevfkPJ3iAGyeQI/jsbh9EStgQ== +"@types/node@18": + version "18.19.17" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.17.tgz#a581a9fb4b2cfdbc61f008804f4436b2d5c40354" + integrity sha512-SzyGKgwPzuWp2SHhlpXKzCX0pIOfcI4V2eF37nNBJOhwlegQ83omtVQ1XxZpDE06V/d6AQvfQdPfnw0tRC//Ng== + dependencies: + undici-types "~5.26.4" "@types/normalize-package-data@^2.4.0": version "2.4.4" From cf8f192461871ef9e9293cc823d26dca41c048b2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 2 Feb 2024 16:47:53 +0000 Subject: [PATCH 2/4] Update dependency oidc-client-ts to v3 --- package.json | 8 ++++---- yarn.lock | 12 ++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 79bcd0d4da0..3c5775a0c45 100644 --- a/package.json +++ b/package.json @@ -110,7 +110,7 @@ "matrix-widget-api": "^1.5.0", "memoize-one": "^6.0.0", "minimist": "^1.2.5", - "oidc-client-ts": "^2.2.4", + "oidc-client-ts": "^3.0.0", "opus-recorder": "^8.0.3", "pako": "^2.0.3", "png-chunks-extract": "^1.0.0", @@ -200,7 +200,6 @@ "eslint-plugin-react-hooks": "^4.3.0", "eslint-plugin-unicorn": "^50.0.0", "express": "^4.18.2", - "fake-indexeddb": "^5.0.2", "fetch-mock-jest": "^1.5.1", "fs-extra": "^11.0.0", "jest": "^29.6.2", @@ -221,7 +220,8 @@ "stylelint-config-standard": "^36.0.0", "stylelint-scss": "^6.0.0", "ts-node": "^10.9.1", - "typescript": "5.3.3" + "typescript": "5.3.3", + "fake-indexeddb": "^5.0.2" }, "peerDependencies": { "postcss": "^8.4.19", @@ -232,4 +232,4 @@ "outputName": "jest-sonar-report.xml", "relativePaths": true } -} +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 0fb564fee78..d33e50a2e73 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6466,6 +6466,11 @@ jwt-decode@^3.1.2: resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-3.1.2.tgz#3fb319f3675a2df0c2895c8f5e9fa4b67b04ed59" integrity sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A== +jwt-decode@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-4.0.0.tgz#2270352425fd413785b2faf11f6e755c5151bd4b" + integrity sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA== + katex@^0.16.0: version "0.16.9" resolved "https://registry.yarnpkg.com/katex/-/katex-0.16.9.tgz#bc62d8f7abfea6e181250f85a56e4ef292dcb1fa" @@ -7111,6 +7116,13 @@ oidc-client-ts@^2.2.4: crypto-js "^4.2.0" jwt-decode "^3.1.2" +oidc-client-ts@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/oidc-client-ts/-/oidc-client-ts-3.0.0.tgz#910b27193b54730dbabd93709ca000f8b1e5bdf2" + integrity sha512-YUcel/+C4AmXXhM/geNWc1jBsBVYzd+xhvSl1NMkxKpzZXqhLKmtj1ttSdxtDYm3P2YelnAr4zS4c96+p02iFQ== + dependencies: + jwt-decode "^4.0.0" + on-finished@2.4.1: version "2.4.1" resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.4.1.tgz#58c8c44116e54845ad57f14ab10b03533184ac3f" From 90296edf2097e6de7912cb203b51cfc2601787e4 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 19 Feb 2024 16:22:10 +0000 Subject: [PATCH 3/4] delint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3c5775a0c45..dc4f9b527a3 100644 --- a/package.json +++ b/package.json @@ -200,6 +200,7 @@ "eslint-plugin-react-hooks": "^4.3.0", "eslint-plugin-unicorn": "^50.0.0", "express": "^4.18.2", + "fake-indexeddb": "^5.0.2", "fetch-mock-jest": "^1.5.1", "fs-extra": "^11.0.0", "jest": "^29.6.2", @@ -220,8 +221,7 @@ "stylelint-config-standard": "^36.0.0", "stylelint-scss": "^6.0.0", "ts-node": "^10.9.1", - "typescript": "5.3.3", - "fake-indexeddb": "^5.0.2" + "typescript": "5.3.3" }, "peerDependencies": { "postcss": "^8.4.19", @@ -232,4 +232,4 @@ "outputName": "jest-sonar-report.xml", "relativePaths": true } -} \ No newline at end of file +} From 94fad4b139331510312d1b9ace7f04725d184818 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Mon, 19 Feb 2024 16:36:15 +0000 Subject: [PATCH 4/4] Ensure oidc-client-ts 3.0.1 to drop crypto-js Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- package.json | 6 ++++-- yarn.lock | 28 +++++----------------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index dc4f9b527a3..f7aa02b9099 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,9 @@ }, "resolutions": { "@types/react-dom": "17.0.21", - "@types/react": "17.0.68" + "@types/react": "17.0.68", + "oidc-client-ts": "3.0.1", + "jwt-decode": "4.0.0" }, "dependencies": { "@babel/runtime": "^7.12.5", @@ -110,7 +112,7 @@ "matrix-widget-api": "^1.5.0", "memoize-one": "^6.0.0", "minimist": "^1.2.5", - "oidc-client-ts": "^3.0.0", + "oidc-client-ts": "^3.0.1", "opus-recorder": "^8.0.3", "pako": "^2.0.3", "png-chunks-extract": "^1.0.0", diff --git a/yarn.lock b/yarn.lock index d33e50a2e73..471e20dbd29 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3912,11 +3912,6 @@ crypt@0.0.2: resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b" integrity sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow== -crypto-js@^4.2.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.2.0.tgz#4d931639ecdfd12ff80e8186dba6af2c2e856631" - integrity sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q== - css-box-model@^1.2.0: version "1.2.1" resolved "https://registry.yarnpkg.com/css-box-model/-/css-box-model-1.2.1.tgz#59951d3b81fd6b2074a62d49444415b0d2b4d7c1" @@ -6461,12 +6456,7 @@ jszip@^3.7.0: readable-stream "~2.3.6" setimmediate "^1.0.5" -jwt-decode@^3.1.2: - version "3.1.2" - resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-3.1.2.tgz#3fb319f3675a2df0c2895c8f5e9fa4b67b04ed59" - integrity sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A== - -jwt-decode@^4.0.0: +jwt-decode@4.0.0, jwt-decode@^3.1.2, jwt-decode@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-4.0.0.tgz#2270352425fd413785b2faf11f6e755c5151bd4b" integrity sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA== @@ -7108,18 +7098,10 @@ object.values@^1.1.6, object.values@^1.1.7: define-properties "^1.2.0" es-abstract "^1.22.1" -oidc-client-ts@^2.2.4: - version "2.4.0" - resolved "https://registry.yarnpkg.com/oidc-client-ts/-/oidc-client-ts-2.4.0.tgz#764c8a33de542026e2798de9849ce8049047d7e5" - integrity sha512-WijhkTrlXK2VvgGoakWJiBdfIsVGz6CFzgjNNqZU1hPKV2kyeEaJgLs7RwuiSp2WhLfWBQuLvr2SxVlZnk3N1w== - dependencies: - crypto-js "^4.2.0" - jwt-decode "^3.1.2" - -oidc-client-ts@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/oidc-client-ts/-/oidc-client-ts-3.0.0.tgz#910b27193b54730dbabd93709ca000f8b1e5bdf2" - integrity sha512-YUcel/+C4AmXXhM/geNWc1jBsBVYzd+xhvSl1NMkxKpzZXqhLKmtj1ttSdxtDYm3P2YelnAr4zS4c96+p02iFQ== +oidc-client-ts@3.0.1, oidc-client-ts@^2.2.4, oidc-client-ts@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/oidc-client-ts/-/oidc-client-ts-3.0.1.tgz#be264fb87c89f74f73863646431c32cd06f5ceb7" + integrity sha512-xX8unZNtmtw3sOz4FPSqDhkLFnxCDsdo2qhFEH2opgWnF/iXMFoYdBQzkwCxAZVgt3FT3DnuBY3k80EZHT0RYg== dependencies: jwt-decode "^4.0.0"