Files
deepseek-harness/packages/host/authentication-desktop/tests/plugin.host.spec.ts
T
imccyu 71753fdf91 refactor(connection): add connection auth provider for remote connection (#8266)
* refactor(connection): extract peer authentication providers

* test(connection): cover provider lifecycle and satisfy package gates

* fix(packaging): publish authentication provider locale resources

* test(auth): use runtime login output and cover gateway admission

* fix(auth): preserve Worker requests and migrate Desktop fixtures

* refactor(auth): centralize route admission with required policy

* fix(release): align authentication providers with rc.2

* refactor(connection): keep peer lookup and source policy private

* test(gateway): cover centralized upgrade rejections

* fix(ci): authenticate homepage compression probe

* refactor(auth): let Token own API socket lifecycle

* fix(auth): prevent caching admission refusals and clarify ownership

* refactor(web): collect provider entry URLs after readiness

* refactor(webserver): name the shared entry URL event

* refactor(connection): provide authentication as a nested service

* fix(web-app): restore startup publication defaults

* fix(auth): scope web events and preserve callback flows

* docs(auth): record the implemented provider architecture

* fix(auth): require owner access for administrative routes
2026-11-12 23:14:32 +08:00

29 lines
1.7 KiB
TypeScript

/** Desktop authentication is owned by its mounted plugin fiber. */
import { Context } from '@deepseek-ai/cordis'
import * as Connection from '@deepseek-ai/dsh-client-connection'
import { expect, it, onTestFinished } from 'vitest'
import * as DesktopAuthentication from '../src/index.ts'
it('owns the provider and shared Peer while retaining only an in-memory credential reader in config', async () => {
const ctx = new Context()
onTestFinished(() => ctx.fiber.dispose())
await ctx.plugin(Connection).await()
const secret = 'A'.repeat(43)
const config = { readSecret: () => secret }
expect(JSON.stringify(config)).toBe('{}')
const plugin = ctx.plugin(DesktopAuthentication, config)
await plugin.await()
const request = { headers: { cookie: `dsh-desktop-session=${secret}` } }
const first = ctx.connection.authentication.authenticate(request)
if ('rejection' in first) throw new Error('Desktop provider did not activate')
expect(first.peer).not.toBe(ctx.connection.browserPeer)
expect(ctx.connection.authentication.authenticate(request)).toEqual({ peer: first.peer })
expect(ctx.connection.authentication.authenticate({ headers: new Headers(request.headers) })).toEqual({ peer: first.peer })
expect(ctx.connection.authentication.authenticate({ headers: new Headers() })).toEqual({ rejection: 401 })
expect(ctx.connection.authentication.authenticate({ headers: new Headers({ cookie: 'dsh-desktop-session=wrong' }) })).toEqual({ rejection: 401 })
expect(ctx.connection.authentication.authenticate({ headers: { cookie: 'dsh-desktop-session=wrong' } })).toEqual({ rejection: 401 })
await plugin.dispose()
expect(first.peer.signal.aborted).toBe(true)
expect(ctx.connection.authentication.authenticate(request)).toEqual({ rejection: 401 })
})