2021-07-07 09:38:56 +00:00
|
|
|
const Settings = require('@overleaf/settings')
|
2020-03-09 13:36:13 +00:00
|
|
|
const request = require('./helpers/request')
|
|
|
|
|
|
|
|
// create a string that is longer than the max allowed (as defined in Server.js)
|
2020-03-18 14:26:53 +00:00
|
|
|
const wayTooLongString = 'a'.repeat(Settings.max_json_request_size + 1)
|
2020-03-09 13:36:13 +00:00
|
|
|
|
2021-04-14 13:17:21 +00:00
|
|
|
describe('BodyParserErrors', function () {
|
|
|
|
describe('when request is too large', function () {
|
|
|
|
describe('json', function () {
|
|
|
|
it('return 413', function (done) {
|
2020-03-09 13:36:13 +00:00
|
|
|
request.post(
|
|
|
|
{
|
|
|
|
url: '/login',
|
|
|
|
body: { password: wayTooLongString },
|
2021-04-27 07:52:58 +00:00
|
|
|
json: true,
|
2020-03-09 13:36:13 +00:00
|
|
|
},
|
|
|
|
(error, response, body) => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
response.statusCode.should.equal(413)
|
|
|
|
body.should.deep.equal({})
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 13:17:21 +00:00
|
|
|
describe('urlencoded', function () {
|
|
|
|
it('return 413', function (done) {
|
2020-03-09 13:36:13 +00:00
|
|
|
request.post(
|
|
|
|
{
|
|
|
|
url: '/login',
|
2021-04-27 07:52:58 +00:00
|
|
|
form: { password: wayTooLongString },
|
2020-03-09 13:36:13 +00:00
|
|
|
},
|
|
|
|
(error, response, body) => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
response.statusCode.should.equal(413)
|
2022-06-22 09:33:22 +00:00
|
|
|
body.should.match(/There was a problem with your request/)
|
2020-03-09 13:36:13 +00:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 13:17:21 +00:00
|
|
|
describe('when request is not too large', function () {
|
|
|
|
describe('json', function () {
|
|
|
|
it('return normal status code', function (done) {
|
2020-03-09 13:36:13 +00:00
|
|
|
request.post(
|
|
|
|
{
|
|
|
|
url: '/login',
|
|
|
|
body: { password: 'foo' },
|
2021-04-27 07:52:58 +00:00
|
|
|
json: true,
|
2020-03-09 13:36:13 +00:00
|
|
|
},
|
|
|
|
(error, response, body) => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
response.statusCode.should.equal(403)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 13:17:21 +00:00
|
|
|
describe('urlencoded', function () {
|
|
|
|
it('return normal status code', function (done) {
|
2020-03-09 13:36:13 +00:00
|
|
|
request.post(
|
|
|
|
{
|
|
|
|
url: '/login',
|
2021-04-27 07:52:58 +00:00
|
|
|
form: { password: 'foo' },
|
2020-03-09 13:36:13 +00:00
|
|
|
},
|
|
|
|
(error, response, body) => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
response.statusCode.should.equal(403)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|