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