| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- 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)
- const wayTooLongString = 'a'.repeat(2 * Settings.max_doc_length + 64 * 1024 + 1)
- 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)
- body.should.match(/Something went wrong, sorry/)
- 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()
- }
- )
- })
- })
- })
- })
|