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/utils'
19 const expect = chai.expect
25 registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig
26 } from '../../../../shared/utils/index'
28 describe('Test application behind a reverse proxy', function () {
32 before(async function () {
36 server = await runServer(1)
37 await setAccessTokensToServers([ server ])
39 const { body } = await uploadVideo(server.url, server.accessToken, {})
40 videoId = body.video.uuid
43 it('Should view a video only once with the same IP by default', async function () {
46 await viewVideo(server.url, videoId)
47 await viewVideo(server.url, videoId)
49 // Wait the repeatable job
52 const { body } = await getVideo(server.url, videoId)
53 expect(body.views).to.equal(1)
56 it('Should view a video 2 times with the X-Forwarded-For header set', async function () {
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')
62 // Wait the repeatable job
65 const { body } = await getVideo(server.url, videoId)
66 expect(body.views).to.equal(3)
69 it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () {
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')
75 // Wait the repeatable job
78 const { body } = await getVideo(server.url, videoId)
79 expect(body.views).to.equal(4)
82 it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () {
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')
88 // Wait the repeatable job
91 const { body } = await getVideo(server.url, videoId)
92 expect(body.views).to.equal(6)
95 it('Should rate limit logins', async function () {
96 const user = { username: 'root', password: 'fail' }
98 for (let i = 0; i < 19; i++) {
99 await userLogin(server, user, 400)
102 await userLogin(server, user, 429)
105 after(async function () {
106 killallServers([ server ])