From bfe2ef6bfae03444a232883fc7c449206cf3bee4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 21 Feb 2019 17:19:16 +0100 Subject: Add request body limit --- server/tests/helpers/index.ts | 1 + server/tests/helpers/request.ts | 48 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 server/tests/helpers/request.ts (limited to 'server/tests/helpers') diff --git a/server/tests/helpers/index.ts b/server/tests/helpers/index.ts index 551208245..03b971770 100644 --- a/server/tests/helpers/index.ts +++ b/server/tests/helpers/index.ts @@ -1,2 +1,3 @@ import './core-utils' import './comment-model' +import './request' diff --git a/server/tests/helpers/request.ts b/server/tests/helpers/request.ts new file mode 100644 index 000000000..95a74fdfa --- /dev/null +++ b/server/tests/helpers/request.ts @@ -0,0 +1,48 @@ +/* tslint:disable:no-unused-expression */ + +import 'mocha' +import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' +import { get4KFileUrl, root, wait } from '../../../shared/utils' +import { join } from 'path' +import { pathExists, remove } from 'fs-extra' +import { expect } from 'chai' + +describe('Request helpers', function () { + const destPath1 = join(root(), 'test-output-1.txt') + const destPath2 = join(root(), 'test-output-2.txt') + + it('Should throw an error when the bytes limit is exceeded for request', async function () { + try { + await doRequest({ uri: get4KFileUrl() }, 3) + } catch { + return + } + + throw new Error('No error thrown by do request') + }) + + it('Should throw an error when the bytes limit is exceeded for request and save file', async function () { + try { + await doRequestAndSaveToFile({ uri: get4KFileUrl() }, destPath1, 3) + } catch { + + await wait(500) + expect(await pathExists(destPath1)).to.be.false + return + } + + throw new Error('No error thrown by do request and save to file') + }) + + it('Should succeed if the file is below the limit', async function () { + await doRequest({ uri: get4KFileUrl() }, 5) + await doRequestAndSaveToFile({ uri: get4KFileUrl() }, destPath2, 5) + + expect(await pathExists(destPath2)).to.be.true + }) + + after(async function () { + await remove(destPath1) + await remove(destPath2) + }) +}) -- cgit v1.2.3