Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix: reuse auth binding validation during failed logout
Josué14fdd130e4d0
diff --git a/desktop-app/src/__tests__/appService.nativeLogoutRecovery.test.ts b/desktop-app/src/__tests__/appService.nativeLogoutRecovery.test.tsindex bca385fd3..695b24f96 100644--- a/desktop-app/src/__tests__/appService.nativeLogoutRecovery.test.ts+++ b/desktop-app/src/__tests__/appService.nativeLogoutRecovery.test.ts@@ -3,6 +3,7 @@ import {cleanupNativeCommitTestHarness,createNativeCommitTestHarness,} from '../../testSupport/appService.nativeCommitTestHarness.js'+import { testLoginResult } from '../../testSupport/authTestFixtures.js'afterEach(cleanupNativeCommitTestHarness)@@ -10,20 +11,19 @@ describe('AppService logout recovery ownership', () => {it('keeps the current session when token removal fails on the same runtime boundary', async () => {const { service } = await createNativeCommitTestHarness()service.authClient = {- googleLogin: vi.fn().mockResolvedValue({- token: 'synthetic-session-a',- me: {- id: 'user-a',- email: '[email protected]',- name: 'User A',- picture: null,- teamId: 'team-a',- teamName: 'Team A',- role: 'member',- },- }),+ googleLogin: vi.fn().mockResolvedValue(testLoginResult()),} as neverawait service.googleLogin('initial-login')+ const assertAuthEnvironmentBinding = vi.spyOn(+ service as unknown as {+ assertAuthEnvironmentBinding: (binding: {+ environmentKey: string+ profileId: string | null+ restBaseUrl: string+ }) => void+ },+ 'assertAuthEnvironmentBinding'+ )service.tokenStore.clearSessionToken = vi.fn().mockRejectedValue(new Error('keychain unavailable'))@@ -32,6 +32,7 @@ describe('AppService logout recovery ownership', () => {expect(service.getCachedUserId()).toBe('user-a')expect(service.sessionToken).toBe('synthetic-session-a')+ expect(assertAuthEnvironmentBinding).toHaveBeenCalledOnce()await expect(service.listGfsUploadSessions()).resolves.toEqual([])})})diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.tsindex 1c3feff6d..dbf11363f 100644--- a/desktop-app/src/appService.ts+++ b/desktop-app/src/appService.ts@@ -2489,13 +2489,18 @@ export class AppService {await this.tokenStore.clearSessionToken(envKey, { legacyEnvKeys })this.assertSessionGeneration(logoutGeneration)} catch (error) {+ let environmentBindingMatches = false+ try {+ this.assertAuthEnvironmentBinding(logoutEnvironment)+ environmentBindingMatches = true+ } catch {+ // A selected profile change means the failed clear no longer owns this boundary.+ }const capturedSessionStillOwnsBoundary =this.sessionGeneration === logoutGeneration &&this.sessionToken === logoutToken &&this.me === logoutMe &&- getActiveEnvKey() === logoutEnvironment.environmentKey &&- normalizeDesktopUploadBaseUrl(config.externalRestApiBaseUrl) ===- logoutEnvironment.restBaseUrl+ environmentBindingMatchesif (capturedSessionStillOwnsBoundary) {if (logoutToken && logoutMe) this.activateGfsAuthScope()}diff --git a/desktop-app/testSupport/authTestFixtures.ts b/desktop-app/testSupport/authTestFixtures.tsnew file mode 100644index 000000000..e520545cc--- /dev/null+++ b/desktop-app/testSupport/authTestFixtures.ts@@ -0,0 +1,28 @@+import type { LoginResult, SessionMe } from '../src/types.js'++export function testSessionMe(overrides: Partial<SessionMe> = {}): SessionMe {+ return {+ id: 'user-a',+ email: '[email protected]',+ name: 'User A',+ picture: null,+ teamId: 'team-a',+ teamName: 'Team A',+ role: 'member',+ ...overrides,+ }+}++export function testLoginResult(+ token = 'synthetic-session-a',+ me: SessionMe = testSessionMe()+): LoginResult {+ return { token, me }+}++export function testTeamSwitchResult(teamId: string, token = `session-${teamId}`) {+ return {+ token,+ team: { id: teamId, name: teamId, role: 'member' as const },+ }+}