Skip to content

Commit f65f301

Browse files
icecrasher321claude
andcommitted
fix(desktop): pin the platform in the OS-auth tests
promptForSecret gates Touch ID on process.platform === 'darwin'. The suite mocked electron's systemPreferences but inherited the runner's real platform, so the eight biometric expectations passed on a Mac and failed on Linux CI, where every call fell through to the confirmation dialog instead. Pins the platform per-test and restores it after, and adds a case for the gate itself — the branch whose absence from the suite is what let this through. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b34312c commit f65f301

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

apps/desktop/src/main/browser-credentials/os-auth.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, expect, it, vi } from 'vitest'
1+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
22

33
const promptTouchID = vi.fn(async () => undefined)
44
const canPromptTouchID = vi.fn(() => true)
@@ -30,6 +30,18 @@ const { authorizeForSecret, revokeSecretAuthorization } = await import(
3030

3131
const GRACE_MS = 30_000
3232

33+
const realPlatform = process.platform
34+
35+
/**
36+
* Touch ID is reachable only on darwin, so the suite pins the platform rather
37+
* than inheriting the runner's. Without this the biometric expectations below
38+
* pass on a Mac and fail on Linux CI, where the gate sends every call to the
39+
* fallback dialog instead.
40+
*/
41+
function setPlatform(platform: NodeJS.Platform): void {
42+
Object.defineProperty(process, 'platform', { value: platform, configurable: true })
43+
}
44+
3345
function request(credentialId: string) {
3446
return { credentialId, reason: 'show a saved password', action: 'Show password' }
3547
}
@@ -39,10 +51,15 @@ describe('authorizeForSecret', () => {
3951
vi.clearAllMocks()
4052
vi.useRealTimers()
4153
revokeSecretAuthorization()
54+
setPlatform('darwin')
4255
canPromptTouchID.mockReturnValue(true)
4356
promptTouchID.mockResolvedValue(undefined)
4457
})
4558

59+
afterEach(() => {
60+
setPlatform(realPlatform)
61+
})
62+
4663
it('asks the OS the first time a credential is used', async () => {
4764
await expect(authorizeForSecret(request('c1'))).resolves.toBe(true)
4865
expect(promptTouchID).toHaveBeenCalledTimes(1)
@@ -134,4 +151,15 @@ describe('authorizeForSecret', () => {
134151

135152
await expect(authorizeForSecret(request('c1'))).resolves.toBe(false)
136153
})
154+
155+
it('never reaches for Touch ID off darwin', async () => {
156+
// Electron exposes canPromptTouchID on every platform; only the darwin
157+
// guard keeps a non-Mac build out of the biometric path.
158+
setPlatform('linux')
159+
160+
await expect(authorizeForSecret(request('c1'))).resolves.toBe(true)
161+
162+
expect(promptTouchID).not.toHaveBeenCalled()
163+
expect(showMessageBox).toHaveBeenCalledTimes(1)
164+
})
137165
})

0 commit comments

Comments
 (0)