|
1 | 1 | import test from 'ava' |
2 | 2 | import type { onAuthenticatePayload, onTokenSyncPayload } from '@hocuspocus/server' |
3 | | -import { WebSocketStatus } from '@hocuspocus/provider' |
| 3 | +import { Unauthorized } from '@hocuspocus/common' |
4 | 4 | import { |
5 | 5 | newHocuspocus, newHocuspocusProvider, newHocuspocusProviderWebsocket, sleep, |
6 | 6 | } from '../utils/index.ts' |
7 | | -import { retryableAssertion } from '../utils/retryableAssertion.ts' |
8 | 7 |
|
9 | 8 | // ============================================================================ |
10 | 9 | // PROVIDER SEND TOKEN TESTS |
@@ -333,20 +332,22 @@ test('server requestToken: onTokenSync works with readonly connections when serv |
333 | 332 | }) |
334 | 333 | }) |
335 | 334 |
|
336 | | -test('server requestToken: failure of onTokenSync should trigger onAuthenticationFailed hook on provider side', async t => { |
| 335 | +test('server requestToken: failure of onTokenSync should close the connection', async t => { |
337 | 336 | await new Promise(async resolve => { |
338 | 337 | const server = await newHocuspocus({ |
339 | 338 | async onAuthenticate() { |
340 | 339 | return true // Allow initial auth |
341 | 340 | }, |
342 | 341 | async onTokenSync() { |
343 | | - throw new Error('Token sync failed') |
| 342 | + throw new Error() |
344 | 343 | }, |
345 | 344 | }) |
346 | 345 |
|
347 | 346 | const provider = newHocuspocusProvider(server, { |
348 | 347 | token: 'SUPER-SECRET-TOKEN', |
349 | | - onAuthenticationFailed() { |
| 348 | + onClose({ event }) { |
| 349 | + t.is(event.code, Unauthorized.code) |
| 350 | + t.is(event.reason, Unauthorized.reason) |
350 | 351 | t.pass() |
351 | 352 | resolve('done') |
352 | 353 | }, |
|
0 commit comments