]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/reverse-proxy.ts
Merge branch 'release/v1.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / reverse-proxy.ts
CommitLineData
490b595a
C
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import * as chai from 'chai'
7c3b7976
C
5import { cleanupTests, getVideo, uploadVideo, userLogin, viewVideo, wait } from '../../../../shared/extra-utils'
6import { flushAndRunServer, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
490b595a 7
7c3b7976 8const expect = chai.expect
490b595a
C
9
10describe('Test application behind a reverse proxy', function () {
11 let server = null
12 let videoId
13
14 before(async function () {
15 this.timeout(30000)
210feb6c 16 server = await flushAndRunServer(1)
490b595a
C
17 await setAccessTokensToServers([ server ])
18
19 const { body } = await uploadVideo(server.url, server.accessToken, {})
20 videoId = body.video.uuid
21 })
22
23 it('Should view a video only once with the same IP by default', async function () {
6b616860
C
24 this.timeout(20000)
25
490b595a
C
26 await viewVideo(server.url, videoId)
27 await viewVideo(server.url, videoId)
28
6b616860
C
29 // Wait the repeatable job
30 await wait(8000)
31
490b595a
C
32 const { body } = await getVideo(server.url, videoId)
33 expect(body.views).to.equal(1)
34 })
35
36 it('Should view a video 2 times with the X-Forwarded-For header set', async function () {
6b616860
C
37 this.timeout(20000)
38
490b595a
C
39 await viewVideo(server.url, videoId, 204, '0.0.0.1,127.0.0.1')
40 await viewVideo(server.url, videoId, 204, '0.0.0.2,127.0.0.1')
41
6b616860
C
42 // Wait the repeatable job
43 await wait(8000)
44
490b595a
C
45 const { body } = await getVideo(server.url, videoId)
46 expect(body.views).to.equal(3)
47 })
48
49 it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () {
6b616860
C
50 this.timeout(20000)
51
490b595a
C
52 await viewVideo(server.url, videoId, 204, '0.0.0.4,0.0.0.3,::ffff:127.0.0.1')
53 await viewVideo(server.url, videoId, 204, '0.0.0.5,0.0.0.3,127.0.0.1')
54
6b616860
C
55 // Wait the repeatable job
56 await wait(8000)
57
490b595a
C
58 const { body } = await getVideo(server.url, videoId)
59 expect(body.views).to.equal(4)
60 })
61
62 it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () {
6b616860
C
63 this.timeout(20000)
64
490b595a
C
65 await viewVideo(server.url, videoId, 204, '0.0.0.8,0.0.0.6,127.0.0.1')
66 await viewVideo(server.url, videoId, 204, '0.0.0.8,0.0.0.7,127.0.0.1')
67
6b616860
C
68 // Wait the repeatable job
69 await wait(8000)
70
490b595a
C
71 const { body } = await getVideo(server.url, videoId)
72 expect(body.views).to.equal(6)
73 })
74
75 it('Should rate limit logins', async function () {
76 const user = { username: 'root', password: 'fail' }
77
e79d0ba5 78 for (let i = 0; i < 19; i++) {
490b595a
C
79 await userLogin(server, user, 400)
80 }
81
82 await userLogin(server, user, 429)
83 })
84
7c3b7976
C
85 after(async function () {
86 await cleanupTests([ server ])
490b595a
C
87 })
88})