aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-13 14:23:01 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commit7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 (patch)
tree7a166515e4d57a06eb3c08be569f106ed049988b /server/tests/plugins
parentd0a0fa429d4651710ed951a3c11af0219e408964 (diff)
downloadPeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.gz
PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.zst
PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.zip
Introduce user command
Diffstat (limited to 'server/tests/plugins')
-rw-r--r--server/tests/plugins/action-hooks.ts41
-rw-r--r--server/tests/plugins/external-auth.ts49
-rw-r--r--server/tests/plugins/filter-hooks.ts9
-rw-r--r--server/tests/plugins/id-and-pass-auth.ts53
4 files changed, 52 insertions, 100 deletions
diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts
index 84f4e8501..b156f6b60 100644
--- a/server/tests/plugins/action-hooks.ts
+++ b/server/tests/plugins/action-hooks.ts
@@ -1,28 +1,20 @@
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 'mocha' 3import 'mocha'
4import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
5import { 4import {
6 blockUser, 5 cleanupTests,
7 createUser, 6 flushAndRunMultipleServers,
7 killallServers,
8 PluginsCommand, 8 PluginsCommand,
9 registerUser, 9 reRunServer,
10 removeUser, 10 ServerInfo,
11 setAccessTokensToServers, 11 setAccessTokensToServers,
12 setDefaultVideoChannel, 12 setDefaultVideoChannel,
13 unblockUser,
14 updateUser,
15 updateVideo, 13 updateVideo,
16 uploadVideo, 14 uploadVideo,
17 viewVideo 15 viewVideo
18} from '../../../shared/extra-utils' 16} from '@shared/extra-utils'
19import { 17import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
20 cleanupTests,
21 flushAndRunMultipleServers,
22 killallServers,
23 reRunServer,
24 ServerInfo
25} from '../../../shared/extra-utils/server/servers'
26 18
27describe('Test plugin action hooks', function () { 19describe('Test plugin action hooks', function () {
28 let servers: ServerInfo[] 20 let servers: ServerInfo[]
@@ -119,19 +111,14 @@ describe('Test plugin action hooks', function () {
119 let userId: number 111 let userId: number
120 112
121 it('Should run action:api.user.registered', async function () { 113 it('Should run action:api.user.registered', async function () {
122 await registerUser(servers[0].url, 'registered_user', 'super_password') 114 await servers[0].usersCommand.register({ username: 'registered_user' })
123 115
124 await checkHook('action:api.user.registered') 116 await checkHook('action:api.user.registered')
125 }) 117 })
126 118
127 it('Should run action:api.user.created', async function () { 119 it('Should run action:api.user.created', async function () {
128 const res = await createUser({ 120 const user = await servers[0].usersCommand.create({ username: 'created_user' })
129 url: servers[0].url, 121 userId = user.id
130 accessToken: servers[0].accessToken,
131 username: 'created_user',
132 password: 'super_password'
133 })
134 userId = res.body.user.id
135 122
136 await checkHook('action:api.user.created') 123 await checkHook('action:api.user.created')
137 }) 124 })
@@ -143,25 +130,25 @@ describe('Test plugin action hooks', function () {
143 }) 130 })
144 131
145 it('Should run action:api.user.blocked', async function () { 132 it('Should run action:api.user.blocked', async function () {
146 await blockUser(servers[0].url, userId, servers[0].accessToken) 133 await servers[0].usersCommand.banUser({ userId })
147 134
148 await checkHook('action:api.user.blocked') 135 await checkHook('action:api.user.blocked')
149 }) 136 })
150 137
151 it('Should run action:api.user.unblocked', async function () { 138 it('Should run action:api.user.unblocked', async function () {
152 await unblockUser(servers[0].url, userId, servers[0].accessToken) 139 await servers[0].usersCommand.unbanUser({ userId })
153 140
154 await checkHook('action:api.user.unblocked') 141 await checkHook('action:api.user.unblocked')
155 }) 142 })
156 143
157 it('Should run action:api.user.updated', async function () { 144 it('Should run action:api.user.updated', async function () {
158 await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 }) 145 await servers[0].usersCommand.update({ userId, videoQuota: 50 })
159 146
160 await checkHook('action:api.user.updated') 147 await checkHook('action:api.user.updated')
161 }) 148 })
162 149
163 it('Should run action:api.user.deleted', async function () { 150 it('Should run action:api.user.deleted', async function () {
164 await removeUser(servers[0].url, userId, servers[0].accessToken) 151 await servers[0].usersCommand.remove({ userId })
165 152
166 await checkHook('action:api.user.deleted') 153 await checkHook('action:api.user.deleted')
167 }) 154 })
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts
index e421fd224..3e8305611 100644
--- a/server/tests/plugins/external-auth.ts
+++ b/server/tests/plugins/external-auth.ts
@@ -5,17 +5,14 @@ import { expect } from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 createUser,
9 decodeQueryString, 8 decodeQueryString,
10 flushAndRunServer, 9 flushAndRunServer,
11 getMyUserInformation,
12 PluginsCommand, 10 PluginsCommand,
13 ServerInfo, 11 ServerInfo,
14 setAccessTokensToServers, 12 setAccessTokensToServers,
15 updateMyUser,
16 wait 13 wait
17} from '@shared/extra-utils' 14} from '@shared/extra-utils'
18import { User, UserRole } from '@shared/models' 15import { UserRole } from '@shared/models'
19 16
20async function loginExternal (options: { 17async function loginExternal (options: {
21 server: ServerInfo 18 server: ServerInfo
@@ -149,9 +146,7 @@ describe('Test external auth plugins', function () {
149 } 146 }
150 147
151 { 148 {
152 const res = await getMyUserInformation(server.url, cyanAccessToken) 149 const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
153
154 const body: User = res.body
155 expect(body.username).to.equal('cyan') 150 expect(body.username).to.equal('cyan')
156 expect(body.account.displayName).to.equal('cyan') 151 expect(body.account.displayName).to.equal('cyan')
157 expect(body.email).to.equal('cyan@example.com') 152 expect(body.email).to.equal('cyan@example.com')
@@ -173,9 +168,7 @@ describe('Test external auth plugins', function () {
173 } 168 }
174 169
175 { 170 {
176 const res = await getMyUserInformation(server.url, kefkaAccessToken) 171 const body = await server.usersCommand.getMyInfo({ token: kefkaAccessToken })
177
178 const body: User = res.body
179 expect(body.username).to.equal('kefka') 172 expect(body.username).to.equal('kefka')
180 expect(body.account.displayName).to.equal('Kefka Palazzo') 173 expect(body.account.displayName).to.equal('Kefka Palazzo')
181 expect(body.email).to.equal('kefka@example.com') 174 expect(body.email).to.equal('kefka@example.com')
@@ -189,9 +182,8 @@ describe('Test external auth plugins', function () {
189 cyanAccessToken = resRefresh.body.access_token 182 cyanAccessToken = resRefresh.body.access_token
190 cyanRefreshToken = resRefresh.body.refresh_token 183 cyanRefreshToken = resRefresh.body.refresh_token
191 184
192 const res = await getMyUserInformation(server.url, cyanAccessToken) 185 const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
193 const user: User = res.body 186 expect(body.username).to.equal('cyan')
194 expect(user.username).to.equal('cyan')
195 } 187 }
196 188
197 { 189 {
@@ -200,16 +192,13 @@ describe('Test external auth plugins', function () {
200 }) 192 })
201 193
202 it('Should update Cyan profile', async function () { 194 it('Should update Cyan profile', async function () {
203 await updateMyUser({ 195 await server.usersCommand.updateMe({
204 url: server.url, 196 token: cyanAccessToken,
205 accessToken: cyanAccessToken,
206 displayName: 'Cyan Garamonde', 197 displayName: 'Cyan Garamonde',
207 description: 'Retainer to the king of Doma' 198 description: 'Retainer to the king of Doma'
208 }) 199 })
209 200
210 const res = await getMyUserInformation(server.url, cyanAccessToken) 201 const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
211
212 const body: User = res.body
213 expect(body.account.displayName).to.equal('Cyan Garamonde') 202 expect(body.account.displayName).to.equal('Cyan Garamonde')
214 expect(body.account.description).to.equal('Retainer to the king of Doma') 203 expect(body.account.description).to.equal('Retainer to the king of Doma')
215 }) 204 })
@@ -221,7 +210,7 @@ describe('Test external auth plugins', function () {
221 it('Should have logged out Cyan', async function () { 210 it('Should have logged out Cyan', async function () {
222 await server.serversCommand.waitUntilLog('On logout cyan') 211 await server.serversCommand.waitUntilLog('On logout cyan')
223 212
224 await getMyUserInformation(server.url, cyanAccessToken, HttpStatusCode.UNAUTHORIZED_401) 213 await server.usersCommand.getMyInfo({ token: cyanAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
225 }) 214 })
226 215
227 it('Should login Cyan and keep the old existing profile', async function () { 216 it('Should login Cyan and keep the old existing profile', async function () {
@@ -239,9 +228,7 @@ describe('Test external auth plugins', function () {
239 cyanAccessToken = res.access_token 228 cyanAccessToken = res.access_token
240 } 229 }
241 230
242 const res = await getMyUserInformation(server.url, cyanAccessToken) 231 const body = await server.usersCommand.getMyInfo({ token: cyanAccessToken })
243
244 const body: User = res.body
245 expect(body.username).to.equal('cyan') 232 expect(body.username).to.equal('cyan')
246 expect(body.account.displayName).to.equal('Cyan Garamonde') 233 expect(body.account.displayName).to.equal('Cyan Garamonde')
247 expect(body.account.description).to.equal('Retainer to the king of Doma') 234 expect(body.account.description).to.equal('Retainer to the king of Doma')
@@ -249,12 +236,11 @@ describe('Test external auth plugins', function () {
249 }) 236 })
250 237
251 it('Should not update an external auth email', async function () { 238 it('Should not update an external auth email', async function () {
252 await updateMyUser({ 239 await server.usersCommand.updateMe({
253 url: server.url, 240 token: cyanAccessToken,
254 accessToken: cyanAccessToken,
255 email: 'toto@example.com', 241 email: 'toto@example.com',
256 currentPassword: 'toto', 242 currentPassword: 'toto',
257 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 243 expectedStatus: HttpStatusCode.BAD_REQUEST_400
258 }) 244 })
259 }) 245 })
260 246
@@ -263,7 +249,7 @@ describe('Test external auth plugins', function () {
263 249
264 await wait(5000) 250 await wait(5000)
265 251
266 await getMyUserInformation(server.url, kefkaAccessToken, HttpStatusCode.UNAUTHORIZED_401) 252 await server.usersCommand.getMyInfo({ token: kefkaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
267 }) 253 })
268 254
269 it('Should unregister external-auth-2 and do not login existing Kefka', async function () { 255 it('Should unregister external-auth-2 and do not login existing Kefka', async function () {
@@ -334,12 +320,7 @@ describe('Test external auth plugins', function () {
334 }) 320 })
335 321
336 it('Should not login an existing user', async function () { 322 it('Should not login an existing user', async function () {
337 await createUser({ 323 await server.usersCommand.create({ username: 'existing_user', password: 'super_password' })
338 url: server.url,
339 accessToken: server.accessToken,
340 username: 'existing_user',
341 password: 'super_password'
342 })
343 324
344 await loginExternal({ 325 await loginExternal({
345 server, 326 server,
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index b5e29d298..c82025f6a 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -17,7 +17,6 @@ import {
17 ImportsCommand, 17 ImportsCommand,
18 makeRawRequest, 18 makeRawRequest,
19 PluginsCommand, 19 PluginsCommand,
20 registerUser,
21 ServerInfo, 20 ServerInfo,
22 setAccessTokensToServers, 21 setAccessTokensToServers,
23 setDefaultVideoChannel, 22 setDefaultVideoChannel,
@@ -335,11 +334,15 @@ describe('Test plugin filter hooks', function () {
335 }) 334 })
336 335
337 it('Should allow a signup', async function () { 336 it('Should allow a signup', async function () {
338 await registerUser(servers[0].url, 'john', 'password') 337 await servers[0].usersCommand.register({ username: 'john', password: 'password' })
339 }) 338 })
340 339
341 it('Should not allow a signup', async function () { 340 it('Should not allow a signup', async function () {
342 const res = await registerUser(servers[0].url, 'jma', 'password', HttpStatusCode.FORBIDDEN_403) 341 const res = await servers[0].usersCommand.register({
342 username: 'jma',
343 password: 'password',
344 expectedStatus: HttpStatusCode.FORBIDDEN_403
345 })
343 346
344 expect(res.body.error).to.equal('No jma') 347 expect(res.body.error).to.equal('No jma')
345 }) 348 })
diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts
index e3da64110..787080e7c 100644
--- a/server/tests/plugins/id-and-pass-auth.ts
+++ b/server/tests/plugins/id-and-pass-auth.ts
@@ -3,18 +3,8 @@
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import { cleanupTests, flushAndRunServer, PluginsCommand, ServerInfo, setAccessTokensToServers, wait } from '@shared/extra-utils'
7 cleanupTests, 7import { UserRole } from '@shared/models'
8 flushAndRunServer,
9 getMyUserInformation,
10 getUsersList,
11 PluginsCommand,
12 ServerInfo,
13 setAccessTokensToServers,
14 updateMyUser,
15 wait
16} from '@shared/extra-utils'
17import { User, UserRole } from '@shared/models'
18 8
19describe('Test id and pass auth plugins', function () { 9describe('Test id and pass auth plugins', function () {
20 let server: ServerInfo 10 let server: ServerInfo
@@ -55,9 +45,8 @@ describe('Test id and pass auth plugins', function () {
55 it('Should login Spyro, create the user and use the token', async function () { 45 it('Should login Spyro, create the user and use the token', async function () {
56 const accessToken = await server.loginCommand.getAccessToken({ username: 'spyro', password: 'spyro password' }) 46 const accessToken = await server.loginCommand.getAccessToken({ username: 'spyro', password: 'spyro password' })
57 47
58 const res = await getMyUserInformation(server.url, accessToken) 48 const body = await server.usersCommand.getMyInfo({ token: accessToken })
59 49
60 const body: User = res.body
61 expect(body.username).to.equal('spyro') 50 expect(body.username).to.equal('spyro')
62 expect(body.account.displayName).to.equal('Spyro the Dragon') 51 expect(body.account.displayName).to.equal('Spyro the Dragon')
63 expect(body.role).to.equal(UserRole.USER) 52 expect(body.role).to.equal(UserRole.USER)
@@ -71,9 +60,8 @@ describe('Test id and pass auth plugins', function () {
71 } 60 }
72 61
73 { 62 {
74 const res = await getMyUserInformation(server.url, crashAccessToken) 63 const body = await server.usersCommand.getMyInfo({ token: crashAccessToken })
75 64
76 const body: User = res.body
77 expect(body.username).to.equal('crash') 65 expect(body.username).to.equal('crash')
78 expect(body.account.displayName).to.equal('Crash Bandicoot') 66 expect(body.account.displayName).to.equal('Crash Bandicoot')
79 expect(body.role).to.equal(UserRole.MODERATOR) 67 expect(body.role).to.equal(UserRole.MODERATOR)
@@ -88,9 +76,8 @@ describe('Test id and pass auth plugins', function () {
88 } 76 }
89 77
90 { 78 {
91 const res = await getMyUserInformation(server.url, lagunaAccessToken) 79 const body = await server.usersCommand.getMyInfo({ token: lagunaAccessToken })
92 80
93 const body: User = res.body
94 expect(body.username).to.equal('laguna') 81 expect(body.username).to.equal('laguna')
95 expect(body.account.displayName).to.equal('laguna') 82 expect(body.account.displayName).to.equal('laguna')
96 expect(body.role).to.equal(UserRole.USER) 83 expect(body.role).to.equal(UserRole.USER)
@@ -103,9 +90,8 @@ describe('Test id and pass auth plugins', function () {
103 crashAccessToken = resRefresh.body.access_token 90 crashAccessToken = resRefresh.body.access_token
104 crashRefreshToken = resRefresh.body.refresh_token 91 crashRefreshToken = resRefresh.body.refresh_token
105 92
106 const res = await getMyUserInformation(server.url, crashAccessToken) 93 const body = await server.usersCommand.getMyInfo({ token: crashAccessToken })
107 const user: User = res.body 94 expect(body.username).to.equal('crash')
108 expect(user.username).to.equal('crash')
109 } 95 }
110 96
111 { 97 {
@@ -114,16 +100,14 @@ describe('Test id and pass auth plugins', function () {
114 }) 100 })
115 101
116 it('Should update Crash profile', async function () { 102 it('Should update Crash profile', async function () {
117 await updateMyUser({ 103 await server.usersCommand.updateMe({
118 url: server.url, 104 token: crashAccessToken,
119 accessToken: crashAccessToken,
120 displayName: 'Beautiful Crash', 105 displayName: 'Beautiful Crash',
121 description: 'Mutant eastern barred bandicoot' 106 description: 'Mutant eastern barred bandicoot'
122 }) 107 })
123 108
124 const res = await getMyUserInformation(server.url, crashAccessToken) 109 const body = await server.usersCommand.getMyInfo({ token: crashAccessToken })
125 110
126 const body: User = res.body
127 expect(body.account.displayName).to.equal('Beautiful Crash') 111 expect(body.account.displayName).to.equal('Beautiful Crash')
128 expect(body.account.description).to.equal('Mutant eastern barred bandicoot') 112 expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
129 }) 113 })
@@ -135,15 +119,14 @@ describe('Test id and pass auth plugins', function () {
135 it('Should have logged out Crash', async function () { 119 it('Should have logged out Crash', async function () {
136 await server.serversCommand.waitUntilLog('On logout for auth 1 - 2') 120 await server.serversCommand.waitUntilLog('On logout for auth 1 - 2')
137 121
138 await getMyUserInformation(server.url, crashAccessToken, 401) 122 await server.usersCommand.getMyInfo({ token: crashAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
139 }) 123 })
140 124
141 it('Should login Crash and keep the old existing profile', async function () { 125 it('Should login Crash and keep the old existing profile', async function () {
142 crashAccessToken = await server.loginCommand.getAccessToken({ username: 'crash', password: 'crash password' }) 126 crashAccessToken = await server.loginCommand.getAccessToken({ username: 'crash', password: 'crash password' })
143 127
144 const res = await getMyUserInformation(server.url, crashAccessToken) 128 const body = await server.usersCommand.getMyInfo({ token: crashAccessToken })
145 129
146 const body: User = res.body
147 expect(body.username).to.equal('crash') 130 expect(body.username).to.equal('crash')
148 expect(body.account.displayName).to.equal('Beautiful Crash') 131 expect(body.account.displayName).to.equal('Beautiful Crash')
149 expect(body.account.description).to.equal('Mutant eastern barred bandicoot') 132 expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
@@ -155,7 +138,7 @@ describe('Test id and pass auth plugins', function () {
155 138
156 await wait(5000) 139 await wait(5000)
157 140
158 await getMyUserInformation(server.url, lagunaAccessToken, 401) 141 await server.usersCommand.getMyInfo({ token: lagunaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
159 }) 142 })
160 143
161 it('Should reject an invalid username, email, role or display name', async function () { 144 it('Should reject an invalid username, email, role or display name', async function () {
@@ -215,13 +198,11 @@ describe('Test id and pass auth plugins', function () {
215 }) 198 })
216 199
217 it('Should display plugin auth information in users list', async function () { 200 it('Should display plugin auth information in users list', async function () {
218 const res = await getUsersList(server.url, server.accessToken) 201 const { data } = await server.usersCommand.list()
219
220 const users: User[] = res.body.data
221 202
222 const root = users.find(u => u.username === 'root') 203 const root = data.find(u => u.username === 'root')
223 const crash = users.find(u => u.username === 'crash') 204 const crash = data.find(u => u.username === 'crash')
224 const laguna = users.find(u => u.username === 'laguna') 205 const laguna = data.find(u => u.username === 'laguna')
225 206
226 expect(root.pluginAuth).to.be.null 207 expect(root.pluginAuth).to.be.null
227 expect(crash.pluginAuth).to.equal('peertube-plugin-test-id-pass-auth-one') 208 expect(crash.pluginAuth).to.equal('peertube-plugin-test-id-pass-auth-one')