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