-
-
Notifications
You must be signed in to change notification settings - Fork 165
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Description
If a provider attempts to authenticate with a bad token (and fails), a subsequent attempt to authenticate with a good token for the same document does not succeed. The following test demonstrates the issue:
Steps to reproduce the bug
- Add test file
tests/provider/onAuthenticationFailedRetry.ts
:
import test from 'ava'
import { newHocuspocus, newHocuspocusProvider, newHocuspocusProviderWebsocket, sleep } from '../utils/index.ts'
test('onAuthenticate bad token then good token on same doc', async t => {
const docName = 'superSecretDoc'
const requiredToken = 'SUPER-SECRET-TOKEN'
const server = await newHocuspocus({
async onAuthenticate({ token, documentName }) {
if (documentName !== docName) {
throw new Error()
}
if (token !== requiredToken) {
throw new Error()
}
},
})
const socket = newHocuspocusProviderWebsocket(server)
const providerFail = newHocuspocusProvider(server, {
websocketProvider: socket,
token: 'wrongToken',
name: docName,
onAuthenticated() {
t.fail()
},
})
await sleep(100)
const providerOK = newHocuspocusProvider(server, {
websocketProvider: socket,
token: requiredToken,
name: docName,
onAuthenticationFailed() {
t.fail()
},
})
sleep(1000)
t.is(providerFail.isAuthenticated, false)
t.is(providerOK.isAuthenticated, true)
})
- Run
npx ava tests/provider/onAuthenticationFailedRetry.ts
Expected behavior
t.is(providerOK.isAuthenticated, true)
should pass
Actual behavior
t.is(providerOK.isAuthenticated, true)
fails
Environment?
- Hocuspocus version: 3.1.1
- Node.js version: 23.6.0
- OS: macOS 15.4.1
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working