2018-03-29 03:58:24 -05:00
|
|
|
/* tslint:disable:no-unused-expression */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import * as chai from 'chai'
|
|
|
|
import { About } from '../../../../shared/models/server/about.model'
|
|
|
|
import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
|
2018-08-29 09:26:25 -05:00
|
|
|
import {
|
|
|
|
deleteCustomConfig,
|
|
|
|
getAbout,
|
|
|
|
getVideo,
|
|
|
|
killallServers,
|
|
|
|
login,
|
|
|
|
reRunServer,
|
|
|
|
uploadVideo,
|
|
|
|
userLogin,
|
|
|
|
viewVideo,
|
|
|
|
wait
|
2019-04-15 08:26:15 -05:00
|
|
|
} from '../../../../shared/extra-utils'
|
2018-03-29 03:58:24 -05:00
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
import {
|
|
|
|
getConfig,
|
|
|
|
flushTests,
|
2019-04-24 03:53:40 -05:00
|
|
|
flushAndRunServer,
|
2018-03-29 03:58:24 -05:00
|
|
|
registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig
|
2019-04-15 08:26:15 -05:00
|
|
|
} from '../../../../shared/extra-utils/index'
|
2018-03-29 03:58:24 -05:00
|
|
|
|
|
|
|
describe('Test application behind a reverse proxy', function () {
|
|
|
|
let server = null
|
|
|
|
let videoId
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
2019-04-24 03:53:40 -05:00
|
|
|
server = await flushAndRunServer(1)
|
2018-03-29 03:58:24 -05:00
|
|
|
await setAccessTokensToServers([ server ])
|
|
|
|
|
|
|
|
const { body } = await uploadVideo(server.url, server.accessToken, {})
|
|
|
|
videoId = body.video.uuid
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should view a video only once with the same IP by default', async function () {
|
2018-08-29 09:26:25 -05:00
|
|
|
this.timeout(20000)
|
|
|
|
|
2018-03-29 03:58:24 -05:00
|
|
|
await viewVideo(server.url, videoId)
|
|
|
|
await viewVideo(server.url, videoId)
|
|
|
|
|
2018-08-29 09:26:25 -05:00
|
|
|
// Wait the repeatable job
|
|
|
|
await wait(8000)
|
|
|
|
|
2018-03-29 03:58:24 -05:00
|
|
|
const { body } = await getVideo(server.url, videoId)
|
|
|
|
expect(body.views).to.equal(1)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should view a video 2 times with the X-Forwarded-For header set', async function () {
|
2018-08-29 09:26:25 -05:00
|
|
|
this.timeout(20000)
|
|
|
|
|
2018-03-29 03:58:24 -05:00
|
|
|
await viewVideo(server.url, videoId, 204, '0.0.0.1,127.0.0.1')
|
|
|
|
await viewVideo(server.url, videoId, 204, '0.0.0.2,127.0.0.1')
|
|
|
|
|
2018-08-29 09:26:25 -05:00
|
|
|
// Wait the repeatable job
|
|
|
|
await wait(8000)
|
|
|
|
|
2018-03-29 03:58:24 -05:00
|
|
|
const { body } = await getVideo(server.url, videoId)
|
|
|
|
expect(body.views).to.equal(3)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should view a video only once with the same client IP in the X-Forwarded-For header', async function () {
|
2018-08-29 09:26:25 -05:00
|
|
|
this.timeout(20000)
|
|
|
|
|
2018-03-29 03:58:24 -05:00
|
|
|
await viewVideo(server.url, videoId, 204, '0.0.0.4,0.0.0.3,::ffff:127.0.0.1')
|
|
|
|
await viewVideo(server.url, videoId, 204, '0.0.0.5,0.0.0.3,127.0.0.1')
|
|
|
|
|
2018-08-29 09:26:25 -05:00
|
|
|
// Wait the repeatable job
|
|
|
|
await wait(8000)
|
|
|
|
|
2018-03-29 03:58:24 -05:00
|
|
|
const { body } = await getVideo(server.url, videoId)
|
|
|
|
expect(body.views).to.equal(4)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should view a video two times with a different client IP in the X-Forwarded-For header', async function () {
|
2018-08-29 09:26:25 -05:00
|
|
|
this.timeout(20000)
|
|
|
|
|
2018-03-29 03:58:24 -05:00
|
|
|
await viewVideo(server.url, videoId, 204, '0.0.0.8,0.0.0.6,127.0.0.1')
|
|
|
|
await viewVideo(server.url, videoId, 204, '0.0.0.8,0.0.0.7,127.0.0.1')
|
|
|
|
|
2018-08-29 09:26:25 -05:00
|
|
|
// Wait the repeatable job
|
|
|
|
await wait(8000)
|
|
|
|
|
2018-03-29 03:58:24 -05:00
|
|
|
const { body } = await getVideo(server.url, videoId)
|
|
|
|
expect(body.views).to.equal(6)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should rate limit logins', async function () {
|
|
|
|
const user = { username: 'root', password: 'fail' }
|
|
|
|
|
2019-02-11 04:01:50 -06:00
|
|
|
for (let i = 0; i < 19; i++) {
|
2018-03-29 03:58:24 -05:00
|
|
|
await userLogin(server, user, 400)
|
|
|
|
}
|
|
|
|
|
|
|
|
await userLogin(server, user, 429)
|
|
|
|
})
|
|
|
|
|
2019-04-24 03:53:40 -05:00
|
|
|
after(function () {
|
2018-06-13 03:06:50 -05:00
|
|
|
killallServers([ server ])
|
2018-03-29 03:58:24 -05:00
|
|
|
})
|
|
|
|
})
|