aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/users.ts48
-rw-r--r--server/tests/api/server/email.ts76
2 files changed, 111 insertions, 13 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index f448bb2a6..4d597f0a3 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -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,8 @@ 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
53 // eslint-disable-next-line @typescript-eslint/no-unused-vars 58 // eslint-disable-next-line @typescript-eslint/no-unused-vars
54 let channelId: number 59 let channelId: number
55 60
@@ -58,9 +63,14 @@ describe('Test users API validators', function () {
58 before(async function () { 63 before(async function () {
59 this.timeout(30000) 64 this.timeout(30000)
60 65
66 const emails: object[] = []
67 emailPort = await MockSmtpServer.Instance.collectEmails(emails)
68
69 overrideConfig = { signup: { limit: 8 } }
70
61 { 71 {
62 const res = await Promise.all([ 72 const res = await Promise.all([
63 flushAndRunServer(1, { signup: { limit: 7 } }), 73 flushAndRunServer(1, overrideConfig),
64 flushAndRunServer(2) 74 flushAndRunServer(2)
65 ]) 75 ])
66 76
@@ -229,6 +239,40 @@ describe('Test users API validators', function () {
229 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 239 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
230 }) 240 })
231 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
232 it('Should fail with invalid admin flags', async function () { 276 it('Should fail with invalid admin flags', async function () {
233 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' }) 277 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
234 278
@@ -1102,6 +1146,8 @@ describe('Test users API validators', function () {
1102 }) 1146 })
1103 1147
1104 after(async function () { 1148 after(async function () {
1149 MockSmtpServer.Instance.kill()
1150
1105 await cleanupTests([ server, serverWithRegistrationDisabled ]) 1151 await cleanupTests([ server, serverWithRegistrationDisabled ])
1106 }) 1152 })
1107}) 1153})
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts
index f18859e5d..95b64a459 100644
--- a/server/tests/api/server/email.ts
+++ b/server/tests/api/server/email.ts
@@ -28,10 +28,12 @@ const expect = chai.expect
28describe('Test emails', function () { 28describe('Test emails', function () {
29 let server: ServerInfo 29 let server: ServerInfo
30 let userId: number 30 let userId: number
31 let userId2: number
31 let userAccessToken: string 32 let userAccessToken: string
32 let videoUUID: string 33 let videoUUID: string
33 let videoUserUUID: string 34 let videoUserUUID: string
34 let verificationString: string 35 let verificationString: string
36 let verificationString2: string
35 const emails: object[] = [] 37 const emails: object[] = []
36 const user = { 38 const user = {
37 username: 'user_1', 39 username: 'user_1',
@@ -122,6 +124,56 @@ describe('Test emails', function () {
122 }) 124 })
123 }) 125 })
124 126
127 describe('When creating a user without password', function () {
128 it('Should send a create password email', async function () {
129 this.timeout(10000)
130
131 await createUser({
132 url: server.url,
133 accessToken: server.accessToken,
134 username: 'create_password',
135 password: ''
136 })
137
138 await waitJobs(server)
139 expect(emails).to.have.lengthOf(2)
140
141 const email = emails[1]
142
143 expect(email['from'][0]['name']).equal('localhost:' + server.port)
144 expect(email['from'][0]['address']).equal('test-admin@localhost')
145 expect(email['to'][0]['address']).equal('create_password@example.com')
146 expect(email['subject']).contains('account')
147 expect(email['subject']).contains('password')
148
149 const verificationStringMatches = /verificationString=([a-z0-9]+)/.exec(email['text'])
150 expect(verificationStringMatches).not.to.be.null
151
152 verificationString2 = verificationStringMatches[1]
153 expect(verificationString2).to.have.length.above(2)
154
155 const userIdMatches = /userId=([0-9]+)/.exec(email['text'])
156 expect(userIdMatches).not.to.be.null
157
158 userId2 = parseInt(userIdMatches[1], 10)
159 })
160
161 it('Should not reset the password with an invalid verification string', async function () {
162 await resetPassword(server.url, userId2, verificationString2 + 'c', 'newly_created_password', 403)
163 })
164
165 it('Should reset the password', async function () {
166 await resetPassword(server.url, userId2, verificationString2, 'newly_created_password')
167 })
168
169 it('Should login with this new password', async function () {
170 await userLogin(server, {
171 username: 'create_password',
172 password: 'newly_created_password'
173 })
174 })
175 })
176
125 describe('When creating a video abuse', function () { 177 describe('When creating a video abuse', function () {
126 it('Should send the notification email', async function () { 178 it('Should send the notification email', async function () {
127 this.timeout(10000) 179 this.timeout(10000)
@@ -130,9 +182,9 @@ describe('Test emails', function () {
130 await reportVideoAbuse(server.url, server.accessToken, videoUUID, reason) 182 await reportVideoAbuse(server.url, server.accessToken, videoUUID, reason)
131 183
132 await waitJobs(server) 184 await waitJobs(server)
133 expect(emails).to.have.lengthOf(2) 185 expect(emails).to.have.lengthOf(3)
134 186
135 const email = emails[1] 187 const email = emails[2]
136 188
137 expect(email['from'][0]['name']).equal('localhost:' + server.port) 189 expect(email['from'][0]['name']).equal('localhost:' + server.port)
138 expect(email['from'][0]['address']).equal('test-admin@localhost') 190 expect(email['from'][0]['address']).equal('test-admin@localhost')
@@ -151,9 +203,9 @@ describe('Test emails', function () {
151 await blockUser(server.url, userId, server.accessToken, 204, reason) 203 await blockUser(server.url, userId, server.accessToken, 204, reason)
152 204
153 await waitJobs(server) 205 await waitJobs(server)
154 expect(emails).to.have.lengthOf(3) 206 expect(emails).to.have.lengthOf(4)
155 207
156 const email = emails[2] 208 const email = emails[3]
157 209
158 expect(email['from'][0]['name']).equal('localhost:' + server.port) 210 expect(email['from'][0]['name']).equal('localhost:' + server.port)
159 expect(email['from'][0]['address']).equal('test-admin@localhost') 211 expect(email['from'][0]['address']).equal('test-admin@localhost')
@@ -169,9 +221,9 @@ describe('Test emails', function () {
169 await unblockUser(server.url, userId, server.accessToken, 204) 221 await unblockUser(server.url, userId, server.accessToken, 204)
170 222
171 await waitJobs(server) 223 await waitJobs(server)
172 expect(emails).to.have.lengthOf(4) 224 expect(emails).to.have.lengthOf(5)
173 225
174 const email = emails[3] 226 const email = emails[4]
175 227
176 expect(email['from'][0]['name']).equal('localhost:' + server.port) 228 expect(email['from'][0]['name']).equal('localhost:' + server.port)
177 expect(email['from'][0]['address']).equal('test-admin@localhost') 229 expect(email['from'][0]['address']).equal('test-admin@localhost')
@@ -189,9 +241,9 @@ describe('Test emails', function () {
189 await addVideoToBlacklist(server.url, server.accessToken, videoUserUUID, reason) 241 await addVideoToBlacklist(server.url, server.accessToken, videoUserUUID, reason)
190 242
191 await waitJobs(server) 243 await waitJobs(server)
192 expect(emails).to.have.lengthOf(5) 244 expect(emails).to.have.lengthOf(6)
193 245
194 const email = emails[4] 246 const email = emails[5]
195 247
196 expect(email['from'][0]['name']).equal('localhost:' + server.port) 248 expect(email['from'][0]['name']).equal('localhost:' + server.port)
197 expect(email['from'][0]['address']).equal('test-admin@localhost') 249 expect(email['from'][0]['address']).equal('test-admin@localhost')
@@ -207,9 +259,9 @@ describe('Test emails', function () {
207 await removeVideoFromBlacklist(server.url, server.accessToken, videoUserUUID) 259 await removeVideoFromBlacklist(server.url, server.accessToken, videoUserUUID)
208 260
209 await waitJobs(server) 261 await waitJobs(server)
210 expect(emails).to.have.lengthOf(6) 262 expect(emails).to.have.lengthOf(7)
211 263
212 const email = emails[5] 264 const email = emails[6]
213 265
214 expect(email['from'][0]['name']).equal('localhost:' + server.port) 266 expect(email['from'][0]['name']).equal('localhost:' + server.port)
215 expect(email['from'][0]['address']).equal('test-admin@localhost') 267 expect(email['from'][0]['address']).equal('test-admin@localhost')
@@ -227,9 +279,9 @@ describe('Test emails', function () {
227 await askSendVerifyEmail(server.url, 'user_1@example.com') 279 await askSendVerifyEmail(server.url, 'user_1@example.com')
228 280
229 await waitJobs(server) 281 await waitJobs(server)
230 expect(emails).to.have.lengthOf(7) 282 expect(emails).to.have.lengthOf(8)
231 283
232 const email = emails[6] 284 const email = emails[7]
233 285
234 expect(email['from'][0]['name']).equal('localhost:' + server.port) 286 expect(email['from'][0]['name']).equal('localhost:' + server.port)
235 expect(email['from'][0]['address']).equal('test-admin@localhost') 287 expect(email['from'][0]['address']).equal('test-admin@localhost')