From 6cf6c0e95547aa6169e92c80b797d67c07ce7c6a Mon Sep 17 00:00:00 2001 From: Lucas Bruno <69604366+lucasbrunozup@users.noreply.github.com> Date: Fri, 19 Feb 2021 10:33:57 -0300 Subject: [PATCH] Added safe JSON parse in manager (#348) * Added safe JSON parse in the locales of use in manager * [skip ci] Update versioning file Co-authored-by: wilian --- horusec-manager/.semver.yaml | 2 +- .../src/helpers/localStorage/currentLanguage.ts | 11 ++++++----- .../src/helpers/localStorage/currentUser.ts | 11 ++++++----- .../src/helpers/localStorage/horusecConfig.ts | 12 ++++++++---- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/horusec-manager/.semver.yaml b/horusec-manager/.semver.yaml index 633813b21..959b0409b 100644 --- a/horusec-manager/.semver.yaml +++ b/horusec-manager/.semver.yaml @@ -1,4 +1,4 @@ alpha: 0 beta: 0 rc: 0 -release: v1.7.2 +release: v1.7.3 diff --git a/horusec-manager/src/helpers/localStorage/currentLanguage.ts b/horusec-manager/src/helpers/localStorage/currentLanguage.ts index 6152cdc0e..aee5d7e44 100644 --- a/horusec-manager/src/helpers/localStorage/currentLanguage.ts +++ b/horusec-manager/src/helpers/localStorage/currentLanguage.ts @@ -18,11 +18,12 @@ import { localStorageKeys } from 'helpers/enums/localStorageKeys'; import { Language } from 'helpers/interfaces/Language'; const getCurrentLanguage = (): Language | null => { - const localData: Language = JSON.parse( - window.localStorage.getItem(localStorageKeys.LANGUAGE) - ); - - return localData; + try { + const localData = window.localStorage.getItem(localStorageKeys.LANGUAGE); + return localData ? JSON.parse(localData) : null; + } catch (e) { + return null; + } }; const setCurrentLanguage = (value: Language) => { diff --git a/horusec-manager/src/helpers/localStorage/currentUser.ts b/horusec-manager/src/helpers/localStorage/currentUser.ts index b1c571927..4d7802983 100644 --- a/horusec-manager/src/helpers/localStorage/currentUser.ts +++ b/horusec-manager/src/helpers/localStorage/currentUser.ts @@ -19,11 +19,12 @@ import { User } from 'helpers/interfaces/User'; import { getCurrentConfig } from './horusecConfig'; const getCurrentUser = (): User | null => { - const localData: User = JSON.parse( - window.localStorage.getItem(localStorageKeys.USER) - ); - - return localData; + try { + const localData = window.localStorage.getItem(localStorageKeys.USER); + return localData ? JSON.parse(localData) : null; + } catch (e) { + return null; + } }; const setCurrentUser = (value: User) => { diff --git a/horusec-manager/src/helpers/localStorage/horusecConfig.ts b/horusec-manager/src/helpers/localStorage/horusecConfig.ts index bc93fd44d..924679675 100644 --- a/horusec-manager/src/helpers/localStorage/horusecConfig.ts +++ b/horusec-manager/src/helpers/localStorage/horusecConfig.ts @@ -18,14 +18,18 @@ import { localStorageKeys } from 'helpers/enums/localStorageKeys'; import { HorusecConfig } from 'helpers/interfaces/HorusecConfig'; const initialValues: HorusecConfig = { - authType: null, + authType: 'horusec', applicationAdminEnable: false, - disabledBroker: false, + disabledBroker: true, }; const getCurrentConfig = (): HorusecConfig => { - const config = window.localStorage.getItem(localStorageKeys.CONFIG); - return config ? JSON.parse(config) : initialValues; + try { + const config = window.localStorage.getItem(localStorageKeys.CONFIG); + return config ? JSON.parse(config) : initialValues; + } catch (e) { + return initialValues; + } }; const setCurrenConfig = (value: HorusecConfig) => {