aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/users/users-verification.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/users/users-verification.ts')
-rw-r--r--server/tests/api/users/users-verification.ts65
1 files changed, 60 insertions, 5 deletions
diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts
index 514acf2e7..7cd61f539 100644
--- a/server/tests/api/users/users-verification.ts
+++ b/server/tests/api/users/users-verification.ts
@@ -3,18 +3,29 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 registerUser, flushTests, getUserInformation, getMyUserInformation, killallServers, 6 cleanupTests,
7 userLogin, login, flushAndRunServer, ServerInfo, verifyEmail, updateCustomSubConfig, wait, cleanupTests 7 flushAndRunServer,
8 getMyUserInformation,
9 getUserInformation,
10 login,
11 registerUser,
12 ServerInfo,
13 updateCustomSubConfig,
14 updateMyUser,
15 userLogin,
16 verifyEmail
8} from '../../../../shared/extra-utils' 17} from '../../../../shared/extra-utils'
9import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' 18import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
10import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' 19import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
11import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 20import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
21import { User } from '../../../../shared/models/users'
12 22
13const expect = chai.expect 23const expect = chai.expect
14 24
15describe('Test users account verification', function () { 25describe('Test users account verification', function () {
16 let server: ServerInfo 26 let server: ServerInfo
17 let userId: number 27 let userId: number
28 let userAccessToken: string
18 let verificationString: string 29 let verificationString: string
19 let expectedEmailsLength = 0 30 let expectedEmailsLength = 0
20 const user1 = { 31 const user1 = {
@@ -30,11 +41,12 @@ describe('Test users account verification', function () {
30 before(async function () { 41 before(async function () {
31 this.timeout(30000) 42 this.timeout(30000)
32 43
33 await MockSmtpServer.Instance.collectEmails(emails) 44 const port = await MockSmtpServer.Instance.collectEmails(emails)
34 45
35 const overrideConfig = { 46 const overrideConfig = {
36 smtp: { 47 smtp: {
37 hostname: 'localhost' 48 hostname: 'localhost',
49 port
38 } 50 }
39 } 51 }
40 server = await flushAndRunServer(1, overrideConfig) 52 server = await flushAndRunServer(1, overrideConfig)
@@ -82,11 +94,54 @@ describe('Test users account verification', function () {
82 94
83 it('Should verify the user via email and allow login', async function () { 95 it('Should verify the user via email and allow login', async function () {
84 await verifyEmail(server.url, userId, verificationString) 96 await verifyEmail(server.url, userId, verificationString)
85 await login(server.url, server.client, user1) 97
98 const res = await login(server.url, server.client, user1)
99 userAccessToken = res.body.access_token
100
86 const resUserVerified = await getUserInformation(server.url, server.accessToken, userId) 101 const resUserVerified = await getUserInformation(server.url, server.accessToken, userId)
87 expect(resUserVerified.body.emailVerified).to.be.true 102 expect(resUserVerified.body.emailVerified).to.be.true
88 }) 103 })
89 104
105 it('Should be able to change the user email', async function () {
106 let updateVerificationString: string
107
108 {
109 await updateMyUser({
110 url: server.url,
111 accessToken: userAccessToken,
112 email: 'updated@example.com',
113 currentPassword: user1.password
114 })
115
116 await waitJobs(server)
117 expectedEmailsLength++
118 expect(emails).to.have.lengthOf(expectedEmailsLength)
119
120 const email = emails[expectedEmailsLength - 1]
121
122 const verificationStringMatches = /verificationString=([a-z0-9]+)/.exec(email['text'])
123 updateVerificationString = verificationStringMatches[1]
124 }
125
126 {
127 const res = await getMyUserInformation(server.url, userAccessToken)
128 const me: User = res.body
129
130 expect(me.email).to.equal('user_1@example.com')
131 expect(me.pendingEmail).to.equal('updated@example.com')
132 }
133
134 {
135 await verifyEmail(server.url, userId, updateVerificationString, true)
136
137 const res = await getMyUserInformation(server.url, userAccessToken)
138 const me: User = res.body
139
140 expect(me.email).to.equal('updated@example.com')
141 expect(me.pendingEmail).to.be.null
142 }
143 })
144
90 it('Should register user not requiring email verification if setting not enabled', async function () { 145 it('Should register user not requiring email verification if setting not enabled', async function () {
91 this.timeout(5000) 146 this.timeout(5000)
92 await updateCustomSubConfig(server.url, server.accessToken, { 147 await updateCustomSubConfig(server.url, server.accessToken, {