diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/check-params/registrations.ts | 39 |
1 files changed, 35 insertions, 4 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 () { |