1 /* tslint:disable:no-unused-expression */
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'
18 } from '../../../../shared/extra-utils'
19 const expect = chai.expect
25 registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig
26 } from '../../../../shared/extra-utils/index'
28 describe('Test application behind a reverse proxy', function () {
32 before(async function () {
34 server = await flushAndRunServer(1)
35 await setAccessTokensToServers([ server ])
37 const { body } = await uploadVideo(server.url, server.accessToken, {})
38 videoId = body.video.uuid
41 it('Should view a video only once with the same IP by default', async function () {
44 await viewVideo(server.url, videoId)
45 await viewVideo(server.url, videoId)
47 // Wait the repeatable job
50 const { body } = await getVideo(server.url, videoId)
51 expect(body.views).to.equal(1)
54 it('Should view a video 2 times with the X-Forwarded-For header set', async function () {
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')
60 // Wait the repeatable job
63 const { body } = await getVideo(server.url, videoId)
64 expect(body.views).to.equal(3)
67 it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () {
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')
73 // Wait the repeatable job
76 const { body } = await getVideo(server.url, videoId)
77 expect(body.views).to.equal(4)
80 it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () {
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')
86 // Wait the repeatable job
89 const { body } = await getVideo(server.url, videoId)
90 expect(body.views).to.equal(6)
93 it('Should rate limit logins', async function () {
94 const user = { username: 'root', password: 'fail' }
96 for (let i = 0; i < 19; i++) {
97 await userLogin(server, user, 400)
100 await userLogin(server, user, 429)
104 killallServers([ server ])