2020-03-09 09:36:13 -04:00
|
|
|
const Settings = require('settings-sharelatex')
|
|
|
|
const request = require('./helpers/request')
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
describe('BodyParserErrors', function() {
|
|
|
|
describe('when request is too large', function() {
|
|
|
|
describe('json', function() {
|
|
|
|
it('return 413', function(done) {
|
|
|
|
request.post(
|
|
|
|
{
|
|
|
|
url: '/login',
|
|
|
|
body: { password: wayTooLongString },
|
|
|
|
json: true
|
|
|
|
},
|
|
|
|
(error, response, body) => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
response.statusCode.should.equal(413)
|
|
|
|
body.should.deep.equal({})
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('urlencoded', function() {
|
|
|
|
it('return 413', function(done) {
|
|
|
|
request.post(
|
|
|
|
{
|
|
|
|
url: '/login',
|
|
|
|
form: { password: wayTooLongString }
|
|
|
|
},
|
|
|
|
(error, response, body) => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
response.statusCode.should.equal(413)
|
2020-04-01 11:07:59 -04:00
|
|
|
body.should.match(/I'm afraid I can't do that./)
|
2020-03-09 09:36:13 -04:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when request is not too large', function() {
|
|
|
|
describe('json', function() {
|
|
|
|
it('return normal status code', function(done) {
|
|
|
|
request.post(
|
|
|
|
{
|
|
|
|
url: '/login',
|
|
|
|
body: { password: 'foo' },
|
|
|
|
json: true
|
|
|
|
},
|
|
|
|
(error, response, body) => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
response.statusCode.should.equal(403)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('urlencoded', function() {
|
|
|
|
it('return normal status code', function(done) {
|
|
|
|
request.post(
|
|
|
|
{
|
|
|
|
url: '/login',
|
|
|
|
form: { password: 'foo' }
|
|
|
|
},
|
|
|
|
(error, response, body) => {
|
|
|
|
if (error) {
|
|
|
|
return done(error)
|
|
|
|
}
|
|
|
|
response.statusCode.should.equal(403)
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|