diff options
author | Chocobozzz <me@florianbigard.com> | 2023-01-19 15:27:04 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-01-19 15:27:04 +0100 |
commit | 9436936cf68b6c1225298b0e30c23c40f0d15bda (patch) | |
tree | 16aa786d941b10b29b03c84f3c69a9fd1e597dd5 | |
parent | 4e4c23c5b8d55ab0aa48a7be8c53ec71d1d7e796 (diff) | |
download | PeerTube-9436936cf68b6c1225298b0e30c23c40f0d15bda.tar.gz PeerTube-9436936cf68b6c1225298b0e30c23c40f0d15bda.tar.zst PeerTube-9436936cf68b6c1225298b0e30c23c40f0d15bda.zip |
Add more signup limit tests
-rw-r--r-- | server/tests/api/check-params/registrations.ts | 39 | ||||
-rw-r--r-- | shared/server-commands/server/config-command.ts | 4 |
2 files changed, 37 insertions, 6 deletions
diff --git a/server/tests/api/check-params/registrations.ts b/server/tests/api/check-params/registrations.ts index 9f0462378..fe16ebd93 100644 --- a/server/tests/api/check-params/registrations.ts +++ b/server/tests/api/check-params/registrations.ts | |||
@@ -1,7 +1,15 @@ | |||
1 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' | 1 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' |
2 | import { omit } from '@shared/core-utils' | 2 | import { omit } from '@shared/core-utils' |
3 | import { HttpStatusCode, UserRole } from '@shared/models' | 3 | import { HttpStatusCode, UserRole } from '@shared/models' |
4 | import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' | 4 | import { |
5 | cleanupTests, | ||
6 | createSingleServer, | ||
7 | makePostBodyRequest, | ||
8 | PeerTubeServer, | ||
9 | setAccessTokensToServers, | ||
10 | setDefaultAccountAvatar, | ||
11 | setDefaultChannelAvatar | ||
12 | } from '@shared/server-commands' | ||
5 | 13 | ||
6 | describe('Test registrations API validators', function () { | 14 | describe('Test registrations API validators', function () { |
7 | let server: PeerTubeServer | 15 | let server: PeerTubeServer |
@@ -16,6 +24,9 @@ describe('Test registrations API validators', function () { | |||
16 | server = await createSingleServer(1) | 24 | server = await createSingleServer(1) |
17 | 25 | ||
18 | await setAccessTokensToServers([ server ]) | 26 | await setAccessTokensToServers([ server ]) |
27 | await setDefaultAccountAvatar([ server ]) | ||
28 | await setDefaultChannelAvatar([ server ]) | ||
29 | |||
19 | await server.config.enableSignup(false); | 30 | await server.config.enableSignup(false); |
20 | 31 | ||
21 | ({ token: moderatorToken } = await server.users.generate('moderator', UserRole.MODERATOR)); | 32 | ({ token: moderatorToken } = await server.users.generate('moderator', UserRole.MODERATOR)); |
@@ -37,7 +48,10 @@ describe('Test registrations API validators', function () { | |||
37 | describe('When registering a new user or requesting user registration', function () { | 48 | describe('When registering a new user or requesting user registration', function () { |
38 | 49 | ||
39 | async function check (fields: any, expectedStatus = HttpStatusCode.BAD_REQUEST_400) { | 50 | async function check (fields: any, expectedStatus = HttpStatusCode.BAD_REQUEST_400) { |
51 | await server.config.enableSignup(false) | ||
40 | await makePostBodyRequest({ url: server.url, path: registrationPath, fields, expectedStatus }) | 52 | await makePostBodyRequest({ url: server.url, path: registrationPath, fields, expectedStatus }) |
53 | |||
54 | await server.config.enableSignup(true) | ||
41 | await makePostBodyRequest({ url: server.url, path: registrationRequestPath, fields, expectedStatus }) | 55 | await makePostBodyRequest({ url: server.url, path: registrationRequestPath, fields, expectedStatus }) |
42 | } | 56 | } |
43 | 57 | ||
@@ -138,7 +152,7 @@ describe('Test registrations API validators', function () { | |||
138 | it('Should fail on a server with registration disabled', async function () { | 152 | it('Should fail on a server with registration disabled', async function () { |
139 | this.timeout(60000) | 153 | this.timeout(60000) |
140 | 154 | ||
141 | await server.config.updateCustomSubConfig({ | 155 | await server.config.updateExistingSubConfig({ |
142 | newConfig: { | 156 | newConfig: { |
143 | signup: { | 157 | signup: { |
144 | enabled: false | 158 | enabled: false |
@@ -159,15 +173,32 @@ describe('Test registrations API validators', function () { | |||
159 | 173 | ||
160 | const { total } = await server.users.list() | 174 | const { total } = await server.users.list() |
161 | 175 | ||
162 | await server.config.updateCustomSubConfig({ newConfig: { signup: { limit: total } } }) | 176 | await server.config.enableSignup(false, total) |
163 | |||
164 | await server.registrations.register({ username: 'user42', expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | 177 | await server.registrations.register({ username: 'user42', expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
178 | |||
179 | await server.config.enableSignup(true, total) | ||
165 | await server.registrations.requestRegistration({ | 180 | await server.registrations.requestRegistration({ |
166 | username: 'user42', | 181 | username: 'user42', |
167 | registrationReason: 'reason', | 182 | registrationReason: 'reason', |
168 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | 183 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
169 | }) | 184 | }) |
170 | }) | 185 | }) |
186 | |||
187 | it('Should succeed if the user limit is not reached', async function () { | ||
188 | this.timeout(60000) | ||
189 | |||
190 | const { total } = await server.users.list() | ||
191 | |||
192 | await server.config.enableSignup(false, total + 1) | ||
193 | await server.registrations.register({ username: 'user43', expectedStatus: HttpStatusCode.NO_CONTENT_204 }) | ||
194 | |||
195 | await server.config.enableSignup(true, total + 2) | ||
196 | await server.registrations.requestRegistration({ | ||
197 | username: 'user44', | ||
198 | registrationReason: 'reason', | ||
199 | expectedStatus: HttpStatusCode.OK_200 | ||
200 | }) | ||
201 | }) | ||
171 | }) | 202 | }) |
172 | 203 | ||
173 | describe('On direct registration', function () { | 204 | describe('On direct registration', function () { |
diff --git a/shared/server-commands/server/config-command.ts b/shared/server-commands/server/config-command.ts index 51267b85b..eb6bb95a5 100644 --- a/shared/server-commands/server/config-command.ts +++ b/shared/server-commands/server/config-command.ts | |||
@@ -31,13 +31,13 @@ export class ConfigCommand extends AbstractCommand { | |||
31 | 31 | ||
32 | // --------------------------------------------------------------------------- | 32 | // --------------------------------------------------------------------------- |
33 | 33 | ||
34 | enableSignup (requiresApproval: boolean) { | 34 | enableSignup (requiresApproval: boolean, limit = -1) { |
35 | return this.updateExistingSubConfig({ | 35 | return this.updateExistingSubConfig({ |
36 | newConfig: { | 36 | newConfig: { |
37 | signup: { | 37 | signup: { |
38 | enabled: true, | 38 | enabled: true, |
39 | requiresApproval, | 39 | requiresApproval, |
40 | limit: -1 | 40 | limit |
41 | } | 41 | } |
42 | } | 42 | } |
43 | }) | 43 | }) |