-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
import * as chai from 'chai'
-import { About } from '../../../../shared/models/server/about.model'
-import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
-import {
- deleteCustomConfig,
- getAbout,
- getVideo,
- killallServers,
- login,
- reRunServer,
- uploadVideo,
- userLogin,
- viewVideo,
- wait
-} from '../../../../shared/utils'
-const expect = chai.expect
+import { cleanupTests, getVideo, registerUser, uploadVideo, userLogin, viewVideo, wait } from '../../../../shared/extra-utils'
+import { flushAndRunServer, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
-import {
- getConfig,
- flushTests,
- runServer,
- registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig
-} from '../../../../shared/utils/index'
+const expect = chai.expect
describe('Test application behind a reverse proxy', function () {
let server = null
before(async function () {
this.timeout(30000)
- await flushTests()
- server = await runServer(1)
+ const config = {
+ rates_limit: {
+ api: {
+ max: 50,
+ window: 5000
+ },
+ signup: {
+ max: 3,
+ window: 5000
+ },
+ login: {
+ max: 20
+ }
+ },
+ signup: {
+ limit: 20
+ }
+ }
+
+ server = await flushAndRunServer(1, config)
await setAccessTokensToServers([ server ])
const { body } = await uploadVideo(server.url, server.accessToken, {})
it('Should rate limit logins', async function () {
const user = { username: 'root', password: 'fail' }
- for (let i = 0; i < 14; i++) {
+ for (let i = 0; i < 19; i++) {
await userLogin(server, user, 400)
}
await userLogin(server, user, 429)
})
+ it('Should rate limit signup', async function () {
+ for (let i = 0; i < 10; i++) {
+ try {
+ await registerUser(server.url, 'test' + i, 'password')
+ } catch {
+ // empty
+ }
+ }
+
+ await registerUser(server.url, 'test42', 'password', 429)
+ })
+
+ it('Should not rate limit failed signup', async function () {
+ this.timeout(30000)
+
+ await wait(7000)
+
+ for (let i = 0; i < 3; i++) {
+ await registerUser(server.url, 'test' + i, 'password', 409)
+ }
+
+ await registerUser(server.url, 'test43', 'password', 204)
+
+ })
+
+ it('Should rate limit API calls', async function () {
+ this.timeout(30000)
+
+ await wait(7000)
+
+ for (let i = 0; i < 100; i++) {
+ try {
+ await getVideo(server.url, videoId)
+ } catch {
+ // don't care if it fails
+ }
+ }
+
+ await getVideo(server.url, videoId, 429)
+ })
+
after(async function () {
- killallServers([ server ])
+ await cleanupTests([ server ])
})
})