Skip to content

Commit 26ec25f

Browse files
committed
RI-6508: add custom logic for handling keytar encryption issue
1 parent 94fc867 commit 26ec25f

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

src/webviews/src/utils/comparisons/compareConsents.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import { has } from 'lodash'
22
import { isVersionHigher } from 'uiSrc/utils/comparisons/compareVersions'
33

4+
// There was an issue that caused users to have encryption setting populated as false by default
5+
// This is a custom check to address that issue for existing users. The commit should be reverted after some time.
6+
const shouldTriggerKeytarEncryptionSpec = (spec: any, applied: any): boolean => true
7+
// local settings are from v1.0.6
8+
&& applied?.version === '1.0.6'
9+
// has locally stored false value
10+
&& applied.encryption === false
11+
// keytar is enabled
12+
&& spec?.encryption?.disabled === false
13+
// target current version of config
14+
&& spec.encryption.since === '1.0.2'
15+
416
// returns true if has different consents
517
export const isDifferentConsentsExists = (specs: any, applied: any) =>
618
!!compareConsents(specs, applied).length
@@ -19,6 +31,7 @@ export const compareConsents = (
1931
(isReturnAllNonRequired && !specs[consent]?.required)
2032
|| applied === null
2133
|| !has(applied, consent)
34+
|| (consent === 'encryption' && shouldTriggerKeytarEncryptionSpec(specs, applied))
2235
|| isVersionHigher(specs[consent]?.since, applied.version),
2336
)
2437
.map((consent) => ({ ...specs[consent], agreementName: consent }))

src/webviews/src/utils/comparisons/tests/compareConsents.spec.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,62 @@ describe('isDifferentConsentsExists', () => {
6060
expect(isDifferentConsentsExists(spec.agreements, agreements3)).toBeTruthy()
6161
})
6262
})
63+
64+
describe('compareConsents: custom keytar encryption conditions', () => {
65+
const agreementsSpec = {
66+
eula: spec.agreements.eula,
67+
encryption: {
68+
defaultValue: true,
69+
displayInSetting: false,
70+
required: false,
71+
editable: true,
72+
disabled: false,
73+
category: 'privacy',
74+
since: '1.0.2',
75+
title: 'Encryption',
76+
label: 'Encrypt sensitive information',
77+
description:
78+
'Select to encrypt sensitive information using system keychain. Otherwise, this information is stored locally in plain text, which may incur security risk.',
79+
},
80+
}
81+
82+
const agreements1 = {
83+
eula: true,
84+
encryption: false,
85+
version: '1.0.6',
86+
}
87+
88+
const agreements2 = {
89+
eula: true,
90+
encryption: false,
91+
version: '1.0.7',
92+
}
93+
94+
const agreements3 = {
95+
eula: true,
96+
encryption: true,
97+
version: '1.0.6',
98+
}
99+
100+
const agreements4 = {
101+
eula: true,
102+
encryption: true,
103+
version: '1.0.7',
104+
}
105+
106+
it('should prompt users with encryption set to false and v1.0.6 to set encryption again', () => {
107+
expect(compareConsents(agreementsSpec, agreements1)).toHaveLength(1)
108+
})
109+
110+
it('should NOT prompt users with encryption set to false and v1.0.7 to set encryption again', () => {
111+
expect(compareConsents(agreementsSpec, agreements2)).toHaveLength(0)
112+
})
113+
114+
it('should NOT prompt users with encryption set to true and v1.0.6 to set encryption again', () => {
115+
expect(compareConsents(agreementsSpec, agreements3)).toHaveLength(0)
116+
})
117+
118+
it('should NOT prompt users with encryption set to true and v1.0.7 to set encryption again', () => {
119+
expect(compareConsents(agreementsSpec, agreements4)).toHaveLength(0)
120+
})
121+
})

0 commit comments

Comments
 (0)