Skip to content

The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.

904 B
Raw Blame
import { signAccess } from '../proxy/gate'
import { verifyExpiring } from './signed-token'

describe('App access cookie expiry', () => {
  afterEach(() => jest.useRealTimers())
  test('accepts the last valid instant and rejects missing, malformed, expired and differently signed cookies', () => {
    jest.useFakeTimers({ now: new Date('2026-03-01T12:00:00Z') })
    const cookie = signAccess('first', 'main', 2)
    const verify = (value?: string) => verifyExpiring('first', 'app-access', value, '.')
    const [subject, , mac] = cookie.split('.')
    expect(verify()).toBeNull()
    expect(verify(subject + '.invalid.' + mac)).toBeNull()
    expect(verify(cookie + '.extra')).toBeNull()
    expect(verify(signAccess('other', 'main', 2))).toBeNull()
    jest.advanceTimersByTime(2000)
    expect(verify(cookie)).toBe('main')
    jest.advanceTimersByTime(1)
    expect(verify(cookie)).toBeNull()
  })
})