Skip to content

Commit 960970e

Browse files
committed
Fake duress mode settings while in duress mode
1 parent d85fdca commit 960970e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/core/account/account-api.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
108108
}
109109
}
110110

111+
// This is used to fake duress mode settings while in duress mode:
112+
let fakeDuressModeSetup = false
113+
111114
const out: EdgeAccount = {
112115
on: onMethod,
113116
watch: watchMethod,
@@ -188,6 +191,9 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
188191

189192
get canDuressLogin(): boolean {
190193
const { activeAppId } = accountState()
194+
if (ai.props.state.clientInfo.duressEnabled) {
195+
return fakeDuressModeSetup
196+
}
191197
const duressAppId = activeAppId.endsWith('.duress')
192198
? activeAppId
193199
: activeAppId + '.duress'
@@ -257,6 +263,11 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
257263
: activeAppId + '.duress'
258264
// Ensure the duress account exists:
259265
if (forDuressAccount) {
266+
if (ai.props.state.clientInfo.duressEnabled) {
267+
fakeDuressModeSetup = opts.enableLogin ?? opts.pin != null
268+
ai.props.dispatch({ type: 'UPDATE_NEXT' })
269+
return ''
270+
}
260271
await ensureAccountExists(
261272
ai,
262273
accountState().stashTree,

test/core/login/login.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,27 @@ describe('duress', function () {
752752
expect(topicAccount.appId).equals('.duress')
753753
})
754754

755+
it('fake duress mode settings while in duress mode', async function () {
756+
const world = await makeFakeEdgeWorld([fakeUser], quiet)
757+
const context = await world.makeEdgeContext(contextOptions)
758+
let account = await context.loginWithPIN(fakeUser.username, fakeUser.pin)
759+
await account.changePin({ pin: '0000', forDuressAccount: true })
760+
await account.logout()
761+
762+
let duressAccount = await context.loginWithPIN(fakeUser.username, '0000')
763+
expect(duressAccount.canDuressLogin).equals(false)
764+
await duressAccount.changePin({ forDuressAccount: true, enableLogin: true })
765+
expect(duressAccount.canDuressLogin).equals(true)
766+
await duressAccount.logout()
767+
768+
duressAccount = await context.loginWithPIN(fakeUser.username, '0000')
769+
expect(duressAccount.canDuressLogin).equals(false)
770+
771+
// Doesn't impact main account:
772+
account = await context.loginWithPIN(fakeUser.username, fakeUser.pin)
773+
expect(account.canDuressLogin).equals(true)
774+
})
775+
755776
it('Avoid creating duress account when using loginWithPassword', async function () {
756777
const world = await makeFakeEdgeWorld([fakeUser], quiet)
757778
const context = await world.makeEdgeContext(contextOptions)

0 commit comments

Comments
 (0)