aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/users.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/users.ts')
-rw-r--r--server/tests/api/check-params/users.ts77
1 files changed, 40 insertions, 37 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index bffe29bce..fda7e9640 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -15,7 +15,6 @@ import {
15 getMyUserVideoRating, 15 getMyUserVideoRating,
16 getUserScopedTokens, 16 getUserScopedTokens,
17 getUsersList, 17 getUsersList,
18 immutableAssign,
19 killallServers, 18 killallServers,
20 makeGetRequest, 19 makeGetRequest,
21 makePostBodyRequest, 20 makePostBodyRequest,
@@ -181,25 +180,25 @@ describe('Test users API validators', function () {
181 } 180 }
182 181
183 it('Should fail with a too small username', async function () { 182 it('Should fail with a too small username', async function () {
184 const fields = immutableAssign(baseCorrectParams, { username: '' }) 183 const fields = { ...baseCorrectParams, username: '' }
185 184
186 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 185 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
187 }) 186 })
188 187
189 it('Should fail with a too long username', async function () { 188 it('Should fail with a too long username', async function () {
190 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) 189 const fields = { ...baseCorrectParams, username: 'super'.repeat(50) }
191 190
192 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 191 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
193 }) 192 })
194 193
195 it('Should fail with a not lowercase username', async function () { 194 it('Should fail with a not lowercase username', async function () {
196 const fields = immutableAssign(baseCorrectParams, { username: 'Toto' }) 195 const fields = { ...baseCorrectParams, username: 'Toto' }
197 196
198 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 197 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
199 }) 198 })
200 199
201 it('Should fail with an incorrect username', async function () { 200 it('Should fail with an incorrect username', async function () {
202 const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) 201 const fields = { ...baseCorrectParams, username: 'my username' }
203 202
204 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 203 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
205 }) 204 })
@@ -211,25 +210,25 @@ describe('Test users API validators', function () {
211 }) 210 })
212 211
213 it('Should fail with an invalid email', async function () { 212 it('Should fail with an invalid email', async function () {
214 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) 213 const fields = { ...baseCorrectParams, email: 'test_example.com' }
215 214
216 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 215 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
217 }) 216 })
218 217
219 it('Should fail with a too small password', async function () { 218 it('Should fail with a too small password', async function () {
220 const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) 219 const fields = { ...baseCorrectParams, password: 'bla' }
221 220
222 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 221 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
223 }) 222 })
224 223
225 it('Should fail with a too long password', async function () { 224 it('Should fail with a too long password', async function () {
226 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) 225 const fields = { ...baseCorrectParams, password: 'super'.repeat(61) }
227 226
228 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 227 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
229 }) 228 })
230 229
231 it('Should fail with empty password and no smtp configured', async function () { 230 it('Should fail with empty password and no smtp configured', async function () {
232 const fields = immutableAssign(baseCorrectParams, { password: '' }) 231 const fields = { ...baseCorrectParams, password: '' }
233 232
234 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 233 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
235 }) 234 })
@@ -239,19 +238,23 @@ describe('Test users API validators', function () {
239 238
240 await killallServers([ server ]) 239 await killallServers([ server ])
241 240
242 const config = immutableAssign(overrideConfig, { 241 const config = {
242 ...overrideConfig,
243
243 smtp: { 244 smtp: {
244 hostname: 'localhost', 245 hostname: 'localhost',
245 port: emailPort 246 port: emailPort
246 } 247 }
247 }) 248 }
248 await reRunServer(server, config) 249 await reRunServer(server, config)
249 250
250 const fields = immutableAssign(baseCorrectParams, { 251 const fields = {
252 ...baseCorrectParams,
253
251 password: '', 254 password: '',
252 username: 'create_password', 255 username: 'create_password',
253 email: 'create_password@example.com' 256 email: 'create_password@example.com'
254 }) 257 }
255 258
256 await makePostBodyRequest({ 259 await makePostBodyRequest({
257 url: server.url, 260 url: server.url,
@@ -263,7 +266,7 @@ describe('Test users API validators', function () {
263 }) 266 })
264 267
265 it('Should fail with invalid admin flags', async function () { 268 it('Should fail with invalid admin flags', async function () {
266 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' }) 269 const fields = { ...baseCorrectParams, adminFlags: 'toto' }
267 270
268 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 271 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
269 }) 272 })
@@ -279,7 +282,7 @@ describe('Test users API validators', function () {
279 }) 282 })
280 283
281 it('Should fail if we add a user with the same username', async function () { 284 it('Should fail if we add a user with the same username', async function () {
282 const fields = immutableAssign(baseCorrectParams, { username: 'user1' }) 285 const fields = { ...baseCorrectParams, username: 'user1' }
283 286
284 await makePostBodyRequest({ 287 await makePostBodyRequest({
285 url: server.url, 288 url: server.url,
@@ -291,7 +294,7 @@ describe('Test users API validators', function () {
291 }) 294 })
292 295
293 it('Should fail if we add a user with the same email', async function () { 296 it('Should fail if we add a user with the same email', async function () {
294 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' }) 297 const fields = { ...baseCorrectParams, email: 'user1@example.com' }
295 298
296 await makePostBodyRequest({ 299 await makePostBodyRequest({
297 url: server.url, 300 url: server.url,
@@ -315,13 +318,13 @@ describe('Test users API validators', function () {
315 }) 318 })
316 319
317 it('Should fail with an invalid videoQuota', async function () { 320 it('Should fail with an invalid videoQuota', async function () {
318 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 }) 321 const fields = { ...baseCorrectParams, videoQuota: -5 }
319 322
320 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 323 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
321 }) 324 })
322 325
323 it('Should fail with an invalid videoQuotaDaily', async function () { 326 it('Should fail with an invalid videoQuotaDaily', async function () {
324 const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 }) 327 const fields = { ...baseCorrectParams, videoQuotaDaily: -7 }
325 328
326 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 329 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
327 }) 330 })
@@ -333,13 +336,13 @@ describe('Test users API validators', function () {
333 }) 336 })
334 337
335 it('Should fail with an invalid user role', async function () { 338 it('Should fail with an invalid user role', async function () {
336 const fields = immutableAssign(baseCorrectParams, { role: 88989 }) 339 const fields = { ...baseCorrectParams, role: 88989 }
337 340
338 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 341 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
339 }) 342 })
340 343
341 it('Should fail with a "peertube" username', async function () { 344 it('Should fail with a "peertube" username', async function () {
342 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) 345 const fields = { ...baseCorrectParams, username: 'peertube' }
343 346
344 await makePostBodyRequest({ 347 await makePostBodyRequest({
345 url: server.url, 348 url: server.url,
@@ -352,7 +355,7 @@ describe('Test users API validators', function () {
352 355
353 it('Should fail to create a moderator or an admin with a moderator', async function () { 356 it('Should fail to create a moderator or an admin with a moderator', async function () {
354 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) { 357 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
355 const fields = immutableAssign(baseCorrectParams, { role }) 358 const fields = { ...baseCorrectParams, role }
356 359
357 await makePostBodyRequest({ 360 await makePostBodyRequest({
358 url: server.url, 361 url: server.url,
@@ -365,7 +368,7 @@ describe('Test users API validators', function () {
365 }) 368 })
366 369
367 it('Should succeed to create a user with a moderator', async function () { 370 it('Should succeed to create a user with a moderator', async function () {
368 const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER }) 371 const fields = { ...baseCorrectParams, username: 'a4656', email: 'a4656@example.com', role: UserRole.USER }
369 372
370 await makePostBodyRequest({ 373 await makePostBodyRequest({
371 url: server.url, 374 url: server.url,
@@ -937,19 +940,19 @@ describe('Test users API validators', function () {
937 } 940 }
938 941
939 it('Should fail with a too small username', async function () { 942 it('Should fail with a too small username', async function () {
940 const fields = immutableAssign(baseCorrectParams, { username: '' }) 943 const fields = { ...baseCorrectParams, username: '' }
941 944
942 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 945 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
943 }) 946 })
944 947
945 it('Should fail with a too long username', async function () { 948 it('Should fail with a too long username', async function () {
946 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) 949 const fields = { ...baseCorrectParams, username: 'super'.repeat(50) }
947 950
948 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 951 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
949 }) 952 })
950 953
951 it('Should fail with an incorrect username', async function () { 954 it('Should fail with an incorrect username', async function () {
952 const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) 955 const fields = { ...baseCorrectParams, username: 'my username' }
953 956
954 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 957 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
955 }) 958 })
@@ -961,25 +964,25 @@ describe('Test users API validators', function () {
961 }) 964 })
962 965
963 it('Should fail with an invalid email', async function () { 966 it('Should fail with an invalid email', async function () {
964 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) 967 const fields = { ...baseCorrectParams, email: 'test_example.com' }
965 968
966 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 969 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
967 }) 970 })
968 971
969 it('Should fail with a too small password', async function () { 972 it('Should fail with a too small password', async function () {
970 const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) 973 const fields = { ...baseCorrectParams, password: 'bla' }
971 974
972 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 975 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
973 }) 976 })
974 977
975 it('Should fail with a too long password', async function () { 978 it('Should fail with a too long password', async function () {
976 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) 979 const fields = { ...baseCorrectParams, password: 'super'.repeat(61) }
977 980
978 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 981 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
979 }) 982 })
980 983
981 it('Should fail if we register a user with the same username', async function () { 984 it('Should fail if we register a user with the same username', async function () {
982 const fields = immutableAssign(baseCorrectParams, { username: 'root' }) 985 const fields = { ...baseCorrectParams, username: 'root' }
983 986
984 await makePostBodyRequest({ 987 await makePostBodyRequest({
985 url: server.url, 988 url: server.url,
@@ -991,7 +994,7 @@ describe('Test users API validators', function () {
991 }) 994 })
992 995
993 it('Should fail with a "peertube" username', async function () { 996 it('Should fail with a "peertube" username', async function () {
994 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) 997 const fields = { ...baseCorrectParams, username: 'peertube' }
995 998
996 await makePostBodyRequest({ 999 await makePostBodyRequest({
997 url: server.url, 1000 url: server.url,
@@ -1003,7 +1006,7 @@ describe('Test users API validators', function () {
1003 }) 1006 })
1004 1007
1005 it('Should fail if we register a user with the same email', async function () { 1008 it('Should fail if we register a user with the same email', async function () {
1006 const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' }) 1009 const fields = { ...baseCorrectParams, email: 'admin' + server.internalServerNumber + '@example.com' }
1007 1010
1008 await makePostBodyRequest({ 1011 await makePostBodyRequest({
1009 url: server.url, 1012 url: server.url,
@@ -1015,26 +1018,26 @@ describe('Test users API validators', function () {
1015 }) 1018 })
1016 1019
1017 it('Should fail with a bad display name', async function () { 1020 it('Should fail with a bad display name', async function () {
1018 const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) }) 1021 const fields = { ...baseCorrectParams, displayName: 'a'.repeat(150) }
1019 1022
1020 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 1023 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1021 }) 1024 })
1022 1025
1023 it('Should fail with a bad channel name', async function () { 1026 it('Should fail with a bad channel name', async function () {
1024 const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } }) 1027 const fields = { ...baseCorrectParams, channel: { name: '[]azf', displayName: 'toto' } }
1025 1028
1026 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 1029 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1027 }) 1030 })
1028 1031
1029 it('Should fail with a bad channel display name', async function () { 1032 it('Should fail with a bad channel display name', async function () {
1030 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } }) 1033 const fields = { ...baseCorrectParams, channel: { name: 'toto', displayName: '' } }
1031 1034
1032 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 1035 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1033 }) 1036 })
1034 1037
1035 it('Should fail with a channel name that is the same as username', async function () { 1038 it('Should fail with a channel name that is the same as username', async function () {
1036 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } } 1039 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
1037 const fields = immutableAssign(baseCorrectParams, source) 1040 const fields = { ...baseCorrectParams, ...source }
1038 1041
1039 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 1042 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1040 }) 1043 })
@@ -1043,7 +1046,7 @@ describe('Test users API validators', function () {
1043 const attributes = { name: 'existing_channel', displayName: 'hello', description: 'super description' } 1046 const attributes = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
1044 await server.channelsCommand.create({ attributes }) 1047 await server.channelsCommand.create({ attributes })
1045 1048
1046 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } }) 1049 const fields = { ...baseCorrectParams, channel: { name: 'existing_channel', displayName: 'toto' } }
1047 1050
1048 await makePostBodyRequest({ 1051 await makePostBodyRequest({
1049 url: server.url, 1052 url: server.url,
@@ -1055,7 +1058,7 @@ describe('Test users API validators', function () {
1055 }) 1058 })
1056 1059
1057 it('Should succeed with the correct params', async function () { 1060 it('Should succeed with the correct params', async function () {
1058 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } }) 1061 const fields = { ...baseCorrectParams, channel: { name: 'super_channel', displayName: 'toto' } }
1059 1062
1060 await makePostBodyRequest({ 1063 await makePostBodyRequest({
1061 url: server.url, 1064 url: server.url,