Skip to content

Commit

Permalink
Merge pull request #2711 from flowforge/update-ws-close-codes
Browse files Browse the repository at this point in the history
Update websocket close codes to proper range
  • Loading branch information
Steve-Mcl committed Sep 8, 2023
2 parents f880743 + 408c171 commit 93f90df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions forge/ee/routes/deviceEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ module.exports = async function (app) {
if (tunnelManager.verifyToken(deviceId, token)) {
const tunnelSetupOK = tunnelManager.initTunnel(deviceId, token, connection)
if (!tunnelSetupOK) {
connection.socket.close(1008, 'Tunnel setup failed')
connection.socket.close(4000, 'Tunnel setup failed')
}
} else {
connection.socket.close(1008, 'Invalid token')
connection.socket.close(4001, 'Invalid token')
}
} else {
connection.socket.close(1008, 'No tunnel')
connection.socket.close(4004, 'No tunnel')
}
})

Expand Down Expand Up @@ -236,7 +236,7 @@ module.exports = async function (app) {
return // handled
}
// not handled
connection.socket.close(1008, 'No tunnel established')
connection.socket.close(4000, 'No tunnel established')
}
})

Expand Down
6 changes: 3 additions & 3 deletions test/unit/forge/ee/routes/deviceEditor/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Device Editor API', function () {
const TestObjects = { tokens: {} }

before(async function () {
app = await setup({ billing: null })
app = await setup({ })
await login('alice', 'aaPassword')

app.device = await app.factory.createDevice({
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('Device Editor API', function () {
await sleep(200)

ws.readyState.should.equal(WebSocket.CLOSED)
closeCode.should.equal(1008)
closeCode.should.equal(4004)
closeReason.should.equal('No tunnel')
})
it('device websocket cannot connect with incorrect token', async function () {
Expand All @@ -186,7 +186,7 @@ describe('Device Editor API', function () {
await sleep(200)

ws.readyState.should.equal(WebSocket.CLOSED)
closeCode.should.equal(1008)
closeCode.should.equal(4001)
closeReason.should.equal('Invalid token')
})
it('Proxy HTTP GET - fails if device ws not connected', async function () {
Expand Down

0 comments on commit 93f90df

Please sign in to comment.