BodyParserErrorsTest.mjs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import Settings from '@overleaf/settings'
  2. import request from './helpers/request.js'
  3. // create a string that is longer than the max allowed (as defined in Server.js)
  4. const wayTooLongString = 'a'.repeat(Settings.max_json_request_size + 1)
  5. describe('BodyParserErrors', function () {
  6. describe('when request is too large', function () {
  7. describe('json', function () {
  8. it('return 413', function (done) {
  9. request.post(
  10. {
  11. url: '/login',
  12. body: { password: wayTooLongString },
  13. json: true,
  14. },
  15. (error, response, body) => {
  16. if (error) {
  17. return done(error)
  18. }
  19. response.statusCode.should.equal(413)
  20. body.should.deep.equal({})
  21. done()
  22. }
  23. )
  24. })
  25. })
  26. describe('urlencoded', function () {
  27. it('return 413', function (done) {
  28. request.post(
  29. {
  30. url: '/login',
  31. form: { password: wayTooLongString },
  32. },
  33. (error, response, body) => {
  34. if (error) {
  35. return done(error)
  36. }
  37. response.statusCode.should.equal(413)
  38. body.should.match(/There was a problem with your request/)
  39. done()
  40. }
  41. )
  42. })
  43. })
  44. })
  45. describe('when request is not too large', function () {
  46. describe('json', function () {
  47. it('return normal status code', function (done) {
  48. request.post(
  49. {
  50. url: '/login',
  51. body: { password: 'foo' },
  52. json: true,
  53. },
  54. (error, response, body) => {
  55. if (error) {
  56. return done(error)
  57. }
  58. response.statusCode.should.equal(403)
  59. done()
  60. }
  61. )
  62. })
  63. })
  64. describe('urlencoded', function () {
  65. it('return normal status code', function (done) {
  66. request.post(
  67. {
  68. url: '/login',
  69. form: { password: 'foo' },
  70. },
  71. (error, response, body) => {
  72. if (error) {
  73. return done(error)
  74. }
  75. response.statusCode.should.equal(403)
  76. done()
  77. }
  78. )
  79. })
  80. })
  81. })
  82. })