Switch to secure random strings (#29013)
* Switch to secure random strings Because the js-sdk methods are changing and there's no reason for these not to use the secure versions. The dedicated upper/lower functions were *only* used in this one case, so this should do the exact same thing with the one exported function. Requires https://github.com/matrix-org/matrix-js-sdk/pull/4621 (merge both together) * Change remaining instances of randomString which I somehow entirely missed the first time. * Fix import order
This commit is contained in:
@@ -8,7 +8,7 @@ Please see LICENSE files in the repository root for full details.
|
||||
|
||||
import "@testing-library/jest-dom";
|
||||
import "blob-polyfill";
|
||||
import { randomString } from "matrix-js-sdk/src/randomstring";
|
||||
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
|
||||
import { mocked } from "jest-mock";
|
||||
|
||||
import { PredictableRandom } from "./test-utils/predictableRandom"; // https://github.com/jsdom/jsdom/issues/2555
|
||||
@@ -25,7 +25,8 @@ jest.mock("matrix-js-sdk/src/randomstring");
|
||||
beforeEach(() => {
|
||||
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
const mockRandom = new PredictableRandom();
|
||||
mocked(randomString).mockImplementation((len) => {
|
||||
// needless to say, the mock is not cryptographically secure
|
||||
mocked(secureRandomString).mockImplementation((len) => {
|
||||
let ret = "";
|
||||
for (let i = 0; i < len; ++i) {
|
||||
const v = mockRandom.get() * chars.length;
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
M_POLL_RESPONSE,
|
||||
M_TEXT,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { randomString } from "matrix-js-sdk/src/randomstring";
|
||||
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
|
||||
|
||||
import { flushPromises } from "./utilities";
|
||||
|
||||
@@ -67,7 +67,7 @@ export const makePollEndEvent = (
|
||||
id?: string,
|
||||
): MatrixEvent => {
|
||||
return new MatrixEvent({
|
||||
event_id: id || randomString(16),
|
||||
event_id: id || secureRandomString(16),
|
||||
room_id: roomId,
|
||||
origin_server_ts: ts,
|
||||
type: M_POLL_END.name,
|
||||
@@ -91,7 +91,7 @@ export const makePollResponseEvent = (
|
||||
ts = 0,
|
||||
): MatrixEvent =>
|
||||
new MatrixEvent({
|
||||
event_id: randomString(16),
|
||||
event_id: secureRandomString(16),
|
||||
room_id: roomId,
|
||||
origin_server_ts: ts,
|
||||
type: M_POLL_RESPONSE.name,
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
IThreepid,
|
||||
ThreepidMedium,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { randomString } from "matrix-js-sdk/src/randomstring";
|
||||
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
|
||||
import {
|
||||
act,
|
||||
fireEvent,
|
||||
@@ -287,7 +287,7 @@ describe("<Notifications />", () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
let i = 0;
|
||||
mocked(randomString).mockImplementation(() => {
|
||||
mocked(secureRandomString).mockImplementation(() => {
|
||||
return "testid_" + i++;
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Please see LICENSE files in the repository root for full details.
|
||||
|
||||
import React from "react";
|
||||
import { mocked } from "jest-mock";
|
||||
import { randomString } from "matrix-js-sdk/src/randomstring";
|
||||
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
|
||||
import { act, fireEvent, render, RenderResult } from "jest-matrix-react";
|
||||
import { EventType, MatrixClient, Room, GuestAccess, HistoryVisibility, JoinRule } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
@@ -92,7 +92,7 @@ describe("<SpaceSettingsVisibilityTab />", () => {
|
||||
|
||||
beforeEach(() => {
|
||||
let i = 0;
|
||||
mocked(randomString).mockImplementation(() => {
|
||||
mocked(secureRandomString).mockImplementation(() => {
|
||||
return "testid_" + i++;
|
||||
});
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ describe("OIDC authorization", () => {
|
||||
origin: baseUrl,
|
||||
};
|
||||
|
||||
jest.spyOn(randomStringUtils, "randomString").mockRestore();
|
||||
jest.spyOn(randomStringUtils, "secureRandomString").mockRestore();
|
||||
mockPlatformPeg();
|
||||
Object.defineProperty(window, "crypto", {
|
||||
value: {
|
||||
|
||||
Reference in New Issue
Block a user