describe('Test application behind a reverse proxy', function () {
let server: PeerTubeServer
+ let userAccessToken: string
let videoId: string
before(async function () {
- this.timeout(30000)
+ this.timeout(60000)
const config = {
rates_limit: {
server = await createSingleServer(1, config)
await setAccessTokensToServers([ server ])
+ userAccessToken = await server.users.generateUserAndToken('user')
+
const { uuid } = await server.videos.upload()
videoId = uuid
})
it('Should view a video only once with the same IP by default', async function () {
- this.timeout(20000)
+ this.timeout(40000)
await server.views.simulateView({ id: videoId })
await server.views.simulateView({ id: videoId })
it('Should rate limit logins', async function () {
const user = { username: 'root', password: 'fail' }
- for (let i = 0; i < 19; i++) {
+ for (let i = 0; i < 18; i++) {
await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
}
it('Should rate limit signup', async function () {
for (let i = 0; i < 10; i++) {
try {
- await server.users.register({ username: 'test' + i })
+ await server.registrations.register({ username: 'test' + i })
} catch {
// empty
}
}
- await server.users.register({ username: 'test42', expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 })
+ await server.registrations.register({ username: 'test42', expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 })
})
it('Should not rate limit failed signup', async function () {
await wait(7000)
for (let i = 0; i < 3; i++) {
- await server.users.register({ username: 'test' + i, expectedStatus: HttpStatusCode.CONFLICT_409 })
+ await server.registrations.register({ username: 'test' + i, expectedStatus: HttpStatusCode.CONFLICT_409 })
}
- await server.users.register({ username: 'test43', expectedStatus: HttpStatusCode.NO_CONTENT_204 })
+ await server.registrations.register({ username: 'test43', expectedStatus: HttpStatusCode.NO_CONTENT_204 })
})
await server.videos.get({ id: videoId, expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 })
})
+ it('Should rate limit API calls with a user but not with an admin', async function () {
+ await server.videos.get({ id: videoId, token: userAccessToken, expectedStatus: HttpStatusCode.TOO_MANY_REQUESTS_429 })
+
+ await server.videos.get({ id: videoId, token: server.accessToken, expectedStatus: HttpStatusCode.OK_200 })
+ })
+
after(async function () {
await cleanupTests([ server ])
})