| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import { describe, expect, it } from 'vitest'
- import { RealtimeLeaseStore } from '../../src/server/leases.js'
- describe('RealtimeLeaseStore', () => {
- it('binds a lease to channel, origin, account and one use', () => {
- let now = 1_000
- const store = new RealtimeLeaseStore(20_000, () => now)
- const lease = store.issue({
- channel: 'chat',
- credential: { name: 'ticket', value: 'upstream-secret' },
- origin: 'http://127.0.0.1:8800',
- accountKeys: ['account-a'],
- localUserID: 'local-user-a',
- })
- expect(() => store.consume(
- lease.id,
- 'groups',
- 'http://127.0.0.1:8800',
- 'account-a',
- )).toThrow(/invalid or expired/)
- const consumed = store.consume(
- lease.id,
- 'chat',
- 'http://127.0.0.1:8800',
- 'account-a',
- )
- expect(consumed.credential.value).toBe('upstream-secret')
- expect(consumed.localUserID).toBe('local-user-a')
- expect(() => store.consume(
- lease.id,
- 'chat',
- 'http://127.0.0.1:8800',
- 'account-a',
- )).toThrow(/invalid or expired/)
- const expiring = store.issue({
- channel: 'chat',
- credential: { name: 'ticket', value: 'another-secret' },
- origin: 'http://127.0.0.1:8800',
- accountKeys: ['account-a'],
- })
- now += 20_001
- expect(() => store.consume(
- expiring.id,
- 'chat',
- 'http://127.0.0.1:8800',
- 'account-a',
- )).toThrow(/invalid or expired/)
- })
- })
|