diff options
author | Chocobozzz <me@florianbigard.com> | 2019-02-21 17:19:16 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-02-21 17:19:16 +0100 |
commit | bfe2ef6bfae03444a232883fc7c449206cf3bee4 (patch) | |
tree | d1ee39e1700f6918c2799c5537da771bda468890 /server/tests | |
parent | 539d3f4faa1c1d2dbc68bb3ac0ba3549252e0f2a (diff) | |
download | PeerTube-bfe2ef6bfae03444a232883fc7c449206cf3bee4.tar.gz PeerTube-bfe2ef6bfae03444a232883fc7c449206cf3bee4.tar.zst PeerTube-bfe2ef6bfae03444a232883fc7c449206cf3bee4.zip |
Add request body limit
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/helpers/index.ts | 1 | ||||
-rw-r--r-- | server/tests/helpers/request.ts | 48 |
2 files changed, 49 insertions, 0 deletions
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 @@ | |||
1 | import './core-utils' | 1 | import './core-utils' |
2 | import './comment-model' | 2 | import './comment-model' |
3 | 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 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' | ||
5 | import { get4KFileUrl, root, wait } from '../../../shared/utils' | ||
6 | import { join } from 'path' | ||
7 | import { pathExists, remove } from 'fs-extra' | ||
8 | import { expect } from 'chai' | ||
9 | |||
10 | describe('Request helpers', function () { | ||
11 | const destPath1 = join(root(), 'test-output-1.txt') | ||
12 | const destPath2 = join(root(), 'test-output-2.txt') | ||
13 | |||
14 | it('Should throw an error when the bytes limit is exceeded for request', async function () { | ||
15 | try { | ||
16 | await doRequest({ uri: get4KFileUrl() }, 3) | ||
17 | } catch { | ||
18 | return | ||
19 | } | ||
20 | |||
21 | throw new Error('No error thrown by do request') | ||
22 | }) | ||
23 | |||
24 | it('Should throw an error when the bytes limit is exceeded for request and save file', async function () { | ||
25 | try { | ||
26 | await doRequestAndSaveToFile({ uri: get4KFileUrl() }, destPath1, 3) | ||
27 | } catch { | ||
28 | |||
29 | await wait(500) | ||
30 | expect(await pathExists(destPath1)).to.be.false | ||
31 | return | ||
32 | } | ||
33 | |||
34 | throw new Error('No error thrown by do request and save to file') | ||
35 | }) | ||
36 | |||
37 | it('Should succeed if the file is below the limit', async function () { | ||
38 | await doRequest({ uri: get4KFileUrl() }, 5) | ||
39 | await doRequestAndSaveToFile({ uri: get4KFileUrl() }, destPath2, 5) | ||
40 | |||
41 | expect(await pathExists(destPath2)).to.be.true | ||
42 | }) | ||
43 | |||
44 | after(async function () { | ||
45 | await remove(destPath1) | ||
46 | await remove(destPath2) | ||
47 | }) | ||
48 | }) | ||