aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/users/users-verification.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
committerChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
commita24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch)
treea54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tests/api/users/users-verification.ts
parent5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff)
parentc63830f15403ac4e750829f27d8bbbdc9a59282c (diff)
downloadPeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip
Merge branch 'next' into develop
Diffstat (limited to 'server/tests/api/users/users-verification.ts')
-rw-r--r--server/tests/api/users/users-verification.ts107
1 files changed, 46 insertions, 61 deletions
diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts
index e0f2f2112..f54463359 100644
--- a/server/tests/api/users/users-verification.ts
+++ b/server/tests/api/users/users-verification.ts
@@ -1,30 +1,14 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
5import { 4import * as chai from 'chai'
6 cleanupTests, 5import { cleanupTests, createSingleServer, MockSmtpServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
7 flushAndRunServer, 6import { HttpStatusCode } from '@shared/models'
8 getMyUserInformation,
9 getUserInformation,
10 login,
11 registerUser,
12 ServerInfo,
13 updateCustomSubConfig,
14 updateMyUser,
15 userLogin,
16 verifyEmail
17} from '../../../../shared/extra-utils'
18import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
19import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
20import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
21import { User } from '../../../../shared/models/users'
22import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
23 7
24const expect = chai.expect 8const expect = chai.expect
25 9
26describe('Test users account verification', function () { 10describe('Test users account verification', function () {
27 let server: ServerInfo 11 let server: PeerTubeServer
28 let userId: number 12 let userId: number
29 let userAccessToken: string 13 let userAccessToken: string
30 let verificationString: string 14 let verificationString: string
@@ -50,7 +34,7 @@ describe('Test users account verification', function () {
50 port 34 port
51 } 35 }
52 } 36 }
53 server = await flushAndRunServer(1, overrideConfig) 37 server = await createSingleServer(1, overrideConfig)
54 38
55 await setAccessTokensToServers([ server ]) 39 await setAccessTokensToServers([ server ])
56 }) 40 })
@@ -58,15 +42,17 @@ describe('Test users account verification', function () {
58 it('Should register user and send verification email if verification required', async function () { 42 it('Should register user and send verification email if verification required', async function () {
59 this.timeout(30000) 43 this.timeout(30000)
60 44
61 await updateCustomSubConfig(server.url, server.accessToken, { 45 await server.config.updateCustomSubConfig({
62 signup: { 46 newConfig: {
63 enabled: true, 47 signup: {
64 requiresEmailVerification: true, 48 enabled: true,
65 limit: 10 49 requiresEmailVerification: true,
50 limit: 10
51 }
66 } 52 }
67 }) 53 })
68 54
69 await registerUser(server.url, user1.username, user1.password) 55 await server.users.register(user1)
70 56
71 await waitJobs(server) 57 await waitJobs(server)
72 expectedEmailsLength++ 58 expectedEmailsLength++
@@ -85,23 +71,23 @@ describe('Test users account verification', function () {
85 71
86 userId = parseInt(userIdMatches[1], 10) 72 userId = parseInt(userIdMatches[1], 10)
87 73
88 const resUserInfo = await getUserInformation(server.url, server.accessToken, userId) 74 const body = await server.users.get({ userId })
89 expect(resUserInfo.body.emailVerified).to.be.false 75 expect(body.emailVerified).to.be.false
90 }) 76 })
91 77
92 it('Should not allow login for user with unverified email', async function () { 78 it('Should not allow login for user with unverified email', async function () {
93 const resLogin = await login(server.url, server.client, user1, HttpStatusCode.BAD_REQUEST_400) 79 const { detail } = await server.login.login({ user: user1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
94 expect(resLogin.body.detail).to.contain('User email is not verified.') 80 expect(detail).to.contain('User email is not verified.')
95 }) 81 })
96 82
97 it('Should verify the user via email and allow login', async function () { 83 it('Should verify the user via email and allow login', async function () {
98 await verifyEmail(server.url, userId, verificationString) 84 await server.users.verifyEmail({ userId, verificationString })
99 85
100 const res = await login(server.url, server.client, user1) 86 const body = await server.login.login({ user: user1 })
101 userAccessToken = res.body.access_token 87 userAccessToken = body.access_token
102 88
103 const resUserVerified = await getUserInformation(server.url, server.accessToken, userId) 89 const user = await server.users.get({ userId })
104 expect(resUserVerified.body.emailVerified).to.be.true 90 expect(user.emailVerified).to.be.true
105 }) 91 })
106 92
107 it('Should be able to change the user email', async function () { 93 it('Should be able to change the user email', async function () {
@@ -110,9 +96,8 @@ describe('Test users account verification', function () {
110 let updateVerificationString: string 96 let updateVerificationString: string
111 97
112 { 98 {
113 await updateMyUser({ 99 await server.users.updateMe({
114 url: server.url, 100 token: userAccessToken,
115 accessToken: userAccessToken,
116 email: 'updated@example.com', 101 email: 'updated@example.com',
117 currentPassword: user1.password 102 currentPassword: user1.password
118 }) 103 })
@@ -128,19 +113,15 @@ describe('Test users account verification', function () {
128 } 113 }
129 114
130 { 115 {
131 const res = await getMyUserInformation(server.url, userAccessToken) 116 const me = await server.users.getMyInfo({ token: userAccessToken })
132 const me: User = res.body
133
134 expect(me.email).to.equal('user_1@example.com') 117 expect(me.email).to.equal('user_1@example.com')
135 expect(me.pendingEmail).to.equal('updated@example.com') 118 expect(me.pendingEmail).to.equal('updated@example.com')
136 } 119 }
137 120
138 { 121 {
139 await verifyEmail(server.url, userId, updateVerificationString, true) 122 await server.users.verifyEmail({ userId, verificationString: updateVerificationString, isPendingEmail: true })
140
141 const res = await getMyUserInformation(server.url, userAccessToken)
142 const me: User = res.body
143 123
124 const me = await server.users.getMyInfo({ token: userAccessToken })
144 expect(me.email).to.equal('updated@example.com') 125 expect(me.email).to.equal('updated@example.com')
145 expect(me.pendingEmail).to.be.null 126 expect(me.pendingEmail).to.be.null
146 } 127 }
@@ -148,35 +129,39 @@ describe('Test users account verification', function () {
148 129
149 it('Should register user not requiring email verification if setting not enabled', async function () { 130 it('Should register user not requiring email verification if setting not enabled', async function () {
150 this.timeout(5000) 131 this.timeout(5000)
151 await updateCustomSubConfig(server.url, server.accessToken, { 132 await server.config.updateCustomSubConfig({
152 signup: { 133 newConfig: {
153 enabled: true, 134 signup: {
154 requiresEmailVerification: false, 135 enabled: true,
155 limit: 10 136 requiresEmailVerification: false,
137 limit: 10
138 }
156 } 139 }
157 }) 140 })
158 141
159 await registerUser(server.url, user2.username, user2.password) 142 await server.users.register(user2)
160 143
161 await waitJobs(server) 144 await waitJobs(server)
162 expect(emails).to.have.lengthOf(expectedEmailsLength) 145 expect(emails).to.have.lengthOf(expectedEmailsLength)
163 146
164 const accessToken = await userLogin(server, user2) 147 const accessToken = await server.login.getAccessToken(user2)
165 148
166 const resMyUserInfo = await getMyUserInformation(server.url, accessToken) 149 const user = await server.users.getMyInfo({ token: accessToken })
167 expect(resMyUserInfo.body.emailVerified).to.be.null 150 expect(user.emailVerified).to.be.null
168 }) 151 })
169 152
170 it('Should allow login for user with unverified email when setting later enabled', async function () { 153 it('Should allow login for user with unverified email when setting later enabled', async function () {
171 await updateCustomSubConfig(server.url, server.accessToken, { 154 await server.config.updateCustomSubConfig({
172 signup: { 155 newConfig: {
173 enabled: true, 156 signup: {
174 requiresEmailVerification: true, 157 enabled: true,
175 limit: 10 158 requiresEmailVerification: true,
159 limit: 10
160 }
176 } 161 }
177 }) 162 })
178 163
179 await userLogin(server, user2) 164 await server.login.getAccessToken(user2)
180 }) 165 })
181 166
182 after(async function () { 167 after(async function () {