From 0c281db4113f6971a4265ef9f9732aacac39d80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 16 Dec 2021 15:57:37 +0100 Subject: [PATCH] More eslint fixes (+ ignoring no-unsafe-argument rule for now) --- front/.eslintrc.js | 3 ++- front/src/Connexion/ConnectionManager.ts | 10 ++++++- front/src/Stores/MediaStore.ts | 4 +-- front/src/Stores/ScreenSharingStore.ts | 2 +- front/src/Touch/TouchScreenManager.ts | 2 +- messages/JsonMessages/AdminApiData.ts | 23 ++++++++++++++++ messages/JsonMessages/RegisterData.ts | 24 +++++++++++++++++ .../src/Controller/AuthenticateController.ts | 3 ++- pusher/src/Services/AdminApi.ts | 26 +++++++++---------- 9 files changed, 76 insertions(+), 21 deletions(-) create mode 100644 messages/JsonMessages/AdminApiData.ts create mode 100644 messages/JsonMessages/RegisterData.ts diff --git a/front/.eslintrc.js b/front/.eslintrc.js index 33466012..117cb7e6 100644 --- a/front/.eslintrc.js +++ b/front/.eslintrc.js @@ -41,7 +41,8 @@ module.exports = { "@typescript-eslint/no-unsafe-assignment": "off", "@typescript-eslint/no-unsafe-return": "off", "@typescript-eslint/no-unsafe-member-access": "off", - "@typescript-eslint/restrict-template-expressions": "off" + "@typescript-eslint/restrict-template-expressions": "off", + "@typescript-eslint/no-unsafe-argument": "off", }, "settings": { "svelte3/typescript": true, diff --git a/front/src/Connexion/ConnectionManager.ts b/front/src/Connexion/ConnectionManager.ts index 6c40631c..6f1e1f50 100644 --- a/front/src/Connexion/ConnectionManager.ts +++ b/front/src/Connexion/ConnectionManager.ts @@ -12,6 +12,8 @@ import { userIsConnected } from "../Stores/MenuStore"; import { analyticsClient } from "../Administration/AnalyticsClient"; import { axiosWithRetry } from "./AxiosUtils"; import axios from "axios"; +import { isRegisterData } from "../Messages/JsonMessages/RegisterData"; +import { isAdminApiData } from "../Messages/JsonMessages/AdminApiData"; class ConnectionManager { private localUser!: LocalUser; @@ -126,6 +128,10 @@ class ConnectionManager { const data = await Axios.post(`${PUSHER_URL}/register`, { organizationMemberToken }).then( (res) => res.data ); + if (!isRegisterData(data)) { + console.error("Invalid data received from /register route. Data: ", data); + throw new Error("Invalid data received from /register route."); + } this.localUser = new LocalUser(data.userUuid, data.textures, data.email); this.authToken = data.authToken; localUserStore.saveUser(this.localUser); @@ -326,7 +332,9 @@ class ConnectionManager { } const { authToken, userUuid, textures, email } = await Axios.get(`${PUSHER_URL}/login-callback`, { params: { code, nonce, token, playUri: this.currentRoom?.key }, - }).then((res) => res.data); + }).then((res) => { + return res.data; + }); localUserStore.setAuthToken(authToken); this.localUser = new LocalUser(userUuid, textures, email); localUserStore.saveUser(this.localUser); diff --git a/front/src/Stores/MediaStore.ts b/front/src/Stores/MediaStore.ts index 8a8e39e2..44c78ad2 100644 --- a/front/src/Stores/MediaStore.ts +++ b/front/src/Stores/MediaStore.ts @@ -426,7 +426,7 @@ export const localStreamStore = derived, LocalS // TODO: does it make sense to pop this error when retrying? set({ type: "error", - error: e, + error: e instanceof Error ? e : new Error("An unknown error happened"), }); // Let's try without video constraints if (constraints.video !== false) { @@ -444,7 +444,7 @@ export const localStreamStore = derived, LocalS console.info("Error. Unable to get microphone and/or camera access.", constraints, e); set({ type: "error", - error: e, + error: e instanceof Error ? e : new Error("An unknown error happened"), }); } } diff --git a/front/src/Stores/ScreenSharingStore.ts b/front/src/Stores/ScreenSharingStore.ts index e4ee6410..d68dbf8b 100644 --- a/front/src/Stores/ScreenSharingStore.ts +++ b/front/src/Stores/ScreenSharingStore.ts @@ -153,7 +153,7 @@ export const screenSharingLocalStreamStore = derived 0 || navigator.msMaxTouchPoints > 0; + return "ontouchstart" in window || navigator.maxTouchPoints > 0; } } diff --git a/messages/JsonMessages/AdminApiData.ts b/messages/JsonMessages/AdminApiData.ts new file mode 100644 index 00000000..f21cc17c --- /dev/null +++ b/messages/JsonMessages/AdminApiData.ts @@ -0,0 +1,23 @@ +import * as tg from "generic-type-guard"; +import { isCharacterTexture} from "./CharacterTexture"; + +/* + * WARNING! The original file is in /messages/JsonMessages. + * All other files are automatically copied from this file on container startup / build + */ + +export const isAdminApiData = new tg.IsInterface() + .withProperties({ + roomUrl: tg.isString, + email: tg.isNullable(tg.isString), + mapUrlStart: tg.isString, + tags: tg.isArray(tg.isString), + policy_type: tg.isNumber, + userUuid: tg.isString, + textures: tg.isArray(isCharacterTexture), + }) + .withOptionalProperties({ + messages: tg.isArray(tg.isUnknown), + }) + .get(); +export type AdminApiData = tg.GuardedType; diff --git a/messages/JsonMessages/RegisterData.ts b/messages/JsonMessages/RegisterData.ts new file mode 100644 index 00000000..c585731e --- /dev/null +++ b/messages/JsonMessages/RegisterData.ts @@ -0,0 +1,24 @@ +import * as tg from "generic-type-guard"; +import { isCharacterTexture} from "./CharacterTexture"; + +/* + * WARNING! The original file is in /messages/JsonMessages. + * All other files are automatically copied from this file on container startup / build + */ + +export const isRegisterData = new tg.IsInterface() + .withProperties({ + roomUrl: tg.isString, + email: tg.isNullable(tg.isString), + organizationMemberToken: tg.isNullable(tg.isString), + mapUrlStart: tg.isString, + userUuid: tg.isString, + textures: tg.isArray(isCharacterTexture), + authToken: tg.isString, + + }) + .withOptionalProperties({ + messages: tg.isArray(tg.isUnknown), + }) + .get(); +export type RegisterData = tg.GuardedType; diff --git a/pusher/src/Controller/AuthenticateController.ts b/pusher/src/Controller/AuthenticateController.ts index e2089c89..3e725da5 100644 --- a/pusher/src/Controller/AuthenticateController.ts +++ b/pusher/src/Controller/AuthenticateController.ts @@ -6,6 +6,7 @@ import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager"; import { parse } from "query-string"; import { openIDClient } from "../Services/OpenIDClient"; import { DISABLE_ANONYMOUS, FRONT_URL } from "../Enum/EnvironmentVariable"; +import { RegisterData } from "../../../messages/JsonMessages/RegisterData"; export interface TokenInterface { userUuid: string; @@ -191,7 +192,7 @@ export class AuthenticateController extends BaseController { mapUrlStart, organizationMemberToken, textures, - }) + } as RegisterData) ); } catch (e) { console.error("register => ERROR", e); diff --git a/pusher/src/Services/AdminApi.ts b/pusher/src/Services/AdminApi.ts index 87c0d920..4410c29e 100644 --- a/pusher/src/Services/AdminApi.ts +++ b/pusher/src/Services/AdminApi.ts @@ -1,20 +1,10 @@ import { ADMIN_API_TOKEN, ADMIN_API_URL, ADMIN_URL, OPID_PROFILE_SCREEN_PROVIDER } from "../Enum/EnvironmentVariable"; import Axios from "axios"; import { GameRoomPolicyTypes } from "_Model/PusherRoom"; -import { CharacterTexture} from "../Messages/JsonMessages/CharacterTexture"; -import { MapDetailsData} from "../Messages/JsonMessages/MapDetailsData"; -import { RoomRedirect} from "../Messages/JsonMessages/RoomRedirect"; - -export interface AdminApiData { - roomUrl: string; - email: string | null; - mapUrlStart: string; - tags: string[]; - policy_type: number; - userUuid: string; - messages?: unknown[]; - textures: CharacterTexture[]; -} +import { CharacterTexture } from "../Messages/JsonMessages/CharacterTexture"; +import { MapDetailsData } from "../Messages/JsonMessages/MapDetailsData"; +import { RoomRedirect } from "../Messages/JsonMessages/RoomRedirect"; +import { AdminApiData, isAdminApiData } from "../Messages/JsonMessages/AdminApiData"; export interface AdminBannedData { is_banned: boolean; @@ -77,6 +67,10 @@ class AdminApi { const res = await Axios.get(ADMIN_API_URL + "/api/login-url/" + organizationMemberToken, { headers: { Authorization: `${ADMIN_API_TOKEN}` }, }); + if (!isAdminApiData(res.data)) { + console.error("Message received from /api/login-url is not in the expected format. Message: ", res.data); + throw new Error("Message received from /api/login-url is not in the expected format."); + } return res.data; } @@ -88,6 +82,10 @@ class AdminApi { const res = await Axios.get(ADMIN_API_URL + "/api/check-user/" + organizationMemberToken, { headers: { Authorization: `${ADMIN_API_TOKEN}` }, }); + if (!isAdminApiData(res.data)) { + console.error("Message received from /api/check-user is not in the expected format. Message: ", res.data); + throw new Error("Message received from /api/check-user is not in the expected format."); + } return res.data; }