]>
Commit | Line | Data |
---|---|---|
490b595a C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { About } from '../../../../shared/models/server/about.model' | |
6 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' | |
6b616860 C |
7 | import { |
8 | deleteCustomConfig, | |
9 | getAbout, | |
10 | getVideo, | |
11 | killallServers, | |
12 | login, | |
13 | reRunServer, | |
14 | uploadVideo, | |
15 | userLogin, | |
16 | viewVideo, | |
17 | wait | |
94565d52 | 18 | } from '../../../../shared/extra-utils' |
490b595a C |
19 | const expect = chai.expect |
20 | ||
21 | import { | |
22 | getConfig, | |
23 | flushTests, | |
210feb6c | 24 | flushAndRunServer, |
490b595a | 25 | registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig |
94565d52 | 26 | } from '../../../../shared/extra-utils/index' |
490b595a C |
27 | |
28 | describe('Test application behind a reverse proxy', function () { | |
29 | let server = null | |
30 | let videoId | |
31 | ||
32 | before(async function () { | |
33 | this.timeout(30000) | |
210feb6c | 34 | server = await flushAndRunServer(1) |
490b595a C |
35 | await setAccessTokensToServers([ server ]) |
36 | ||
37 | const { body } = await uploadVideo(server.url, server.accessToken, {}) | |
38 | videoId = body.video.uuid | |
39 | }) | |
40 | ||
41 | it('Should view a video only once with the same IP by default', async function () { | |
6b616860 C |
42 | this.timeout(20000) |
43 | ||
490b595a C |
44 | await viewVideo(server.url, videoId) |
45 | await viewVideo(server.url, videoId) | |
46 | ||
6b616860 C |
47 | // Wait the repeatable job |
48 | await wait(8000) | |
49 | ||
490b595a C |
50 | const { body } = await getVideo(server.url, videoId) |
51 | expect(body.views).to.equal(1) | |
52 | }) | |
53 | ||
54 | it('Should view a video 2 times with the X-Forwarded-For header set', async function () { | |
6b616860 C |
55 | this.timeout(20000) |
56 | ||
490b595a C |
57 | await viewVideo(server.url, videoId, 204, '0.0.0.1,127.0.0.1') |
58 | await viewVideo(server.url, videoId, 204, '0.0.0.2,127.0.0.1') | |
59 | ||
6b616860 C |
60 | // Wait the repeatable job |
61 | await wait(8000) | |
62 | ||
490b595a C |
63 | const { body } = await getVideo(server.url, videoId) |
64 | expect(body.views).to.equal(3) | |
65 | }) | |
66 | ||
67 | it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () { | |
6b616860 C |
68 | this.timeout(20000) |
69 | ||
490b595a C |
70 | await viewVideo(server.url, videoId, 204, '0.0.0.4,0.0.0.3,::ffff:127.0.0.1') |
71 | await viewVideo(server.url, videoId, 204, '0.0.0.5,0.0.0.3,127.0.0.1') | |
72 | ||
6b616860 C |
73 | // Wait the repeatable job |
74 | await wait(8000) | |
75 | ||
490b595a C |
76 | const { body } = await getVideo(server.url, videoId) |
77 | expect(body.views).to.equal(4) | |
78 | }) | |
79 | ||
80 | it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () { | |
6b616860 C |
81 | this.timeout(20000) |
82 | ||
490b595a C |
83 | await viewVideo(server.url, videoId, 204, '0.0.0.8,0.0.0.6,127.0.0.1') |
84 | await viewVideo(server.url, videoId, 204, '0.0.0.8,0.0.0.7,127.0.0.1') | |
85 | ||
6b616860 C |
86 | // Wait the repeatable job |
87 | await wait(8000) | |
88 | ||
490b595a C |
89 | const { body } = await getVideo(server.url, videoId) |
90 | expect(body.views).to.equal(6) | |
91 | }) | |
92 | ||
93 | it('Should rate limit logins', async function () { | |
94 | const user = { username: 'root', password: 'fail' } | |
95 | ||
e79d0ba5 | 96 | for (let i = 0; i < 19; i++) { |
490b595a C |
97 | await userLogin(server, user, 400) |
98 | } | |
99 | ||
100 | await userLogin(server, user, 429) | |
101 | }) | |
102 | ||
210feb6c | 103 | after(function () { |
3cd0734f | 104 | killallServers([ server ]) |
490b595a C |
105 | }) |
106 | }) |