Skip to content

Commit

Permalink
fix: add missing undefined/null check to e2ei typeguards (#16149)
Browse files Browse the repository at this point in the history
* fix: add missing undefined check to e2ei typeguards

* chore: rename for clarity

* chore: rename for clarity

* fix: logic

* chore: refactor guards
  • Loading branch information
aweiss-dev committed Nov 2, 2023
1 parent 2780589 commit 7e22f4d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Expand Up @@ -22,13 +22,13 @@ import {FeatureStatus, FEATURE_KEY, FeatureList} from '@wireapp/api-client/lib/t
import {E2EIHandler} from 'src/script/E2EIdentity';
import {Logger} from 'Util/Logger';

import {isFeatureMLSE2EI, isFeatureMLS} from '../../guards';
import {hasE2EIVerificationExpiration, hasMLSDefaultProtocol} from '../../guards';

export const handleE2EIdentityFeatureChange = (logger: Logger, config: FeatureList) => {
const e2eiConfig = config[FEATURE_KEY.MLSE2EID];
const mlsConfig = config[FEATURE_KEY.MLS];
// Check if MLS or MLS E2EIdentity feature is existent
if (!isFeatureMLSE2EI(e2eiConfig) && !isFeatureMLS(mlsConfig)) {
if (!hasE2EIVerificationExpiration(e2eiConfig) || !hasMLSDefaultProtocol(mlsConfig)) {
return;
}

Expand Down
12 changes: 8 additions & 4 deletions src/script/page/components/FeatureConfigChange/guards.ts
Expand Up @@ -19,8 +19,12 @@

import {FeatureMLS, FeatureMLSE2EId} from '@wireapp/api-client/lib/team';

export const isFeatureMLSE2EI = (feature: any): feature is FeatureMLSE2EId =>
'config' in feature && 'verificationExpiration' in feature.config;
const isObject = (value: unknown): value is {} => typeof value === 'object' && value !== null;
const isFeatureWithConfig = (feature: unknown): feature is {config: {}} =>
isObject(feature) && 'config' in feature && isObject(feature.config);

export const isFeatureMLS = (feature: any): feature is FeatureMLS =>
'config' in feature && 'defaultProtocol' in feature.config;
export const hasE2EIVerificationExpiration = (feature: unknown): feature is FeatureMLSE2EId =>
isFeatureWithConfig(feature) && 'verificationExpiration' in feature.config;

export const hasMLSDefaultProtocol = (feature: unknown): feature is FeatureMLS =>
isFeatureWithConfig(feature) && 'defaultProtocol' in feature.config;

0 comments on commit 7e22f4d

Please sign in to comment.