From 45f1bd72a08998c60a9dd68ff069cea9de39161c Mon Sep 17 00:00:00 2001 From: John Livingston <38844060+JohnXLivingston@users.noreply.github.com> Date: Mon, 17 Feb 2020 10:16:52 +0100 Subject: Creating a user with an empty password will send an email to let him set his password (#2479) * Creating a user with an empty password will send an email to let him set his password * Consideration of Chocobozzz's comments * Tips for optional password * API documentation * Fix circular imports * Tests --- server/tests/api/check-params/users.ts | 48 +++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'server/tests/api/check-params/users.ts') 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 { getMyUserVideoRating, getUsersList, immutableAssign, + killallServers, makeGetRequest, makePostBodyRequest, makePutBodyRequest, makeUploadRequest, registerUser, removeUser, + reRunServer, ServerInfo, setAccessTokensToServers, unblockUser, @@ -39,6 +41,7 @@ import { VideoPrivacy } from '../../../../shared/models/videos' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { expect } from 'chai' import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' +import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' describe('Test users API validators', function () { const path = '/api/v1/users/' @@ -50,6 +53,8 @@ describe('Test users API validators', function () { let serverWithRegistrationDisabled: ServerInfo let userAccessToken = '' let moderatorAccessToken = '' + let emailPort: number + let overrideConfig: Object // eslint-disable-next-line @typescript-eslint/no-unused-vars let channelId: number @@ -58,9 +63,14 @@ describe('Test users API validators', function () { before(async function () { this.timeout(30000) + const emails: object[] = [] + emailPort = await MockSmtpServer.Instance.collectEmails(emails) + + overrideConfig = { signup: { limit: 8 } } + { const res = await Promise.all([ - flushAndRunServer(1, { signup: { limit: 7 } }), + flushAndRunServer(1, overrideConfig), flushAndRunServer(2) ]) @@ -229,6 +239,40 @@ describe('Test users API validators', function () { await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) + it('Should fail with empty password and no smtp configured', async function () { + const fields = immutableAssign(baseCorrectParams, { password: '' }) + + await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) + }) + + it('Should succeed with no password on a server with smtp enabled', async function () { + this.timeout(10000) + + killallServers([ server ]) + + const config = immutableAssign(overrideConfig, { + smtp: { + hostname: 'localhost', + port: emailPort + } + }) + await reRunServer(server, config) + + const fields = immutableAssign(baseCorrectParams, { + password: '', + username: 'create_password', + email: 'create_password@example.com' + }) + + await makePostBodyRequest({ + url: server.url, + path: path, + token: server.accessToken, + fields, + statusCodeExpected: 200 + }) + }) + it('Should fail with invalid admin flags', async function () { const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' }) @@ -1102,6 +1146,8 @@ describe('Test users API validators', function () { }) after(async function () { + MockSmtpServer.Instance.kill() + await cleanupTests([ server, serverWithRegistrationDisabled ]) }) }) -- cgit v1.2.3