]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/reverse-proxy.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / reverse-proxy.ts
index e7dc1653158c8715c9df165b8bddd414fbe40e04..d0d79c4f616683a361c4684e1448223594dc61b8 100644 (file)
@@ -1,29 +1,11 @@
-/* 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/extra-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/extra-utils/index'
+const expect = chai.expect
 
 describe('Test application behind a reverse proxy', function () {
   let server = null
@@ -32,8 +14,26 @@ describe('Test application behind a reverse proxy', function () {
   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, {})
@@ -102,7 +102,48 @@ describe('Test application behind a reverse proxy', function () {
     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 ])
   })
 })