1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
5 import { cleanupTests, getVideo, uploadVideo, userLogin, viewVideo, wait } from '../../../../shared/extra-utils'
6 import { flushAndRunServer, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
8 const expect = chai.expect
10 describe('Test application behind a reverse proxy', function () {
14 before(async function () {
16 server = await flushAndRunServer(1)
17 await setAccessTokensToServers([ server ])
19 const { body } = await uploadVideo(server.url, server.accessToken, {})
20 videoId = body.video.uuid
23 it('Should view a video only once with the same IP by default', async function () {
26 await viewVideo(server.url, videoId)
27 await viewVideo(server.url, videoId)
29 // Wait the repeatable job
32 const { body } = await getVideo(server.url, videoId)
33 expect(body.views).to.equal(1)
36 it('Should view a video 2 times with the X-Forwarded-For header set', async function () {
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')
42 // Wait the repeatable job
45 const { body } = await getVideo(server.url, videoId)
46 expect(body.views).to.equal(3)
49 it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () {
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')
55 // Wait the repeatable job
58 const { body } = await getVideo(server.url, videoId)
59 expect(body.views).to.equal(4)
62 it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () {
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')
68 // Wait the repeatable job
71 const { body } = await getVideo(server.url, videoId)
72 expect(body.views).to.equal(6)
75 it('Should rate limit logins', async function () {
76 const user = { username: 'root', password: 'fail' }
78 for (let i = 0; i < 19; i++) {
79 await userLogin(server, user, 400)
82 await userLogin(server, user, 429)
85 after(async function () {
86 await cleanupTests([ server ])