mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-03 12:41:42 +00:00
[misc] add test cases for the validation of the callback argument
When the user provides a function as last argument for socket.emit, socket.io will flag this as an RPC and add a cb as the last argument to the client.on('event', ...) handler on the server side. Without a function as last argument for socket.emit, the callback argument on the server side is undefined, leading to invalid function calls (`undefined()`) and an unhandled exception. The user can also provide lots of other arguments, so the 2nd/3rd ... argument is of arbitrary type, again leading to invalid function calls -- e.g. `1()`.
This commit is contained in:
parent
1c9eaf574a
commit
acb7d7df5a
2 changed files with 77 additions and 0 deletions
|
@ -26,6 +26,7 @@ module.exports = Router =
|
||||||
logger.warn attrs, error.message, code: error.code
|
logger.warn attrs, error.message, code: error.code
|
||||||
return callback {message: error.message, code: error.code}
|
return callback {message: error.message, code: error.code}
|
||||||
if error.message == 'unexpected arguments'
|
if error.message == 'unexpected arguments'
|
||||||
|
# the payload might be very large, put it on level info
|
||||||
logger.log attrs, 'unexpected arguments'
|
logger.log attrs, 'unexpected arguments'
|
||||||
metrics.inc 'unexpected-arguments', 1, { status: method }
|
metrics.inc 'unexpected-arguments', 1, { status: method }
|
||||||
return callback { message: error.message }
|
return callback { message: error.message }
|
||||||
|
|
76
services/real-time/test/acceptance/coffee/RouterTests.coffee
Normal file
76
services/real-time/test/acceptance/coffee/RouterTests.coffee
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
async = require "async"
|
||||||
|
{expect} = require("chai")
|
||||||
|
|
||||||
|
RealTimeClient = require "./helpers/RealTimeClient"
|
||||||
|
FixturesManager = require "./helpers/FixturesManager"
|
||||||
|
|
||||||
|
|
||||||
|
describe "Router", ->
|
||||||
|
describe "joinProject", ->
|
||||||
|
describe "when there is no callback provided", ->
|
||||||
|
after () ->
|
||||||
|
process.removeListener('unhandledRejection', @onUnhandled)
|
||||||
|
|
||||||
|
before (done) ->
|
||||||
|
@onUnhandled = (error) ->
|
||||||
|
done(error)
|
||||||
|
process.on('unhandledRejection', @onUnhandled)
|
||||||
|
async.series [
|
||||||
|
(cb) =>
|
||||||
|
FixturesManager.setUpProject {
|
||||||
|
privilegeLevel: "owner"
|
||||||
|
project: {
|
||||||
|
name: "Test Project"
|
||||||
|
}
|
||||||
|
}, (e, {@project_id, @user_id}) =>
|
||||||
|
cb(e)
|
||||||
|
|
||||||
|
(cb) =>
|
||||||
|
@client = RealTimeClient.connect()
|
||||||
|
@client.on "connectionAccepted", cb
|
||||||
|
|
||||||
|
(cb) =>
|
||||||
|
@client = RealTimeClient.connect()
|
||||||
|
@client.on "connectionAccepted", cb
|
||||||
|
|
||||||
|
(cb) =>
|
||||||
|
@client.emit "joinProject", project_id: @project_id
|
||||||
|
setTimeout(cb, 100)
|
||||||
|
], done
|
||||||
|
|
||||||
|
it "should keep on going", ->
|
||||||
|
expect('still running').to.exist
|
||||||
|
|
||||||
|
describe "when there are too many arguments", ->
|
||||||
|
after () ->
|
||||||
|
process.removeListener('unhandledRejection', @onUnhandled)
|
||||||
|
|
||||||
|
before (done) ->
|
||||||
|
@onUnhandled = (error) ->
|
||||||
|
done(error)
|
||||||
|
process.on('unhandledRejection', @onUnhandled)
|
||||||
|
async.series [
|
||||||
|
(cb) =>
|
||||||
|
FixturesManager.setUpProject {
|
||||||
|
privilegeLevel: "owner"
|
||||||
|
project: {
|
||||||
|
name: "Test Project"
|
||||||
|
}
|
||||||
|
}, (e, {@project_id, @user_id}) =>
|
||||||
|
cb(e)
|
||||||
|
|
||||||
|
(cb) =>
|
||||||
|
@client = RealTimeClient.connect()
|
||||||
|
@client.on "connectionAccepted", cb
|
||||||
|
|
||||||
|
(cb) =>
|
||||||
|
@client = RealTimeClient.connect()
|
||||||
|
@client.on "connectionAccepted", cb
|
||||||
|
|
||||||
|
(cb) =>
|
||||||
|
@client.emit "joinProject", 1, 2, 3, 4, 5, (@error) =>
|
||||||
|
cb()
|
||||||
|
], done
|
||||||
|
|
||||||
|
it "should return an error message", ->
|
||||||
|
expect(@error.message).to.equal('unexpected arguments')
|
Loading…
Reference in a new issue