Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Conform more code to strictNullChecks and noImplicitAny #11156

Merged
merged 1 commit into from
Jun 28, 2023
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
12 changes: 10 additions & 2 deletions src/Lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,14 +686,22 @@ async function persistCredentials(credentials: IMatrixClientCreds): Promise<void
// if we couldn't save to indexedDB, fall back to localStorage. We
// store the access token unencrypted since localStorage only saves
// strings.
localStorage.setItem("mx_access_token", credentials.accessToken);
if (!!credentials.accessToken) {
localStorage.setItem("mx_access_token", credentials.accessToken);

Check failure

Code scanning / CodeQL

Clear text storage of sensitive information

This stores sensitive data returned by [a call to sendLoginRequest](1) as clear text.
} else {
localStorage.removeItem("mx_access_token");
}
}
localStorage.setItem("mx_has_pickle_key", String(true));
} else {
try {
await StorageManager.idbSave("account", "mx_access_token", credentials.accessToken);
} catch (e) {
localStorage.setItem("mx_access_token", credentials.accessToken);
if (!!credentials.accessToken) {
localStorage.setItem("mx_access_token", credentials.accessToken);

Check failure

Code scanning / CodeQL

Clear text storage of sensitive information

This stores sensitive data returned by [a call to sendLoginRequest](1) as clear text.
} else {
localStorage.removeItem("mx_access_token");
}
}
if (localStorage.getItem("mx_has_pickle_key") === "true") {
logger.error("Expected a pickle key, but none provided. Encryption may not work.");
Expand Down
22 changes: 14 additions & 8 deletions src/components/structures/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1597,14 +1597,15 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
};

private injectSticker(url: string, info: object, text: string, threadId: string | null): void {
if (!this.context.client) return;
const roomId = this.getRoomId();
if (!this.context.client || !roomId) return;
if (this.context.client.isGuest()) {
dis.dispatch({ action: "require_registration" });
return;
}

ContentMessages.sharedInstance()
.sendStickerContentToRoom(url, this.getRoomId(), threadId, info, text, this.context.client)
.sendStickerContentToRoom(url, roomId, threadId, info, text, this.context.client)
.then(undefined, (error) => {
if (error.name === "UnknownDeviceError") {
// Let the staus bar handle this
Expand Down Expand Up @@ -1636,7 +1637,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
private onSearchUpdate = (inProgress: boolean, searchResults: ISearchResults | null): void => {
this.setState({
search: {
...this.state.search,
...this.state.search!,
count: searchResults?.count,
inProgress,
},
Expand All @@ -1658,10 +1659,12 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
};

private onRejectButtonClicked = (): void => {
const roomId = this.getRoomId();
if (!roomId) return;
this.setState({
rejecting: true,
});
this.context.client?.leave(this.getRoomId()).then(
this.context.client?.leave(roomId).then(
() => {
dis.dispatch({ action: Action.ViewHomePage });
this.setState({
Expand Down Expand Up @@ -1896,14 +1899,17 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
});
}

private onFileDrop = (dataTransfer: DataTransfer): Promise<void> =>
ContentMessages.sharedInstance().sendContentListToRoom(
private onFileDrop = async (dataTransfer: DataTransfer): Promise<void> => {
const roomId = this.getRoomId();
if (!roomId || !this.context.client) return;
await ContentMessages.sharedInstance().sendContentListToRoom(
Array.from(dataTransfer.files),
this.getRoomId(),
null,
roomId,
undefined,
this.context.client,
TimelineRenderingType.Room,
);
};

private onMeasurement = (narrow: boolean): void => {
this.setState({ narrow });
Expand Down
1 change: 1 addition & 0 deletions src/components/structures/ScrollPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ export default class ScrollPanel extends React.Component<IProps> {
}

private topFromBottom(node: HTMLElement): number {
if (!this.itemlist.current) return -1;
// current capped height - distance from top = distance from bottom of container to top of tracked element
return this.itemlist.current.clientHeight - node.offsetTop;
}
Expand Down
2 changes: 1 addition & 1 deletion test/components/structures/SpaceHierarchy-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe("SpaceHierarchy", () => {
observe: () => null,
unobserve: () => null,
disconnect: () => null,
});
} as ResizeObserver);
window.IntersectionObserver = mockIntersectionObserver;
});

Expand Down
2 changes: 1 addition & 1 deletion test/components/structures/TimelinePanel-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const mkTimeline = (room: Room, events: MatrixEvent[]): [EventTimeline, EventTim
room: room as Room,
getLiveTimeline: () => timeline,
getTimelineForEvent: () => timeline,
getPendingEvents: () => [],
getPendingEvents: () => [] as MatrixEvent[],
} as unknown as EventTimelineSet;
const timeline = new EventTimeline(timelineSet);
events.forEach((event) => timeline.addEvent(event, { toStartOfTimeline: false }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function renderComponent(props: Partial<ComponentProps<typeof VerificationPanel>
const defaultProps = {
layout: "",
member: {} as User,
onClose: () => undefined,
onClose: () => {},
isRoomEncrypted: false,
inDialog: false,
phase: props.request.phase,
Expand Down
7 changes: 4 additions & 3 deletions test/components/views/spaces/SpacePanel-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
import React from "react";
import { render, screen, fireEvent, act } from "@testing-library/react";
import { mocked } from "jest-mock";
import { MatrixClient } from "matrix-js-sdk/src/matrix";
import { MatrixClient, Room } from "matrix-js-sdk/src/matrix";

import UnwrappedSpacePanel from "../../../../src/components/views/spaces/SpacePanel";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
Expand All @@ -28,6 +28,7 @@ import { mkStubRoom, wrapInSdkContext } from "../../../test-utils";
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
import SpaceStore from "../../../../src/stores/spaces/SpaceStore";
import DMRoomMap from "../../../../src/utils/DMRoomMap";
import { SpaceNotificationState } from "../../../../src/stores/notifications/SpaceNotificationState";

// DND test utilities based on
// https://github.com/colinrobertbrooks/react-beautiful-dnd-test-utils/issues/18#issuecomment-1373388693
Expand Down Expand Up @@ -98,8 +99,8 @@ jest.mock("../../../../src/stores/spaces/SpaceStore", () => {
enabledMetaSpaces: MetaSpace[] = [];
spacePanelSpaces: string[] = [];
activeSpace: SpaceKey = "!space1";
getChildSpaces = () => [];
getNotificationState = () => null;
getChildSpaces = () => [] as Room[];
getNotificationState = () => null as SpaceNotificationState | null;
setActiveSpace = jest.fn();
moveRootSpace = jest.fn();
}
Expand Down
2 changes: 1 addition & 1 deletion test/utils/AutoDiscoveryUtils-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ describe("AutoDiscoveryUtils", () => {
registrationEndpoint: "https://test.com/registration",
tokenEndpoint: "https://test.com/token",
};
const discoveryResult = {
const discoveryResult: ClientConfig = {
...validIsConfig,
...validHsConfig,
[M_AUTHENTICATION.stable!]: {
Expand Down
5 changes: 3 additions & 2 deletions test/utils/oidc/registerClient-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import fetchMockJest from "fetch-mock-jest";
import { OidcError } from "matrix-js-sdk/src/oidc/error";

import { getOidcClientId } from "../../../src/utils/oidc/registerClient";
import { ValidatedDelegatedAuthConfig } from "../../../src/utils/ValidatedServerConfig";

describe("getOidcClientId()", () => {
const issuer = "https://auth.com/";
Expand Down Expand Up @@ -49,7 +50,7 @@ describe("getOidcClientId()", () => {
});

it("should throw when no static clientId is configured and no registration endpoint", async () => {
const authConfigWithoutRegistration = {
const authConfigWithoutRegistration: ValidatedDelegatedAuthConfig = {
...delegatedAuthConfig,
issuer: "https://issuerWithoutStaticClientId.org/",
registrationEndpoint: undefined,
Expand All @@ -62,7 +63,7 @@ describe("getOidcClientId()", () => {
});

it("should handle when staticOidcClients object is falsy", async () => {
const authConfigWithoutRegistration = {
const authConfigWithoutRegistration: ValidatedDelegatedAuthConfig = {
...delegatedAuthConfig,
registrationEndpoint: undefined,
};
Expand Down