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.ts61
1 files changed, 54 insertions, 7 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index 5d5af284c..4d597f0a3 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -1,4 +1,4 @@
1/* tslint:disable:no-unused-expression */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import { omit } from 'lodash' 3import { omit } from 'lodash'
4import 'mocha' 4import 'mocha'
@@ -16,12 +16,14 @@ import {
16 getMyUserVideoRating, 16 getMyUserVideoRating,
17 getUsersList, 17 getUsersList,
18 immutableAssign, 18 immutableAssign,
19 killallServers,
19 makeGetRequest, 20 makeGetRequest,
20 makePostBodyRequest, 21 makePostBodyRequest,
21 makePutBodyRequest, 22 makePutBodyRequest,
22 makeUploadRequest, 23 makeUploadRequest,
23 registerUser, 24 registerUser,
24 removeUser, 25 removeUser,
26 reRunServer,
25 ServerInfo, 27 ServerInfo,
26 setAccessTokensToServers, 28 setAccessTokensToServers,
27 unblockUser, 29 unblockUser,
@@ -39,6 +41,7 @@ import { VideoPrivacy } from '../../../../shared/models/videos'
39import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 41import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
40import { expect } from 'chai' 42import { expect } from 'chai'
41import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' 43import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
44import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
42 45
43describe('Test users API validators', function () { 46describe('Test users API validators', function () {
44 const path = '/api/v1/users/' 47 const path = '/api/v1/users/'
@@ -50,6 +53,9 @@ describe('Test users API validators', function () {
50 let serverWithRegistrationDisabled: ServerInfo 53 let serverWithRegistrationDisabled: ServerInfo
51 let userAccessToken = '' 54 let userAccessToken = ''
52 let moderatorAccessToken = '' 55 let moderatorAccessToken = ''
56 let emailPort: number
57 let overrideConfig: Object
58 // eslint-disable-next-line @typescript-eslint/no-unused-vars
53 let channelId: number 59 let channelId: number
54 60
55 // --------------------------------------------------------------- 61 // ---------------------------------------------------------------
@@ -57,9 +63,14 @@ describe('Test users API validators', function () {
57 before(async function () { 63 before(async function () {
58 this.timeout(30000) 64 this.timeout(30000)
59 65
66 const emails: object[] = []
67 emailPort = await MockSmtpServer.Instance.collectEmails(emails)
68
69 overrideConfig = { signup: { limit: 8 } }
70
60 { 71 {
61 const res = await Promise.all([ 72 const res = await Promise.all([
62 flushAndRunServer(1, { signup: { limit: 7 } }), 73 flushAndRunServer(1, overrideConfig),
63 flushAndRunServer(2) 74 flushAndRunServer(2)
64 ]) 75 ])
65 76
@@ -120,7 +131,7 @@ describe('Test users API validators', function () {
120 131
121 { 132 {
122 const res = await getMyUserInformation(server.url, server.accessToken) 133 const res = await getMyUserInformation(server.url, server.accessToken)
123 channelId = res.body.videoChannels[ 0 ].id 134 channelId = res.body.videoChannels[0].id
124 } 135 }
125 136
126 { 137 {
@@ -228,6 +239,40 @@ describe('Test users API validators', function () {
228 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 239 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
229 }) 240 })
230 241
242 it('Should fail with empty password and no smtp configured', async function () {
243 const fields = immutableAssign(baseCorrectParams, { password: '' })
244
245 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
246 })
247
248 it('Should succeed with no password on a server with smtp enabled', async function () {
249 this.timeout(10000)
250
251 killallServers([ server ])
252
253 const config = immutableAssign(overrideConfig, {
254 smtp: {
255 hostname: 'localhost',
256 port: emailPort
257 }
258 })
259 await reRunServer(server, config)
260
261 const fields = immutableAssign(baseCorrectParams, {
262 password: '',
263 username: 'create_password',
264 email: 'create_password@example.com'
265 })
266
267 await makePostBodyRequest({
268 url: server.url,
269 path: path,
270 token: server.accessToken,
271 fields,
272 statusCodeExpected: 200
273 })
274 })
275
231 it('Should fail with invalid admin flags', async function () { 276 it('Should fail with invalid admin flags', async function () {
232 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' }) 277 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
233 278
@@ -529,7 +574,7 @@ describe('Test users API validators', function () {
529 it('Should fail without an incorrect input file', async function () { 574 it('Should fail without an incorrect input file', async function () {
530 const fields = {} 575 const fields = {}
531 const attaches = { 576 const attaches = {
532 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') 577 avatarfile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
533 } 578 }
534 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) 579 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
535 }) 580 })
@@ -537,7 +582,7 @@ describe('Test users API validators', function () {
537 it('Should fail with a big file', async function () { 582 it('Should fail with a big file', async function () {
538 const fields = {} 583 const fields = {}
539 const attaches = { 584 const attaches = {
540 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') 585 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
541 } 586 }
542 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches }) 587 await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
543 }) 588 })
@@ -545,7 +590,7 @@ describe('Test users API validators', function () {
545 it('Should fail with an unauthenticated user', async function () { 590 it('Should fail with an unauthenticated user', async function () {
546 const fields = {} 591 const fields = {}
547 const attaches = { 592 const attaches = {
548 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') 593 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
549 } 594 }
550 await makeUploadRequest({ 595 await makeUploadRequest({
551 url: server.url, 596 url: server.url,
@@ -559,7 +604,7 @@ describe('Test users API validators', function () {
559 it('Should succeed with the correct params', async function () { 604 it('Should succeed with the correct params', async function () {
560 const fields = {} 605 const fields = {}
561 const attaches = { 606 const attaches = {
562 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') 607 avatarfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
563 } 608 }
564 await makeUploadRequest({ 609 await makeUploadRequest({
565 url: server.url, 610 url: server.url,
@@ -1101,6 +1146,8 @@ describe('Test users API validators', function () {
1101 }) 1146 })
1102 1147
1103 after(async function () { 1148 after(async function () {
1149 MockSmtpServer.Instance.kill()
1150
1104 await cleanupTests([ server, serverWithRegistrationDisabled ]) 1151 await cleanupTests([ server, serverWithRegistrationDisabled ])
1105 }) 1152 })
1106}) 1153})