aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/plugins')
-rw-r--r--server/tests/plugins/action-hooks.ts111
-rw-r--r--server/tests/plugins/external-auth.ts184
-rw-r--r--server/tests/plugins/filter-hooks.ts400
-rw-r--r--server/tests/plugins/html-injection.ts41
-rw-r--r--server/tests/plugins/id-and-pass-auth.ts141
-rw-r--r--server/tests/plugins/plugin-helpers.ts114
-rw-r--r--server/tests/plugins/plugin-router.ts43
-rw-r--r--server/tests/plugins/plugin-storage.ts45
-rw-r--r--server/tests/plugins/plugin-transcoding.ts138
-rw-r--r--server/tests/plugins/plugin-unloading.ts45
-rw-r--r--server/tests/plugins/translations.ts51
-rw-r--r--server/tests/plugins/video-constants.ts121
12 files changed, 595 insertions, 839 deletions
diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts
index 0f57ef7fe..4c1bc7d06 100644
--- a/server/tests/plugins/action-hooks.ts
+++ b/server/tests/plugins/action-hooks.ts
@@ -1,63 +1,38 @@
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 {
6 addVideoCommentReply,
7 addVideoCommentThread,
8 addVideoInPlaylist,
9 blockUser,
10 createLive,
11 createUser,
12 createVideoPlaylist,
13 deleteVideoComment,
14 getPluginTestPath,
15 installPlugin,
16 registerUser,
17 removeUser,
18 setAccessTokensToServers,
19 setDefaultVideoChannel,
20 unblockUser,
21 updateUser,
22 updateVideo,
23 uploadVideo,
24 userLogin,
25 viewVideo
26} from '../../../shared/extra-utils'
27import { 4import {
28 cleanupTests, 5 cleanupTests,
29 flushAndRunMultipleServers, 6 createMultipleServers,
30 killallServers, 7 killallServers,
31 reRunServer, 8 PeerTubeServer,
32 ServerInfo, 9 PluginsCommand,
33 waitUntilLog 10 setAccessTokensToServers,
34} from '../../../shared/extra-utils/server/servers' 11 setDefaultVideoChannel
12} from '@shared/extra-utils'
13import { ServerHookName, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
35 14
36describe('Test plugin action hooks', function () { 15describe('Test plugin action hooks', function () {
37 let servers: ServerInfo[] 16 let servers: PeerTubeServer[]
38 let videoUUID: string 17 let videoUUID: string
39 let threadId: number 18 let threadId: number
40 19
41 function checkHook (hook: ServerHookName) { 20 function checkHook (hook: ServerHookName) {
42 return waitUntilLog(servers[0], 'Run hook ' + hook) 21 return servers[0].servers.waitUntilLog('Run hook ' + hook)
43 } 22 }
44 23
45 before(async function () { 24 before(async function () {
46 this.timeout(30000) 25 this.timeout(30000)
47 26
48 servers = await flushAndRunMultipleServers(2) 27 servers = await createMultipleServers(2)
49 await setAccessTokensToServers(servers) 28 await setAccessTokensToServers(servers)
50 await setDefaultVideoChannel(servers) 29 await setDefaultVideoChannel(servers)
51 30
52 await installPlugin({ 31 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() })
53 url: servers[0].url,
54 accessToken: servers[0].accessToken,
55 path: getPluginTestPath()
56 })
57 32
58 killallServers([ servers[0] ]) 33 await killallServers([ servers[0] ])
59 34
60 await reRunServer(servers[0], { 35 await servers[0].run({
61 live: { 36 live: {
62 enabled: true 37 enabled: true
63 } 38 }
@@ -73,20 +48,20 @@ describe('Test plugin action hooks', function () {
73 describe('Videos hooks', function () { 48 describe('Videos hooks', function () {
74 49
75 it('Should run action:api.video.uploaded', async function () { 50 it('Should run action:api.video.uploaded', async function () {
76 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) 51 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } })
77 videoUUID = res.body.video.uuid 52 videoUUID = uuid
78 53
79 await checkHook('action:api.video.uploaded') 54 await checkHook('action:api.video.uploaded')
80 }) 55 })
81 56
82 it('Should run action:api.video.updated', async function () { 57 it('Should run action:api.video.updated', async function () {
83 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' }) 58 await servers[0].videos.update({ id: videoUUID, attributes: { name: 'video updated' } })
84 59
85 await checkHook('action:api.video.updated') 60 await checkHook('action:api.video.updated')
86 }) 61 })
87 62
88 it('Should run action:api.video.viewed', async function () { 63 it('Should run action:api.video.viewed', async function () {
89 await viewVideo(servers[0].url, videoUUID) 64 await servers[0].videos.view({ id: videoUUID })
90 65
91 await checkHook('action:api.video.viewed') 66 await checkHook('action:api.video.viewed')
92 }) 67 })
@@ -98,10 +73,10 @@ describe('Test plugin action hooks', function () {
98 const attributes = { 73 const attributes = {
99 name: 'live', 74 name: 'live',
100 privacy: VideoPrivacy.PUBLIC, 75 privacy: VideoPrivacy.PUBLIC,
101 channelId: servers[0].videoChannel.id 76 channelId: servers[0].store.channel.id
102 } 77 }
103 78
104 await createLive(servers[0].url, servers[0].accessToken, attributes) 79 await servers[0].live.create({ fields: attributes })
105 80
106 await checkHook('action:api.live-video.created') 81 await checkHook('action:api.live-video.created')
107 }) 82 })
@@ -109,20 +84,20 @@ describe('Test plugin action hooks', function () {
109 84
110 describe('Comments hooks', function () { 85 describe('Comments hooks', function () {
111 it('Should run action:api.video-thread.created', async function () { 86 it('Should run action:api.video-thread.created', async function () {
112 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread') 87 const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
113 threadId = res.body.comment.id 88 threadId = created.id
114 89
115 await checkHook('action:api.video-thread.created') 90 await checkHook('action:api.video-thread.created')
116 }) 91 })
117 92
118 it('Should run action:api.video-comment-reply.created', async function () { 93 it('Should run action:api.video-comment-reply.created', async function () {
119 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply') 94 await servers[0].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: 'reply' })
120 95
121 await checkHook('action:api.video-comment-reply.created') 96 await checkHook('action:api.video-comment-reply.created')
122 }) 97 })
123 98
124 it('Should run action:api.video-comment.deleted', async function () { 99 it('Should run action:api.video-comment.deleted', async function () {
125 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) 100 await servers[0].comments.delete({ videoId: videoUUID, commentId: threadId })
126 101
127 await checkHook('action:api.video-comment.deleted') 102 await checkHook('action:api.video-comment.deleted')
128 }) 103 })
@@ -132,49 +107,44 @@ describe('Test plugin action hooks', function () {
132 let userId: number 107 let userId: number
133 108
134 it('Should run action:api.user.registered', async function () { 109 it('Should run action:api.user.registered', async function () {
135 await registerUser(servers[0].url, 'registered_user', 'super_password') 110 await servers[0].users.register({ username: 'registered_user' })
136 111
137 await checkHook('action:api.user.registered') 112 await checkHook('action:api.user.registered')
138 }) 113 })
139 114
140 it('Should run action:api.user.created', async function () { 115 it('Should run action:api.user.created', async function () {
141 const res = await createUser({ 116 const user = await servers[0].users.create({ username: 'created_user' })
142 url: servers[0].url, 117 userId = user.id
143 accessToken: servers[0].accessToken,
144 username: 'created_user',
145 password: 'super_password'
146 })
147 userId = res.body.user.id
148 118
149 await checkHook('action:api.user.created') 119 await checkHook('action:api.user.created')
150 }) 120 })
151 121
152 it('Should run action:api.user.oauth2-got-token', async function () { 122 it('Should run action:api.user.oauth2-got-token', async function () {
153 await userLogin(servers[0], { username: 'created_user', password: 'super_password' }) 123 await servers[0].login.login({ user: { username: 'created_user' } })
154 124
155 await checkHook('action:api.user.oauth2-got-token') 125 await checkHook('action:api.user.oauth2-got-token')
156 }) 126 })
157 127
158 it('Should run action:api.user.blocked', async function () { 128 it('Should run action:api.user.blocked', async function () {
159 await blockUser(servers[0].url, userId, servers[0].accessToken) 129 await servers[0].users.banUser({ userId })
160 130
161 await checkHook('action:api.user.blocked') 131 await checkHook('action:api.user.blocked')
162 }) 132 })
163 133
164 it('Should run action:api.user.unblocked', async function () { 134 it('Should run action:api.user.unblocked', async function () {
165 await unblockUser(servers[0].url, userId, servers[0].accessToken) 135 await servers[0].users.unbanUser({ userId })
166 136
167 await checkHook('action:api.user.unblocked') 137 await checkHook('action:api.user.unblocked')
168 }) 138 })
169 139
170 it('Should run action:api.user.updated', async function () { 140 it('Should run action:api.user.updated', async function () {
171 await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 }) 141 await servers[0].users.update({ userId, videoQuota: 50 })
172 142
173 await checkHook('action:api.user.updated') 143 await checkHook('action:api.user.updated')
174 }) 144 })
175 145
176 it('Should run action:api.user.deleted', async function () { 146 it('Should run action:api.user.deleted', async function () {
177 await removeUser(servers[0].url, userId, servers[0].accessToken) 147 await servers[0].users.remove({ userId })
178 148
179 await checkHook('action:api.user.deleted') 149 await checkHook('action:api.user.deleted')
180 }) 150 })
@@ -186,30 +156,23 @@ describe('Test plugin action hooks', function () {
186 156
187 before(async function () { 157 before(async function () {
188 { 158 {
189 const res = await createVideoPlaylist({ 159 const { id } = await servers[0].playlists.create({
190 url: servers[0].url, 160 attributes: {
191 token: servers[0].accessToken,
192 playlistAttrs: {
193 displayName: 'My playlist', 161 displayName: 'My playlist',
194 privacy: VideoPlaylistPrivacy.PRIVATE 162 privacy: VideoPlaylistPrivacy.PRIVATE
195 } 163 }
196 }) 164 })
197 playlistId = res.body.videoPlaylist.id 165 playlistId = id
198 } 166 }
199 167
200 { 168 {
201 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my super name' }) 169 const { id } = await servers[0].videos.upload({ attributes: { name: 'my super name' } })
202 videoId = res.body.video.id 170 videoId = id
203 } 171 }
204 }) 172 })
205 173
206 it('Should run action:api.video-playlist-element.created', async function () { 174 it('Should run action:api.video-playlist-element.created', async function () {
207 await addVideoInPlaylist({ 175 await servers[0].playlists.addElement({ playlistId, attributes: { videoId } })
208 url: servers[0].url,
209 token: servers[0].accessToken,
210 playlistId,
211 elementAttrs: { videoId }
212 })
213 176
214 await checkHook('action:api.video-playlist-element.created') 177 await checkHook('action:api.video-playlist-element.created')
215 }) 178 })
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts
index 5addb45c7..f3e018d43 100644
--- a/server/tests/plugins/external-auth.ts
+++ b/server/tests/plugins/external-auth.ts
@@ -2,44 +2,32 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { ServerConfig, User, UserRole } from '@shared/models'
6import { 5import {
6 cleanupTests,
7 createSingleServer,
7 decodeQueryString, 8 decodeQueryString,
8 getConfig, 9 PeerTubeServer,
9 getExternalAuth, 10 PluginsCommand,
10 getMyUserInformation,
11 getPluginTestPath,
12 installPlugin,
13 loginUsingExternalToken,
14 logout,
15 refreshToken,
16 setAccessTokensToServers, 11 setAccessTokensToServers,
17 uninstallPlugin, 12 wait
18 updateMyUser, 13} from '@shared/extra-utils'
19 wait, 14import { HttpStatusCode, UserRole } from '@shared/models'
20 userLogin,
21 updatePluginSettings,
22 createUser
23} from '../../../shared/extra-utils'
24import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
25import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
26 15
27async function loginExternal (options: { 16async function loginExternal (options: {
28 server: ServerInfo 17 server: PeerTubeServer
29 npmName: string 18 npmName: string
30 authName: string 19 authName: string
31 username: string 20 username: string
32 query?: any 21 query?: any
33 statusCodeExpected?: HttpStatusCode 22 expectedStatus?: HttpStatusCode
34 statusCodeExpectedStep2?: HttpStatusCode 23 expectedStatusStep2?: HttpStatusCode
35}) { 24}) {
36 const res = await getExternalAuth({ 25 const res = await options.server.plugins.getExternalAuth({
37 url: options.server.url,
38 npmName: options.npmName, 26 npmName: options.npmName,
39 npmVersion: '0.0.1', 27 npmVersion: '0.0.1',
40 authName: options.authName, 28 authName: options.authName,
41 query: options.query, 29 query: options.query,
42 statusCodeExpected: options.statusCodeExpected || HttpStatusCode.FOUND_302 30 expectedStatus: options.expectedStatus || HttpStatusCode.FOUND_302
43 }) 31 })
44 32
45 if (res.status !== HttpStatusCode.FOUND_302) return 33 if (res.status !== HttpStatusCode.FOUND_302) return
@@ -47,18 +35,17 @@ async function loginExternal (options: {
47 const location = res.header.location 35 const location = res.header.location
48 const { externalAuthToken } = decodeQueryString(location) 36 const { externalAuthToken } = decodeQueryString(location)
49 37
50 const resLogin = await loginUsingExternalToken( 38 const resLogin = await options.server.login.loginUsingExternalToken({
51 options.server, 39 username: options.username,
52 options.username, 40 externalAuthToken: externalAuthToken as string,
53 externalAuthToken as string, 41 expectedStatus: options.expectedStatusStep2
54 options.statusCodeExpectedStep2 42 })
55 )
56 43
57 return resLogin.body 44 return resLogin.body
58} 45}
59 46
60describe('Test external auth plugins', function () { 47describe('Test external auth plugins', function () {
61 let server: ServerInfo 48 let server: PeerTubeServer
62 49
63 let cyanAccessToken: string 50 let cyanAccessToken: string
64 let cyanRefreshToken: string 51 let cyanRefreshToken: string
@@ -71,22 +58,16 @@ describe('Test external auth plugins', function () {
71 before(async function () { 58 before(async function () {
72 this.timeout(30000) 59 this.timeout(30000)
73 60
74 server = await flushAndRunServer(1) 61 server = await createSingleServer(1)
75 await setAccessTokensToServers([ server ]) 62 await setAccessTokensToServers([ server ])
76 63
77 for (const suffix of [ 'one', 'two', 'three' ]) { 64 for (const suffix of [ 'one', 'two', 'three' ]) {
78 await installPlugin({ 65 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-external-auth-' + suffix) })
79 url: server.url,
80 accessToken: server.accessToken,
81 path: getPluginTestPath('-external-auth-' + suffix)
82 })
83 } 66 }
84 }) 67 })
85 68
86 it('Should display the correct configuration', async function () { 69 it('Should display the correct configuration', async function () {
87 const res = await getConfig(server.url) 70 const config = await server.config.getConfig()
88
89 const config: ServerConfig = res.body
90 71
91 const auths = config.plugin.registeredExternalAuths 72 const auths = config.plugin.registeredExternalAuths
92 expect(auths).to.have.lengthOf(8) 73 expect(auths).to.have.lengthOf(8)
@@ -98,15 +79,14 @@ describe('Test external auth plugins', function () {
98 }) 79 })
99 80
100 it('Should redirect for a Cyan login', async function () { 81 it('Should redirect for a Cyan login', async function () {
101 const res = await getExternalAuth({ 82 const res = await server.plugins.getExternalAuth({
102 url: server.url,
103 npmName: 'test-external-auth-one', 83 npmName: 'test-external-auth-one',
104 npmVersion: '0.0.1', 84 npmVersion: '0.0.1',
105 authName: 'external-auth-1', 85 authName: 'external-auth-1',
106 query: { 86 query: {
107 username: 'cyan' 87 username: 'cyan'
108 }, 88 },
109 statusCodeExpected: HttpStatusCode.FOUND_302 89 expectedStatus: HttpStatusCode.FOUND_302
110 }) 90 })
111 91
112 const location = res.header.location 92 const location = res.header.location
@@ -121,13 +101,17 @@ describe('Test external auth plugins', function () {
121 }) 101 })
122 102
123 it('Should reject auto external login with a missing or invalid token', async function () { 103 it('Should reject auto external login with a missing or invalid token', async function () {
124 await loginUsingExternalToken(server, 'cyan', '', HttpStatusCode.BAD_REQUEST_400) 104 const command = server.login
125 await loginUsingExternalToken(server, 'cyan', 'blabla', HttpStatusCode.BAD_REQUEST_400) 105
106 await command.loginUsingExternalToken({ username: 'cyan', externalAuthToken: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
107 await command.loginUsingExternalToken({ username: 'cyan', externalAuthToken: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
126 }) 108 })
127 109
128 it('Should reject auto external login with a missing or invalid username', async function () { 110 it('Should reject auto external login with a missing or invalid username', async function () {
129 await loginUsingExternalToken(server, '', externalAuthToken, HttpStatusCode.BAD_REQUEST_400) 111 const command = server.login
130 await loginUsingExternalToken(server, '', externalAuthToken, HttpStatusCode.BAD_REQUEST_400) 112
113 await command.loginUsingExternalToken({ username: '', externalAuthToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
114 await command.loginUsingExternalToken({ username: '', externalAuthToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
131 }) 115 })
132 116
133 it('Should reject auto external login with an expired token', async function () { 117 it('Should reject auto external login with an expired token', async function () {
@@ -135,9 +119,13 @@ describe('Test external auth plugins', function () {
135 119
136 await wait(5000) 120 await wait(5000)
137 121
138 await loginUsingExternalToken(server, 'cyan', externalAuthToken, HttpStatusCode.BAD_REQUEST_400) 122 await server.login.loginUsingExternalToken({
123 username: 'cyan',
124 externalAuthToken,
125 expectedStatus: HttpStatusCode.BAD_REQUEST_400
126 })
139 127
140 await waitUntilLog(server, 'expired external auth token', 2) 128 await server.servers.waitUntilLog('expired external auth token', 2)
141 }) 129 })
142 130
143 it('Should auto login Cyan, create the user and use the token', async function () { 131 it('Should auto login Cyan, create the user and use the token', async function () {
@@ -157,9 +145,7 @@ describe('Test external auth plugins', function () {
157 } 145 }
158 146
159 { 147 {
160 const res = await getMyUserInformation(server.url, cyanAccessToken) 148 const body = await server.users.getMyInfo({ token: cyanAccessToken })
161
162 const body: User = res.body
163 expect(body.username).to.equal('cyan') 149 expect(body.username).to.equal('cyan')
164 expect(body.account.displayName).to.equal('cyan') 150 expect(body.account.displayName).to.equal('cyan')
165 expect(body.email).to.equal('cyan@example.com') 151 expect(body.email).to.equal('cyan@example.com')
@@ -181,9 +167,7 @@ describe('Test external auth plugins', function () {
181 } 167 }
182 168
183 { 169 {
184 const res = await getMyUserInformation(server.url, kefkaAccessToken) 170 const body = await server.users.getMyInfo({ token: kefkaAccessToken })
185
186 const body: User = res.body
187 expect(body.username).to.equal('kefka') 171 expect(body.username).to.equal('kefka')
188 expect(body.account.displayName).to.equal('Kefka Palazzo') 172 expect(body.account.displayName).to.equal('Kefka Palazzo')
189 expect(body.email).to.equal('kefka@example.com') 173 expect(body.email).to.equal('kefka@example.com')
@@ -193,43 +177,39 @@ describe('Test external auth plugins', function () {
193 177
194 it('Should refresh Cyan token, but not Kefka token', async function () { 178 it('Should refresh Cyan token, but not Kefka token', async function () {
195 { 179 {
196 const resRefresh = await refreshToken(server, cyanRefreshToken) 180 const resRefresh = await server.login.refreshToken({ refreshToken: cyanRefreshToken })
197 cyanAccessToken = resRefresh.body.access_token 181 cyanAccessToken = resRefresh.body.access_token
198 cyanRefreshToken = resRefresh.body.refresh_token 182 cyanRefreshToken = resRefresh.body.refresh_token
199 183
200 const res = await getMyUserInformation(server.url, cyanAccessToken) 184 const body = await server.users.getMyInfo({ token: cyanAccessToken })
201 const user: User = res.body 185 expect(body.username).to.equal('cyan')
202 expect(user.username).to.equal('cyan')
203 } 186 }
204 187
205 { 188 {
206 await refreshToken(server, kefkaRefreshToken, HttpStatusCode.BAD_REQUEST_400) 189 await server.login.refreshToken({ refreshToken: kefkaRefreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
207 } 190 }
208 }) 191 })
209 192
210 it('Should update Cyan profile', async function () { 193 it('Should update Cyan profile', async function () {
211 await updateMyUser({ 194 await server.users.updateMe({
212 url: server.url, 195 token: cyanAccessToken,
213 accessToken: cyanAccessToken,
214 displayName: 'Cyan Garamonde', 196 displayName: 'Cyan Garamonde',
215 description: 'Retainer to the king of Doma' 197 description: 'Retainer to the king of Doma'
216 }) 198 })
217 199
218 const res = await getMyUserInformation(server.url, cyanAccessToken) 200 const body = await server.users.getMyInfo({ token: cyanAccessToken })
219
220 const body: User = res.body
221 expect(body.account.displayName).to.equal('Cyan Garamonde') 201 expect(body.account.displayName).to.equal('Cyan Garamonde')
222 expect(body.account.description).to.equal('Retainer to the king of Doma') 202 expect(body.account.description).to.equal('Retainer to the king of Doma')
223 }) 203 })
224 204
225 it('Should logout Cyan', async function () { 205 it('Should logout Cyan', async function () {
226 await logout(server.url, cyanAccessToken) 206 await server.login.logout({ token: cyanAccessToken })
227 }) 207 })
228 208
229 it('Should have logged out Cyan', async function () { 209 it('Should have logged out Cyan', async function () {
230 await waitUntilLog(server, 'On logout cyan') 210 await server.servers.waitUntilLog('On logout cyan')
231 211
232 await getMyUserInformation(server.url, cyanAccessToken, HttpStatusCode.UNAUTHORIZED_401) 212 await server.users.getMyInfo({ token: cyanAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
233 }) 213 })
234 214
235 it('Should login Cyan and keep the old existing profile', async function () { 215 it('Should login Cyan and keep the old existing profile', async function () {
@@ -247,9 +227,7 @@ describe('Test external auth plugins', function () {
247 cyanAccessToken = res.access_token 227 cyanAccessToken = res.access_token
248 } 228 }
249 229
250 const res = await getMyUserInformation(server.url, cyanAccessToken) 230 const body = await server.users.getMyInfo({ token: cyanAccessToken })
251
252 const body: User = res.body
253 expect(body.username).to.equal('cyan') 231 expect(body.username).to.equal('cyan')
254 expect(body.account.displayName).to.equal('Cyan Garamonde') 232 expect(body.account.displayName).to.equal('Cyan Garamonde')
255 expect(body.account.description).to.equal('Retainer to the king of Doma') 233 expect(body.account.description).to.equal('Retainer to the king of Doma')
@@ -257,12 +235,11 @@ describe('Test external auth plugins', function () {
257 }) 235 })
258 236
259 it('Should not update an external auth email', async function () { 237 it('Should not update an external auth email', async function () {
260 await updateMyUser({ 238 await server.users.updateMe({
261 url: server.url, 239 token: cyanAccessToken,
262 accessToken: cyanAccessToken,
263 email: 'toto@example.com', 240 email: 'toto@example.com',
264 currentPassword: 'toto', 241 currentPassword: 'toto',
265 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 242 expectedStatus: HttpStatusCode.BAD_REQUEST_400
266 }) 243 })
267 }) 244 })
268 245
@@ -271,18 +248,16 @@ describe('Test external auth plugins', function () {
271 248
272 await wait(5000) 249 await wait(5000)
273 250
274 await getMyUserInformation(server.url, kefkaAccessToken, HttpStatusCode.UNAUTHORIZED_401) 251 await server.users.getMyInfo({ token: kefkaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
275 }) 252 })
276 253
277 it('Should unregister external-auth-2 and do not login existing Kefka', async function () { 254 it('Should unregister external-auth-2 and do not login existing Kefka', async function () {
278 await updatePluginSettings({ 255 await server.plugins.updateSettings({
279 url: server.url,
280 accessToken: server.accessToken,
281 npmName: 'peertube-plugin-test-external-auth-one', 256 npmName: 'peertube-plugin-test-external-auth-one',
282 settings: { disableKefka: true } 257 settings: { disableKefka: true }
283 }) 258 })
284 259
285 await userLogin(server, { username: 'kefka', password: 'fake' }, HttpStatusCode.BAD_REQUEST_400) 260 await server.login.login({ user: { username: 'kefka', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
286 261
287 await loginExternal({ 262 await loginExternal({
288 server, 263 server,
@@ -292,14 +267,12 @@ describe('Test external auth plugins', function () {
292 username: 'kefka' 267 username: 'kefka'
293 }, 268 },
294 username: 'kefka', 269 username: 'kefka',
295 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 270 expectedStatus: HttpStatusCode.NOT_FOUND_404
296 }) 271 })
297 }) 272 })
298 273
299 it('Should have disabled this auth', async function () { 274 it('Should have disabled this auth', async function () {
300 const res = await getConfig(server.url) 275 const config = await server.config.getConfig()
301
302 const config: ServerConfig = res.body
303 276
304 const auths = config.plugin.registeredExternalAuths 277 const auths = config.plugin.registeredExternalAuths
305 expect(auths).to.have.lengthOf(7) 278 expect(auths).to.have.lengthOf(7)
@@ -309,11 +282,7 @@ describe('Test external auth plugins', function () {
309 }) 282 })
310 283
311 it('Should uninstall the plugin one and do not login Cyan', async function () { 284 it('Should uninstall the plugin one and do not login Cyan', async function () {
312 await uninstallPlugin({ 285 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-external-auth-one' })
313 url: server.url,
314 accessToken: server.accessToken,
315 npmName: 'peertube-plugin-test-external-auth-one'
316 })
317 286
318 await loginExternal({ 287 await loginExternal({
319 server, 288 server,
@@ -323,12 +292,12 @@ describe('Test external auth plugins', function () {
323 username: 'cyan' 292 username: 'cyan'
324 }, 293 },
325 username: 'cyan', 294 username: 'cyan',
326 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 295 expectedStatus: HttpStatusCode.NOT_FOUND_404
327 }) 296 })
328 297
329 await userLogin(server, { username: 'cyan', password: null }, HttpStatusCode.BAD_REQUEST_400) 298 await server.login.login({ user: { username: 'cyan', password: null }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
330 await userLogin(server, { username: 'cyan', password: '' }, HttpStatusCode.BAD_REQUEST_400) 299 await server.login.login({ user: { username: 'cyan', password: '' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
331 await userLogin(server, { username: 'cyan', password: 'fake' }, HttpStatusCode.BAD_REQUEST_400) 300 await server.login.login({ user: { username: 'cyan', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
332 }) 301 })
333 302
334 it('Should not login kefka with another plugin', async function () { 303 it('Should not login kefka with another plugin', async function () {
@@ -337,7 +306,7 @@ describe('Test external auth plugins', function () {
337 npmName: 'test-external-auth-two', 306 npmName: 'test-external-auth-two',
338 authName: 'external-auth-4', 307 authName: 'external-auth-4',
339 username: 'kefka2', 308 username: 'kefka2',
340 statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400 309 expectedStatusStep2: HttpStatusCode.BAD_REQUEST_400
341 }) 310 })
342 311
343 await loginExternal({ 312 await loginExternal({
@@ -345,31 +314,24 @@ describe('Test external auth plugins', function () {
345 npmName: 'test-external-auth-two', 314 npmName: 'test-external-auth-two',
346 authName: 'external-auth-4', 315 authName: 'external-auth-4',
347 username: 'kefka', 316 username: 'kefka',
348 statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400 317 expectedStatusStep2: HttpStatusCode.BAD_REQUEST_400
349 }) 318 })
350 }) 319 })
351 320
352 it('Should not login an existing user', async function () { 321 it('Should not login an existing user', async function () {
353 await createUser({ 322 await server.users.create({ username: 'existing_user', password: 'super_password' })
354 url: server.url,
355 accessToken: server.accessToken,
356 username: 'existing_user',
357 password: 'super_password'
358 })
359 323
360 await loginExternal({ 324 await loginExternal({
361 server, 325 server,
362 npmName: 'test-external-auth-two', 326 npmName: 'test-external-auth-two',
363 authName: 'external-auth-6', 327 authName: 'external-auth-6',
364 username: 'existing_user', 328 username: 'existing_user',
365 statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400 329 expectedStatusStep2: HttpStatusCode.BAD_REQUEST_400
366 }) 330 })
367 }) 331 })
368 332
369 it('Should display the correct configuration', async function () { 333 it('Should display the correct configuration', async function () {
370 const res = await getConfig(server.url) 334 const config = await server.config.getConfig()
371
372 const config: ServerConfig = res.body
373 335
374 const auths = config.plugin.registeredExternalAuths 336 const auths = config.plugin.registeredExternalAuths
375 expect(auths).to.have.lengthOf(6) 337 expect(auths).to.have.lengthOf(6)
@@ -390,9 +352,8 @@ describe('Test external auth plugins', function () {
390 username: 'cid' 352 username: 'cid'
391 }) 353 })
392 354
393 const resLogout = await logout(server.url, resLogin.access_token) 355 const { redirectUrl } = await server.login.logout({ token: resLogin.access_token })
394 356 expect(redirectUrl).to.equal('https://example.com/redirectUrl')
395 expect(resLogout.body.redirectUrl).to.equal('https://example.com/redirectUrl')
396 }) 357 })
397 358
398 it('Should call the plugin\'s onLogout method with the request', async function () { 359 it('Should call the plugin\'s onLogout method with the request', async function () {
@@ -403,8 +364,7 @@ describe('Test external auth plugins', function () {
403 username: 'cid' 364 username: 'cid'
404 }) 365 })
405 366
406 const resLogout = await logout(server.url, resLogin.access_token) 367 const { redirectUrl } = await server.login.logout({ token: resLogin.access_token })
407 368 expect(redirectUrl).to.equal('https://example.com/redirectUrl?access_token=' + resLogin.access_token)
408 expect(resLogout.body.redirectUrl).to.equal('https://example.com/redirectUrl?access_token=' + resLogin.access_token)
409 }) 369 })
410}) 370})
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index 644b41dea..c00ac8f91 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -2,192 +2,152 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { advancedVideoChannelSearch } from '@shared/extra-utils/search/video-channels'
6import { ServerConfig } from '@shared/models'
7import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
8import { 5import {
9 addVideoCommentReply, 6 cleanupTests,
10 addVideoCommentThread, 7 createMultipleServers,
11 advancedVideoPlaylistSearch,
12 advancedVideosSearch,
13 createLive,
14 createVideoPlaylist,
15 doubleFollow, 8 doubleFollow,
16 getAccountVideos, 9 FIXTURE_URLS,
17 getConfig,
18 getMyVideos,
19 getPluginTestPath,
20 getVideo,
21 getVideoChannelVideos,
22 getVideoCommentThreads,
23 getVideoPlaylist,
24 getVideosList,
25 getVideosListPagination,
26 getVideoThreadComments,
27 getVideoWithToken,
28 installPlugin,
29 makeRawRequest, 10 makeRawRequest,
30 registerUser, 11 PeerTubeServer,
12 PluginsCommand,
31 setAccessTokensToServers, 13 setAccessTokensToServers,
32 setDefaultVideoChannel, 14 setDefaultVideoChannel,
33 updateCustomSubConfig,
34 updateVideo,
35 uploadVideo,
36 uploadVideoAndGetId,
37 waitJobs 15 waitJobs
38} from '../../../shared/extra-utils' 16} from '@shared/extra-utils'
39import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' 17import { HttpStatusCode, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
40import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports'
41import {
42 VideoCommentThreadTree,
43 VideoDetails,
44 VideoImport,
45 VideoImportState,
46 VideoPlaylist,
47 VideoPlaylistPrivacy,
48 VideoPrivacy
49} from '../../../shared/models/videos'
50 18
51const expect = chai.expect 19const expect = chai.expect
52 20
53describe('Test plugin filter hooks', function () { 21describe('Test plugin filter hooks', function () {
54 let servers: ServerInfo[] 22 let servers: PeerTubeServer[]
55 let videoUUID: string 23 let videoUUID: string
56 let threadId: number 24 let threadId: number
57 25
58 before(async function () { 26 before(async function () {
59 this.timeout(60000) 27 this.timeout(60000)
60 28
61 servers = await flushAndRunMultipleServers(2) 29 servers = await createMultipleServers(2)
62 await setAccessTokensToServers(servers) 30 await setAccessTokensToServers(servers)
63 await setDefaultVideoChannel(servers) 31 await setDefaultVideoChannel(servers)
64 await doubleFollow(servers[0], servers[1]) 32 await doubleFollow(servers[0], servers[1])
65 33
66 await installPlugin({ 34 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath() })
67 url: servers[0].url, 35 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') })
68 accessToken: servers[0].accessToken,
69 path: getPluginTestPath()
70 })
71
72 await installPlugin({
73 url: servers[0].url,
74 accessToken: servers[0].accessToken,
75 path: getPluginTestPath('-filter-translations')
76 })
77 36
78 for (let i = 0; i < 10; i++) { 37 for (let i = 0; i < 10; i++) {
79 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i }) 38 await servers[0].videos.upload({ attributes: { name: 'default video ' + i } })
80 } 39 }
81 40
82 const res = await getVideosList(servers[0].url) 41 const { data } = await servers[0].videos.list()
83 videoUUID = res.body.data[0].uuid 42 videoUUID = data[0].uuid
84 43
85 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { 44 await servers[0].config.updateCustomSubConfig({
86 live: { enabled: true }, 45 newConfig: {
87 signup: { enabled: true }, 46 live: { enabled: true },
88 import: { 47 signup: { enabled: true },
89 videos: { 48 import: {
90 http: { enabled: true }, 49 videos: {
91 torrent: { enabled: true } 50 http: { enabled: true },
51 torrent: { enabled: true }
52 }
92 } 53 }
93 } 54 }
94 }) 55 })
95 }) 56 })
96 57
97 it('Should run filter:api.videos.list.params', async function () { 58 it('Should run filter:api.videos.list.params', async function () {
98 const res = await getVideosListPagination(servers[0].url, 0, 2) 59 const { data } = await servers[0].videos.list({ start: 0, count: 2 })
99 60
100 // 2 plugins do +1 to the count parameter 61 // 2 plugins do +1 to the count parameter
101 expect(res.body.data).to.have.lengthOf(4) 62 expect(data).to.have.lengthOf(4)
102 }) 63 })
103 64
104 it('Should run filter:api.videos.list.result', async function () { 65 it('Should run filter:api.videos.list.result', async function () {
105 const res = await getVideosListPagination(servers[0].url, 0, 0) 66 const { total } = await servers[0].videos.list({ start: 0, count: 0 })
106 67
107 // Plugin do +1 to the total result 68 // Plugin do +1 to the total result
108 expect(res.body.total).to.equal(11) 69 expect(total).to.equal(11)
109 }) 70 })
110 71
111 it('Should run filter:api.accounts.videos.list.params', async function () { 72 it('Should run filter:api.accounts.videos.list.params', async function () {
112 const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) 73 const { data } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
113 74
114 // 1 plugin do +1 to the count parameter 75 // 1 plugin do +1 to the count parameter
115 expect(res.body.data).to.have.lengthOf(3) 76 expect(data).to.have.lengthOf(3)
116 }) 77 })
117 78
118 it('Should run filter:api.accounts.videos.list.result', async function () { 79 it('Should run filter:api.accounts.videos.list.result', async function () {
119 const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) 80 const { total } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
120 81
121 // Plugin do +2 to the total result 82 // Plugin do +2 to the total result
122 expect(res.body.total).to.equal(12) 83 expect(total).to.equal(12)
123 }) 84 })
124 85
125 it('Should run filter:api.video-channels.videos.list.params', async function () { 86 it('Should run filter:api.video-channels.videos.list.params', async function () {
126 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) 87 const { data } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
127 88
128 // 1 plugin do +3 to the count parameter 89 // 1 plugin do +3 to the count parameter
129 expect(res.body.data).to.have.lengthOf(5) 90 expect(data).to.have.lengthOf(5)
130 }) 91 })
131 92
132 it('Should run filter:api.video-channels.videos.list.result', async function () { 93 it('Should run filter:api.video-channels.videos.list.result', async function () {
133 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) 94 const { total } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
134 95
135 // Plugin do +3 to the total result 96 // Plugin do +3 to the total result
136 expect(res.body.total).to.equal(13) 97 expect(total).to.equal(13)
137 }) 98 })
138 99
139 it('Should run filter:api.user.me.videos.list.params', async function () { 100 it('Should run filter:api.user.me.videos.list.params', async function () {
140 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) 101 const { data } = await servers[0].videos.listMyVideos({ start: 0, count: 2 })
141 102
142 // 1 plugin do +4 to the count parameter 103 // 1 plugin do +4 to the count parameter
143 expect(res.body.data).to.have.lengthOf(6) 104 expect(data).to.have.lengthOf(6)
144 }) 105 })
145 106
146 it('Should run filter:api.user.me.videos.list.result', async function () { 107 it('Should run filter:api.user.me.videos.list.result', async function () {
147 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2) 108 const { total } = await servers[0].videos.listMyVideos({ start: 0, count: 2 })
148 109
149 // Plugin do +4 to the total result 110 // Plugin do +4 to the total result
150 expect(res.body.total).to.equal(14) 111 expect(total).to.equal(14)
151 }) 112 })
152 113
153 it('Should run filter:api.video.get.result', async function () { 114 it('Should run filter:api.video.get.result', async function () {
154 const res = await getVideo(servers[0].url, videoUUID) 115 const video = await servers[0].videos.get({ id: videoUUID })
155 116 expect(video.name).to.contain('<3')
156 expect(res.body.name).to.contain('<3')
157 }) 117 })
158 118
159 it('Should run filter:api.video.upload.accept.result', async function () { 119 it('Should run filter:api.video.upload.accept.result', async function () {
160 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, HttpStatusCode.FORBIDDEN_403) 120 await servers[0].videos.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
161 }) 121 })
162 122
163 it('Should run filter:api.live-video.create.accept.result', async function () { 123 it('Should run filter:api.live-video.create.accept.result', async function () {
164 const attributes = { 124 const attributes = {
165 name: 'video with bad word', 125 name: 'video with bad word',
166 privacy: VideoPrivacy.PUBLIC, 126 privacy: VideoPrivacy.PUBLIC,
167 channelId: servers[0].videoChannel.id 127 channelId: servers[0].store.channel.id
168 } 128 }
169 129
170 await createLive(servers[0].url, servers[0].accessToken, attributes, HttpStatusCode.FORBIDDEN_403) 130 await servers[0].live.create({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
171 }) 131 })
172 132
173 it('Should run filter:api.video.pre-import-url.accept.result', async function () { 133 it('Should run filter:api.video.pre-import-url.accept.result', async function () {
174 const baseAttributes = { 134 const attributes = {
175 name: 'normal title', 135 name: 'normal title',
176 privacy: VideoPrivacy.PUBLIC, 136 privacy: VideoPrivacy.PUBLIC,
177 channelId: servers[0].videoChannel.id, 137 channelId: servers[0].store.channel.id,
178 targetUrl: getGoodVideoUrl() + 'bad' 138 targetUrl: FIXTURE_URLS.goodVideo + 'bad'
179 } 139 }
180 await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403) 140 await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
181 }) 141 })
182 142
183 it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { 143 it('Should run filter:api.video.pre-import-torrent.accept.result', async function () {
184 const baseAttributes = { 144 const attributes = {
185 name: 'bad torrent', 145 name: 'bad torrent',
186 privacy: VideoPrivacy.PUBLIC, 146 privacy: VideoPrivacy.PUBLIC,
187 channelId: servers[0].videoChannel.id, 147 channelId: servers[0].store.channel.id,
188 torrentfile: 'video-720p.torrent' as any 148 torrentfile: 'video-720p.torrent' as any
189 } 149 }
190 await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403) 150 await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
191 }) 151 })
192 152
193 it('Should run filter:api.video.post-import-url.accept.result', async function () { 153 it('Should run filter:api.video.post-import-url.accept.result', async function () {
@@ -196,21 +156,21 @@ describe('Test plugin filter hooks', function () {
196 let videoImportId: number 156 let videoImportId: number
197 157
198 { 158 {
199 const baseAttributes = { 159 const attributes = {
200 name: 'title with bad word', 160 name: 'title with bad word',
201 privacy: VideoPrivacy.PUBLIC, 161 privacy: VideoPrivacy.PUBLIC,
202 channelId: servers[0].videoChannel.id, 162 channelId: servers[0].store.channel.id,
203 targetUrl: getGoodVideoUrl() 163 targetUrl: FIXTURE_URLS.goodVideo
204 } 164 }
205 const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) 165 const body = await servers[0].imports.importVideo({ attributes })
206 videoImportId = res.body.id 166 videoImportId = body.id
207 } 167 }
208 168
209 await waitJobs(servers) 169 await waitJobs(servers)
210 170
211 { 171 {
212 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) 172 const body = await servers[0].imports.getMyVideoImports()
213 const videoImports = res.body.data as VideoImport[] 173 const videoImports = body.data
214 174
215 const videoImport = videoImports.find(i => i.id === videoImportId) 175 const videoImport = videoImports.find(i => i.id === videoImportId)
216 176
@@ -225,21 +185,20 @@ describe('Test plugin filter hooks', function () {
225 let videoImportId: number 185 let videoImportId: number
226 186
227 { 187 {
228 const baseAttributes = { 188 const attributes = {
229 name: 'title with bad word', 189 name: 'title with bad word',
230 privacy: VideoPrivacy.PUBLIC, 190 privacy: VideoPrivacy.PUBLIC,
231 channelId: servers[0].videoChannel.id, 191 channelId: servers[0].store.channel.id,
232 torrentfile: 'video-720p.torrent' as any 192 torrentfile: 'video-720p.torrent' as any
233 } 193 }
234 const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) 194 const body = await servers[0].imports.importVideo({ attributes })
235 videoImportId = res.body.id 195 videoImportId = body.id
236 } 196 }
237 197
238 await waitJobs(servers) 198 await waitJobs(servers)
239 199
240 { 200 {
241 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) 201 const { data: videoImports } = await servers[0].imports.getMyVideoImports()
242 const videoImports = res.body.data as VideoImport[]
243 202
244 const videoImport = videoImports.find(i => i.id === videoImportId) 203 const videoImport = videoImports.find(i => i.id === videoImportId)
245 204
@@ -249,60 +208,63 @@ describe('Test plugin filter hooks', function () {
249 }) 208 })
250 209
251 it('Should run filter:api.video-thread.create.accept.result', async function () { 210 it('Should run filter:api.video-thread.create.accept.result', async function () {
252 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', HttpStatusCode.FORBIDDEN_403) 211 await servers[0].comments.createThread({
212 videoId: videoUUID,
213 text: 'comment with bad word',
214 expectedStatus: HttpStatusCode.FORBIDDEN_403
215 })
253 }) 216 })
254 217
255 it('Should run filter:api.video-comment-reply.create.accept.result', async function () { 218 it('Should run filter:api.video-comment-reply.create.accept.result', async function () {
256 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread') 219 const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
257 threadId = res.body.comment.id 220 threadId = created.id
258 221
259 await addVideoCommentReply( 222 await servers[0].comments.addReply({
260 servers[0].url, 223 videoId: videoUUID,
261 servers[0].accessToken, 224 toCommentId: threadId,
262 videoUUID, 225 text: 'comment with bad word',
263 threadId, 226 expectedStatus: HttpStatusCode.FORBIDDEN_403
264 'comment with bad word', 227 })
265 HttpStatusCode.FORBIDDEN_403 228 await servers[0].comments.addReply({
266 ) 229 videoId: videoUUID,
267 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with good word', HttpStatusCode.OK_200) 230 toCommentId: threadId,
231 text: 'comment with good word',
232 expectedStatus: HttpStatusCode.OK_200
233 })
268 }) 234 })
269 235
270 it('Should run filter:api.video-threads.list.params', async function () { 236 it('Should run filter:api.video-threads.list.params', async function () {
271 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) 237 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
272 238
273 // our plugin do +1 to the count parameter 239 // our plugin do +1 to the count parameter
274 expect(res.body.data).to.have.lengthOf(1) 240 expect(data).to.have.lengthOf(1)
275 }) 241 })
276 242
277 it('Should run filter:api.video-threads.list.result', async function () { 243 it('Should run filter:api.video-threads.list.result', async function () {
278 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) 244 const { total } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
279 245
280 // Plugin do +1 to the total result 246 // Plugin do +1 to the total result
281 expect(res.body.total).to.equal(2) 247 expect(total).to.equal(2)
282 }) 248 })
283 249
284 it('Should run filter:api.video-thread-comments.list.params') 250 it('Should run filter:api.video-thread-comments.list.params')
285 251
286 it('Should run filter:api.video-thread-comments.list.result', async function () { 252 it('Should run filter:api.video-thread-comments.list.result', async function () {
287 const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId) 253 const thread = await servers[0].comments.getThread({ videoId: videoUUID, threadId })
288 254
289 const thread = res.body as VideoCommentThreadTree
290 expect(thread.comment.text.endsWith(' <3')).to.be.true 255 expect(thread.comment.text.endsWith(' <3')).to.be.true
291 }) 256 })
292 257
293 describe('Should run filter:video.auto-blacklist.result', function () { 258 describe('Should run filter:video.auto-blacklist.result', function () {
294 259
295 async function checkIsBlacklisted (oldRes: any, value: boolean) { 260 async function checkIsBlacklisted (id: number | string, value: boolean) {
296 const videoId = oldRes.body.video.uuid 261 const video = await servers[0].videos.getWithToken({ id })
297
298 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoId)
299 const video: VideoDetails = res.body
300 expect(video.blacklisted).to.equal(value) 262 expect(video.blacklisted).to.equal(value)
301 } 263 }
302 264
303 it('Should blacklist on upload', async function () { 265 it('Should blacklist on upload', async function () {
304 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) 266 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video please blacklist me' } })
305 await checkIsBlacklisted(res, true) 267 await checkIsBlacklisted(uuid, true)
306 }) 268 })
307 269
308 it('Should blacklist on import', async function () { 270 it('Should blacklist on import', async function () {
@@ -310,60 +272,62 @@ describe('Test plugin filter hooks', function () {
310 272
311 const attributes = { 273 const attributes = {
312 name: 'video please blacklist me', 274 name: 'video please blacklist me',
313 targetUrl: getGoodVideoUrl(), 275 targetUrl: FIXTURE_URLS.goodVideo,
314 channelId: servers[0].videoChannel.id 276 channelId: servers[0].store.channel.id
315 } 277 }
316 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) 278 const body = await servers[0].imports.importVideo({ attributes })
317 await checkIsBlacklisted(res, true) 279 await checkIsBlacklisted(body.video.uuid, true)
318 }) 280 })
319 281
320 it('Should blacklist on update', async function () { 282 it('Should blacklist on update', async function () {
321 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) 283 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' } })
322 const videoId = res.body.video.uuid 284 await checkIsBlacklisted(uuid, false)
323 await checkIsBlacklisted(res, false)
324 285
325 await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) 286 await servers[0].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } })
326 await checkIsBlacklisted(res, true) 287 await checkIsBlacklisted(uuid, true)
327 }) 288 })
328 289
329 it('Should blacklist on remote upload', async function () { 290 it('Should blacklist on remote upload', async function () {
330 this.timeout(120000) 291 this.timeout(120000)
331 292
332 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) 293 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'remote please blacklist me' } })
333 await waitJobs(servers) 294 await waitJobs(servers)
334 295
335 await checkIsBlacklisted(res, true) 296 await checkIsBlacklisted(uuid, true)
336 }) 297 })
337 298
338 it('Should blacklist on remote update', async function () { 299 it('Should blacklist on remote update', async function () {
339 this.timeout(120000) 300 this.timeout(120000)
340 301
341 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' }) 302 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video' } })
342 await waitJobs(servers) 303 await waitJobs(servers)
343 304
344 const videoId = res.body.video.uuid 305 await checkIsBlacklisted(uuid, false)
345 await checkIsBlacklisted(res, false)
346 306
347 await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) 307 await servers[1].videos.update({ id: uuid, attributes: { name: 'please blacklist me' } })
348 await waitJobs(servers) 308 await waitJobs(servers)
349 309
350 await checkIsBlacklisted(res, true) 310 await checkIsBlacklisted(uuid, true)
351 }) 311 })
352 }) 312 })
353 313
354 describe('Should run filter:api.user.signup.allowed.result', function () { 314 describe('Should run filter:api.user.signup.allowed.result', function () {
355 315
356 it('Should run on config endpoint', async function () { 316 it('Should run on config endpoint', async function () {
357 const res = await getConfig(servers[0].url) 317 const body = await servers[0].config.getConfig()
358 expect((res.body as ServerConfig).signup.allowed).to.be.true 318 expect(body.signup.allowed).to.be.true
359 }) 319 })
360 320
361 it('Should allow a signup', async function () { 321 it('Should allow a signup', async function () {
362 await registerUser(servers[0].url, 'john', 'password') 322 await servers[0].users.register({ username: 'john', password: 'password' })
363 }) 323 })
364 324
365 it('Should not allow a signup', async function () { 325 it('Should not allow a signup', async function () {
366 const res = await registerUser(servers[0].url, 'jma', 'password', HttpStatusCode.FORBIDDEN_403) 326 const res = await servers[0].users.register({
327 username: 'jma',
328 password: 'password',
329 expectedStatus: HttpStatusCode.FORBIDDEN_403
330 })
367 331
368 expect(res.body.error).to.equal('No jma') 332 expect(res.body.error).to.equal('No jma')
369 }) 333 })
@@ -375,13 +339,15 @@ describe('Test plugin filter hooks', function () {
375 before(async function () { 339 before(async function () {
376 this.timeout(120000) 340 this.timeout(120000)
377 341
378 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { 342 await servers[0].config.updateCustomSubConfig({
379 transcoding: { 343 newConfig: {
380 webtorrent: { 344 transcoding: {
381 enabled: true 345 webtorrent: {
382 }, 346 enabled: true
383 hls: { 347 },
384 enabled: true 348 hls: {
349 enabled: true
350 }
385 } 351 }
386 } 352 }
387 }) 353 })
@@ -389,15 +355,14 @@ describe('Test plugin filter hooks', function () {
389 const uuids: string[] = [] 355 const uuids: string[] = []
390 356
391 for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) { 357 for (const name of [ 'bad torrent', 'bad file', 'bad playlist file' ]) {
392 const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid 358 const uuid = (await servers[0].videos.quickUpload({ name: name })).uuid
393 uuids.push(uuid) 359 uuids.push(uuid)
394 } 360 }
395 361
396 await waitJobs(servers) 362 await waitJobs(servers)
397 363
398 for (const uuid of uuids) { 364 for (const uuid of uuids) {
399 const res = await getVideo(servers[0].url, uuid) 365 downloadVideos.push(await servers[0].videos.get({ id: uuid }))
400 downloadVideos.push(res.body)
401 } 366 }
402 }) 367 })
403 368
@@ -437,25 +402,26 @@ describe('Test plugin filter hooks', function () {
437 before(async function () { 402 before(async function () {
438 this.timeout(60000) 403 this.timeout(60000)
439 404
440 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { 405 await servers[0].config.updateCustomSubConfig({
441 transcoding: { 406 newConfig: {
442 enabled: false 407 transcoding: {
408 enabled: false
409 }
443 } 410 }
444 }) 411 })
445 412
446 for (const name of [ 'bad embed', 'good embed' ]) { 413 for (const name of [ 'bad embed', 'good embed' ]) {
447 { 414 {
448 const uuid = (await uploadVideoAndGetId({ server: servers[0], videoName: name })).uuid 415 const uuid = (await servers[0].videos.quickUpload({ name: name })).uuid
449 const res = await getVideo(servers[0].url, uuid) 416 embedVideos.push(await servers[0].videos.get({ id: uuid }))
450 embedVideos.push(res.body)
451 } 417 }
452 418
453 { 419 {
454 const playlistAttrs = { displayName: name, videoChannelId: servers[0].videoChannel.id, privacy: VideoPlaylistPrivacy.PUBLIC } 420 const attributes = { displayName: name, videoChannelId: servers[0].store.channel.id, privacy: VideoPlaylistPrivacy.PUBLIC }
455 const res = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs }) 421 const { id } = await servers[0].playlists.create({ attributes })
456 422
457 const resPlaylist = await getVideoPlaylist(servers[0].url, res.body.videoPlaylist.id) 423 const playlist = await servers[0].playlists.get({ playlistId: id })
458 embedPlaylists.push(resPlaylist.body) 424 embedPlaylists.push(playlist)
459 } 425 }
460 } 426 }
461 }) 427 })
@@ -474,78 +440,92 @@ describe('Test plugin filter hooks', function () {
474 describe('Search filters', function () { 440 describe('Search filters', function () {
475 441
476 before(async function () { 442 before(async function () {
477 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { 443 await servers[0].config.updateCustomSubConfig({
478 search: { 444 newConfig: {
479 searchIndex: { 445 search: {
480 enabled: true, 446 searchIndex: {
481 isDefaultSearch: false, 447 enabled: true,
482 disableLocalSearch: false 448 isDefaultSearch: false,
449 disableLocalSearch: false
450 }
483 } 451 }
484 } 452 }
485 }) 453 })
486 }) 454 })
487 455
488 it('Should run filter:api.search.videos.local.list.{params,result}', async function () { 456 it('Should run filter:api.search.videos.local.list.{params,result}', async function () {
489 await advancedVideosSearch(servers[0].url, { 457 await servers[0].search.advancedVideoSearch({
490 search: 'Sun Quan' 458 search: {
459 search: 'Sun Quan'
460 }
491 }) 461 })
492 462
493 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1) 463 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1)
494 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.result', 1) 464 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1)
495 }) 465 })
496 466
497 it('Should run filter:api.search.videos.index.list.{params,result}', async function () { 467 it('Should run filter:api.search.videos.index.list.{params,result}', async function () {
498 await advancedVideosSearch(servers[0].url, { 468 await servers[0].search.advancedVideoSearch({
499 search: 'Sun Quan', 469 search: {
500 searchTarget: 'search-index' 470 search: 'Sun Quan',
471 searchTarget: 'search-index'
472 }
501 }) 473 })
502 474
503 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1) 475 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.params', 1)
504 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.result', 1) 476 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.local.list.result', 1)
505 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.index.list.params', 1) 477 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.index.list.params', 1)
506 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.index.list.result', 1) 478 await servers[0].servers.waitUntilLog('Run hook filter:api.search.videos.index.list.result', 1)
507 }) 479 })
508 480
509 it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () { 481 it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () {
510 await advancedVideoChannelSearch(servers[0].url, { 482 await servers[0].search.advancedChannelSearch({
511 search: 'Sun Ce' 483 search: {
484 search: 'Sun Ce'
485 }
512 }) 486 })
513 487
514 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1) 488 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1)
515 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.result', 1) 489 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1)
516 }) 490 })
517 491
518 it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () { 492 it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () {
519 await advancedVideoChannelSearch(servers[0].url, { 493 await servers[0].search.advancedChannelSearch({
520 search: 'Sun Ce', 494 search: {
521 searchTarget: 'search-index' 495 search: 'Sun Ce',
496 searchTarget: 'search-index'
497 }
522 }) 498 })
523 499
524 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1) 500 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.params', 1)
525 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.result', 1) 501 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.local.list.result', 1)
526 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.index.list.params', 1) 502 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.index.list.params', 1)
527 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.index.list.result', 1) 503 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-channels.index.list.result', 1)
528 }) 504 })
529 505
530 it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () { 506 it('Should run filter:api.search.video-playlists.local.list.{params,result}', async function () {
531 await advancedVideoPlaylistSearch(servers[0].url, { 507 await servers[0].search.advancedPlaylistSearch({
532 search: 'Sun Jian' 508 search: {
509 search: 'Sun Jian'
510 }
533 }) 511 })
534 512
535 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1) 513 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1)
536 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.result', 1) 514 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1)
537 }) 515 })
538 516
539 it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () { 517 it('Should run filter:api.search.video-playlists.index.list.{params,result}', async function () {
540 await advancedVideoPlaylistSearch(servers[0].url, { 518 await servers[0].search.advancedPlaylistSearch({
541 search: 'Sun Jian', 519 search: {
542 searchTarget: 'search-index' 520 search: 'Sun Jian',
521 searchTarget: 'search-index'
522 }
543 }) 523 })
544 524
545 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.params', 1) 525 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.params', 1)
546 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.local.list.result', 1) 526 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.local.list.result', 1)
547 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.index.list.params', 1) 527 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.params', 1)
548 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-playlists.index.list.result', 1) 528 await servers[0].servers.waitUntilLog('Run hook filter:api.search.video-playlists.index.list.result', 1)
549 }) 529 })
550 }) 530 })
551 531
diff --git a/server/tests/plugins/html-injection.ts b/server/tests/plugins/html-injection.ts
index 4fa8caa3a..95c0cd687 100644
--- a/server/tests/plugins/html-injection.ts
+++ b/server/tests/plugins/html-injection.ts
@@ -4,31 +4,32 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 flushAndRunServer, 7 createSingleServer,
8 getPluginsCSS,
9 installPlugin,
10 makeHTMLRequest, 8 makeHTMLRequest,
11 ServerInfo, 9 PeerTubeServer,
12 setAccessTokensToServers, 10 PluginsCommand,
13 uninstallPlugin 11 setAccessTokensToServers
14} from '../../../shared/extra-utils' 12} from '../../../shared/extra-utils'
15 13
16const expect = chai.expect 14const expect = chai.expect
17 15
18describe('Test plugins HTML injection', function () { 16describe('Test plugins HTML injection', function () {
19 let server: ServerInfo = null 17 let server: PeerTubeServer = null
18 let command: PluginsCommand
20 19
21 before(async function () { 20 before(async function () {
22 this.timeout(30000) 21 this.timeout(30000)
23 22
24 server = await flushAndRunServer(1) 23 server = await createSingleServer(1)
25 await setAccessTokensToServers([ server ]) 24 await setAccessTokensToServers([ server ])
25
26 command = server.plugins
26 }) 27 })
27 28
28 it('Should not inject global css file in HTML', async function () { 29 it('Should not inject global css file in HTML', async function () {
29 { 30 {
30 const res = await getPluginsCSS(server.url) 31 const text = await command.getCSS()
31 expect(res.text).to.be.empty 32 expect(text).to.be.empty
32 } 33 }
33 34
34 for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) { 35 for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
@@ -40,17 +41,13 @@ describe('Test plugins HTML injection', function () {
40 it('Should install a plugin and a theme', async function () { 41 it('Should install a plugin and a theme', async function () {
41 this.timeout(30000) 42 this.timeout(30000)
42 43
43 await installPlugin({ 44 await command.install({ npmName: 'peertube-plugin-hello-world' })
44 url: server.url,
45 accessToken: server.accessToken,
46 npmName: 'peertube-plugin-hello-world'
47 })
48 }) 45 })
49 46
50 it('Should have the correct global css', async function () { 47 it('Should have the correct global css', async function () {
51 { 48 {
52 const res = await getPluginsCSS(server.url) 49 const text = await command.getCSS()
53 expect(res.text).to.contain('background-color: red') 50 expect(text).to.contain('background-color: red')
54 } 51 }
55 52
56 for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) { 53 for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
@@ -60,15 +57,11 @@ describe('Test plugins HTML injection', function () {
60 }) 57 })
61 58
62 it('Should have an empty global css on uninstall', async function () { 59 it('Should have an empty global css on uninstall', async function () {
63 await uninstallPlugin({ 60 await command.uninstall({ npmName: 'peertube-plugin-hello-world' })
64 url: server.url,
65 accessToken: server.accessToken,
66 npmName: 'peertube-plugin-hello-world'
67 })
68 61
69 { 62 {
70 const res = await getPluginsCSS(server.url) 63 const text = await command.getCSS()
71 expect(res.text).to.be.empty 64 expect(text).to.be.empty
72 } 65 }
73 66
74 for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) { 67 for (const path of [ '/', '/videos/embed/1', '/video-playlists/embed/1' ]) {
diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts
index cbba638c2..fde0166f9 100644
--- a/server/tests/plugins/id-and-pass-auth.ts
+++ b/server/tests/plugins/id-and-pass-auth.ts
@@ -1,24 +1,12 @@
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 { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
5import {
6 getMyUserInformation,
7 getPluginTestPath,
8 installPlugin,
9 logout,
10 setAccessTokensToServers,
11 uninstallPlugin,
12 updateMyUser,
13 userLogin,
14 wait,
15 login, refreshToken, getConfig, updatePluginSettings, getUsersList
16} from '../../../shared/extra-utils'
17import { User, UserRole, ServerConfig } from '@shared/models'
18import { expect } from 'chai' 4import { expect } from 'chai'
5import { cleanupTests, createSingleServer, PeerTubeServer, PluginsCommand, setAccessTokensToServers, wait } from '@shared/extra-utils'
6import { HttpStatusCode, UserRole } from '@shared/models'
19 7
20describe('Test id and pass auth plugins', function () { 8describe('Test id and pass auth plugins', function () {
21 let server: ServerInfo 9 let server: PeerTubeServer
22 10
23 let crashAccessToken: string 11 let crashAccessToken: string
24 let crashRefreshToken: string 12 let crashRefreshToken: string
@@ -29,22 +17,16 @@ describe('Test id and pass auth plugins', function () {
29 before(async function () { 17 before(async function () {
30 this.timeout(30000) 18 this.timeout(30000)
31 19
32 server = await flushAndRunServer(1) 20 server = await createSingleServer(1)
33 await setAccessTokensToServers([ server ]) 21 await setAccessTokensToServers([ server ])
34 22
35 for (const suffix of [ 'one', 'two', 'three' ]) { 23 for (const suffix of [ 'one', 'two', 'three' ]) {
36 await installPlugin({ 24 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-id-pass-auth-' + suffix) })
37 url: server.url,
38 accessToken: server.accessToken,
39 path: getPluginTestPath('-id-pass-auth-' + suffix)
40 })
41 } 25 }
42 }) 26 })
43 27
44 it('Should display the correct configuration', async function () { 28 it('Should display the correct configuration', async function () {
45 const res = await getConfig(server.url) 29 const config = await server.config.getConfig()
46
47 const config: ServerConfig = res.body
48 30
49 const auths = config.plugin.registeredIdAndPassAuths 31 const auths = config.plugin.registeredIdAndPassAuths
50 expect(auths).to.have.lengthOf(8) 32 expect(auths).to.have.lengthOf(8)
@@ -56,15 +38,14 @@ describe('Test id and pass auth plugins', function () {
56 }) 38 })
57 39
58 it('Should not login', async function () { 40 it('Should not login', async function () {
59 await userLogin(server, { username: 'toto', password: 'password' }, 400) 41 await server.login.login({ user: { username: 'toto', password: 'password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
60 }) 42 })
61 43
62 it('Should login Spyro, create the user and use the token', async function () { 44 it('Should login Spyro, create the user and use the token', async function () {
63 const accessToken = await userLogin(server, { username: 'spyro', password: 'spyro password' }) 45 const accessToken = await server.login.getAccessToken({ username: 'spyro', password: 'spyro password' })
64 46
65 const res = await getMyUserInformation(server.url, accessToken) 47 const body = await server.users.getMyInfo({ token: accessToken })
66 48
67 const body: User = res.body
68 expect(body.username).to.equal('spyro') 49 expect(body.username).to.equal('spyro')
69 expect(body.account.displayName).to.equal('Spyro the Dragon') 50 expect(body.account.displayName).to.equal('Spyro the Dragon')
70 expect(body.role).to.equal(UserRole.USER) 51 expect(body.role).to.equal(UserRole.USER)
@@ -72,15 +53,14 @@ describe('Test id and pass auth plugins', function () {
72 53
73 it('Should login Crash, create the user and use the token', async function () { 54 it('Should login Crash, create the user and use the token', async function () {
74 { 55 {
75 const res = await login(server.url, server.client, { username: 'crash', password: 'crash password' }) 56 const body = await server.login.login({ user: { username: 'crash', password: 'crash password' } })
76 crashAccessToken = res.body.access_token 57 crashAccessToken = body.access_token
77 crashRefreshToken = res.body.refresh_token 58 crashRefreshToken = body.refresh_token
78 } 59 }
79 60
80 { 61 {
81 const res = await getMyUserInformation(server.url, crashAccessToken) 62 const body = await server.users.getMyInfo({ token: crashAccessToken })
82 63
83 const body: User = res.body
84 expect(body.username).to.equal('crash') 64 expect(body.username).to.equal('crash')
85 expect(body.account.displayName).to.equal('Crash Bandicoot') 65 expect(body.account.displayName).to.equal('Crash Bandicoot')
86 expect(body.role).to.equal(UserRole.MODERATOR) 66 expect(body.role).to.equal(UserRole.MODERATOR)
@@ -89,15 +69,14 @@ describe('Test id and pass auth plugins', function () {
89 69
90 it('Should login the first Laguna, create the user and use the token', async function () { 70 it('Should login the first Laguna, create the user and use the token', async function () {
91 { 71 {
92 const res = await login(server.url, server.client, { username: 'laguna', password: 'laguna password' }) 72 const body = await server.login.login({ user: { username: 'laguna', password: 'laguna password' } })
93 lagunaAccessToken = res.body.access_token 73 lagunaAccessToken = body.access_token
94 lagunaRefreshToken = res.body.refresh_token 74 lagunaRefreshToken = body.refresh_token
95 } 75 }
96 76
97 { 77 {
98 const res = await getMyUserInformation(server.url, lagunaAccessToken) 78 const body = await server.users.getMyInfo({ token: lagunaAccessToken })
99 79
100 const body: User = res.body
101 expect(body.username).to.equal('laguna') 80 expect(body.username).to.equal('laguna')
102 expect(body.account.displayName).to.equal('laguna') 81 expect(body.account.displayName).to.equal('laguna')
103 expect(body.role).to.equal(UserRole.USER) 82 expect(body.role).to.equal(UserRole.USER)
@@ -106,51 +85,47 @@ describe('Test id and pass auth plugins', function () {
106 85
107 it('Should refresh crash token, but not laguna token', async function () { 86 it('Should refresh crash token, but not laguna token', async function () {
108 { 87 {
109 const resRefresh = await refreshToken(server, crashRefreshToken) 88 const resRefresh = await server.login.refreshToken({ refreshToken: crashRefreshToken })
110 crashAccessToken = resRefresh.body.access_token 89 crashAccessToken = resRefresh.body.access_token
111 crashRefreshToken = resRefresh.body.refresh_token 90 crashRefreshToken = resRefresh.body.refresh_token
112 91
113 const res = await getMyUserInformation(server.url, crashAccessToken) 92 const body = await server.users.getMyInfo({ token: crashAccessToken })
114 const user: User = res.body 93 expect(body.username).to.equal('crash')
115 expect(user.username).to.equal('crash')
116 } 94 }
117 95
118 { 96 {
119 await refreshToken(server, lagunaRefreshToken, 400) 97 await server.login.refreshToken({ refreshToken: lagunaRefreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
120 } 98 }
121 }) 99 })
122 100
123 it('Should update Crash profile', async function () { 101 it('Should update Crash profile', async function () {
124 await updateMyUser({ 102 await server.users.updateMe({
125 url: server.url, 103 token: crashAccessToken,
126 accessToken: crashAccessToken,
127 displayName: 'Beautiful Crash', 104 displayName: 'Beautiful Crash',
128 description: 'Mutant eastern barred bandicoot' 105 description: 'Mutant eastern barred bandicoot'
129 }) 106 })
130 107
131 const res = await getMyUserInformation(server.url, crashAccessToken) 108 const body = await server.users.getMyInfo({ token: crashAccessToken })
132 109
133 const body: User = res.body
134 expect(body.account.displayName).to.equal('Beautiful Crash') 110 expect(body.account.displayName).to.equal('Beautiful Crash')
135 expect(body.account.description).to.equal('Mutant eastern barred bandicoot') 111 expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
136 }) 112 })
137 113
138 it('Should logout Crash', async function () { 114 it('Should logout Crash', async function () {
139 await logout(server.url, crashAccessToken) 115 await server.login.logout({ token: crashAccessToken })
140 }) 116 })
141 117
142 it('Should have logged out Crash', async function () { 118 it('Should have logged out Crash', async function () {
143 await waitUntilLog(server, 'On logout for auth 1 - 2') 119 await server.servers.waitUntilLog('On logout for auth 1 - 2')
144 120
145 await getMyUserInformation(server.url, crashAccessToken, 401) 121 await server.users.getMyInfo({ token: crashAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
146 }) 122 })
147 123
148 it('Should login Crash and keep the old existing profile', async function () { 124 it('Should login Crash and keep the old existing profile', async function () {
149 crashAccessToken = await userLogin(server, { username: 'crash', password: 'crash password' }) 125 crashAccessToken = await server.login.getAccessToken({ username: 'crash', password: 'crash password' })
150 126
151 const res = await getMyUserInformation(server.url, crashAccessToken) 127 const body = await server.users.getMyInfo({ token: crashAccessToken })
152 128
153 const body: User = res.body
154 expect(body.username).to.equal('crash') 129 expect(body.username).to.equal('crash')
155 expect(body.account.displayName).to.equal('Beautiful Crash') 130 expect(body.account.displayName).to.equal('Beautiful Crash')
156 expect(body.account.description).to.equal('Mutant eastern barred bandicoot') 131 expect(body.account.description).to.equal('Mutant eastern barred bandicoot')
@@ -162,39 +137,38 @@ describe('Test id and pass auth plugins', function () {
162 137
163 await wait(5000) 138 await wait(5000)
164 139
165 await getMyUserInformation(server.url, lagunaAccessToken, 401) 140 await server.users.getMyInfo({ token: lagunaAccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
166 }) 141 })
167 142
168 it('Should reject an invalid username, email, role or display name', async function () { 143 it('Should reject an invalid username, email, role or display name', async function () {
169 await userLogin(server, { username: 'ward', password: 'ward password' }, 400) 144 const command = server.login
170 await waitUntilLog(server, 'valid username')
171 145
172 await userLogin(server, { username: 'kiros', password: 'kiros password' }, 400) 146 await command.login({ user: { username: 'ward', password: 'ward password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
173 await waitUntilLog(server, 'valid display name') 147 await server.servers.waitUntilLog('valid username')
174 148
175 await userLogin(server, { username: 'raine', password: 'raine password' }, 400) 149 await command.login({ user: { username: 'kiros', password: 'kiros password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
176 await waitUntilLog(server, 'valid role') 150 await server.servers.waitUntilLog('valid display name')
177 151
178 await userLogin(server, { username: 'ellone', password: 'elonne password' }, 400) 152 await command.login({ user: { username: 'raine', password: 'raine password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
179 await waitUntilLog(server, 'valid email') 153 await server.servers.waitUntilLog('valid role')
154
155 await command.login({ user: { username: 'ellone', password: 'elonne password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
156 await server.servers.waitUntilLog('valid email')
180 }) 157 })
181 158
182 it('Should unregister spyro-auth and do not login existing Spyro', async function () { 159 it('Should unregister spyro-auth and do not login existing Spyro', async function () {
183 await updatePluginSettings({ 160 await server.plugins.updateSettings({
184 url: server.url,
185 accessToken: server.accessToken,
186 npmName: 'peertube-plugin-test-id-pass-auth-one', 161 npmName: 'peertube-plugin-test-id-pass-auth-one',
187 settings: { disableSpyro: true } 162 settings: { disableSpyro: true }
188 }) 163 })
189 164
190 await userLogin(server, { username: 'spyro', password: 'spyro password' }, 400) 165 const command = server.login
191 await userLogin(server, { username: 'spyro', password: 'fake' }, 400) 166 await command.login({ user: { username: 'spyro', password: 'spyro password' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
167 await command.login({ user: { username: 'spyro', password: 'fake' }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
192 }) 168 })
193 169
194 it('Should have disabled this auth', async function () { 170 it('Should have disabled this auth', async function () {
195 const res = await getConfig(server.url) 171 const config = await server.config.getConfig()
196
197 const config: ServerConfig = res.body
198 172
199 const auths = config.plugin.registeredIdAndPassAuths 173 const auths = config.plugin.registeredIdAndPassAuths
200 expect(auths).to.have.lengthOf(7) 174 expect(auths).to.have.lengthOf(7)
@@ -204,19 +178,16 @@ describe('Test id and pass auth plugins', function () {
204 }) 178 })
205 179
206 it('Should uninstall the plugin one and do not login existing Crash', async function () { 180 it('Should uninstall the plugin one and do not login existing Crash', async function () {
207 await uninstallPlugin({ 181 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-id-pass-auth-one' })
208 url: server.url,
209 accessToken: server.accessToken,
210 npmName: 'peertube-plugin-test-id-pass-auth-one'
211 })
212 182
213 await userLogin(server, { username: 'crash', password: 'crash password' }, 400) 183 await server.login.login({
184 user: { username: 'crash', password: 'crash password' },
185 expectedStatus: HttpStatusCode.BAD_REQUEST_400
186 })
214 }) 187 })
215 188
216 it('Should display the correct configuration', async function () { 189 it('Should display the correct configuration', async function () {
217 const res = await getConfig(server.url) 190 const config = await server.config.getConfig()
218
219 const config: ServerConfig = res.body
220 191
221 const auths = config.plugin.registeredIdAndPassAuths 192 const auths = config.plugin.registeredIdAndPassAuths
222 expect(auths).to.have.lengthOf(6) 193 expect(auths).to.have.lengthOf(6)
@@ -226,13 +197,11 @@ describe('Test id and pass auth plugins', function () {
226 }) 197 })
227 198
228 it('Should display plugin auth information in users list', async function () { 199 it('Should display plugin auth information in users list', async function () {
229 const res = await getUsersList(server.url, server.accessToken) 200 const { data } = await server.users.list()
230
231 const users: User[] = res.body.data
232 201
233 const root = users.find(u => u.username === 'root') 202 const root = data.find(u => u.username === 'root')
234 const crash = users.find(u => u.username === 'crash') 203 const crash = data.find(u => u.username === 'crash')
235 const laguna = users.find(u => u.username === 'laguna') 204 const laguna = data.find(u => u.username === 'laguna')
236 205
237 expect(root.pluginAuth).to.be.null 206 expect(root.pluginAuth).to.be.null
238 expect(crash.pluginAuth).to.equal('peertube-plugin-test-id-pass-auth-one') 207 expect(crash.pluginAuth).to.equal('peertube-plugin-test-id-pass-auth-one')
diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts
index 0296d6eb7..242994273 100644
--- a/server/tests/plugins/plugin-helpers.ts
+++ b/server/tests/plugins/plugin-helpers.ts
@@ -1,25 +1,22 @@
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 { expect } from 'chai'
4import { 5import {
5 checkVideoFilesWereRemoved, 6 checkVideoFilesWereRemoved,
7 cleanupTests,
8 createMultipleServers,
6 doubleFollow, 9 doubleFollow,
7 getPluginTestPath, 10 makeGetRequest,
8 getVideo,
9 installPlugin,
10 makePostBodyRequest, 11 makePostBodyRequest,
12 PeerTubeServer,
13 PluginsCommand,
11 setAccessTokensToServers, 14 setAccessTokensToServers,
12 uploadVideoAndGetId, 15 waitJobs
13 viewVideo, 16} from '@shared/extra-utils'
14 getVideosList, 17import { HttpStatusCode } from '@shared/models'
15 waitJobs,
16 makeGetRequest
17} from '../../../shared/extra-utils'
18import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
19import { expect } from 'chai'
20import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
21 18
22function postCommand (server: ServerInfo, command: string, bodyArg?: object) { 19function postCommand (server: PeerTubeServer, command: string, bodyArg?: object) {
23 const body = { command } 20 const body = { command }
24 if (bodyArg) Object.assign(body, bodyArg) 21 if (bodyArg) Object.assign(body, bodyArg)
25 22
@@ -27,54 +24,50 @@ function postCommand (server: ServerInfo, command: string, bodyArg?: object) {
27 url: server.url, 24 url: server.url,
28 path: '/plugins/test-four/router/commander', 25 path: '/plugins/test-four/router/commander',
29 fields: body, 26 fields: body,
30 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 27 expectedStatus: HttpStatusCode.NO_CONTENT_204
31 }) 28 })
32} 29}
33 30
34describe('Test plugin helpers', function () { 31describe('Test plugin helpers', function () {
35 let servers: ServerInfo[] 32 let servers: PeerTubeServer[]
36 33
37 before(async function () { 34 before(async function () {
38 this.timeout(60000) 35 this.timeout(60000)
39 36
40 servers = await flushAndRunMultipleServers(2) 37 servers = await createMultipleServers(2)
41 await setAccessTokensToServers(servers) 38 await setAccessTokensToServers(servers)
42 39
43 await doubleFollow(servers[0], servers[1]) 40 await doubleFollow(servers[0], servers[1])
44 41
45 await installPlugin({ 42 await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-four') })
46 url: servers[0].url,
47 accessToken: servers[0].accessToken,
48 path: getPluginTestPath('-four')
49 })
50 }) 43 })
51 44
52 describe('Logger', function () { 45 describe('Logger', function () {
53 46
54 it('Should have logged things', async function () { 47 it('Should have logged things', async function () {
55 await waitUntilLog(servers[0], 'localhost:' + servers[0].port + ' peertube-plugin-test-four', 1, false) 48 await servers[0].servers.waitUntilLog('localhost:' + servers[0].port + ' peertube-plugin-test-four', 1, false)
56 await waitUntilLog(servers[0], 'Hello world from plugin four', 1) 49 await servers[0].servers.waitUntilLog('Hello world from plugin four', 1)
57 }) 50 })
58 }) 51 })
59 52
60 describe('Database', function () { 53 describe('Database', function () {
61 54
62 it('Should have made a query', async function () { 55 it('Should have made a query', async function () {
63 await waitUntilLog(servers[0], `root email is admin${servers[0].internalServerNumber}@example.com`) 56 await servers[0].servers.waitUntilLog(`root email is admin${servers[0].internalServerNumber}@example.com`)
64 }) 57 })
65 }) 58 })
66 59
67 describe('Config', function () { 60 describe('Config', function () {
68 61
69 it('Should have the correct webserver url', async function () { 62 it('Should have the correct webserver url', async function () {
70 await waitUntilLog(servers[0], `server url is http://localhost:${servers[0].port}`) 63 await servers[0].servers.waitUntilLog(`server url is http://localhost:${servers[0].port}`)
71 }) 64 })
72 65
73 it('Should have the correct config', async function () { 66 it('Should have the correct config', async function () {
74 const res = await makeGetRequest({ 67 const res = await makeGetRequest({
75 url: servers[0].url, 68 url: servers[0].url,
76 path: '/plugins/test-four/router/server-config', 69 path: '/plugins/test-four/router/server-config',
77 statusCodeExpected: HttpStatusCode.OK_200 70 expectedStatus: HttpStatusCode.OK_200
78 }) 71 })
79 72
80 expect(res.body.serverConfig).to.exist 73 expect(res.body.serverConfig).to.exist
@@ -85,7 +78,7 @@ describe('Test plugin helpers', function () {
85 describe('Server', function () { 78 describe('Server', function () {
86 79
87 it('Should get the server actor', async function () { 80 it('Should get the server actor', async function () {
88 await waitUntilLog(servers[0], 'server actor name is peertube') 81 await servers[0].servers.waitUntilLog('server actor name is peertube')
89 }) 82 })
90 }) 83 })
91 84
@@ -95,7 +88,7 @@ describe('Test plugin helpers', function () {
95 const res = await makeGetRequest({ 88 const res = await makeGetRequest({
96 url: servers[0].url, 89 url: servers[0].url,
97 path: '/plugins/test-four/router/static-route', 90 path: '/plugins/test-four/router/static-route',
98 statusCodeExpected: HttpStatusCode.OK_200 91 expectedStatus: HttpStatusCode.OK_200
99 }) 92 })
100 93
101 expect(res.body.staticRoute).to.equal('/plugins/test-four/0.0.1/static/') 94 expect(res.body.staticRoute).to.equal('/plugins/test-four/0.0.1/static/')
@@ -107,7 +100,7 @@ describe('Test plugin helpers', function () {
107 const res = await makeGetRequest({ 100 const res = await makeGetRequest({
108 url: servers[0].url, 101 url: servers[0].url,
109 path: baseRouter + 'router-route', 102 path: baseRouter + 'router-route',
110 statusCodeExpected: HttpStatusCode.OK_200 103 expectedStatus: HttpStatusCode.OK_200
111 }) 104 })
112 105
113 expect(res.body.routerRoute).to.equal(baseRouter) 106 expect(res.body.routerRoute).to.equal(baseRouter)
@@ -120,7 +113,7 @@ describe('Test plugin helpers', function () {
120 await makeGetRequest({ 113 await makeGetRequest({
121 url: servers[0].url, 114 url: servers[0].url,
122 path: '/plugins/test-four/router/user', 115 path: '/plugins/test-four/router/user',
123 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 116 expectedStatus: HttpStatusCode.NOT_FOUND_404
124 }) 117 })
125 }) 118 })
126 119
@@ -129,7 +122,7 @@ describe('Test plugin helpers', function () {
129 url: servers[0].url, 122 url: servers[0].url,
130 token: servers[0].accessToken, 123 token: servers[0].accessToken,
131 path: '/plugins/test-four/router/user', 124 path: '/plugins/test-four/router/user',
132 statusCodeExpected: HttpStatusCode.OK_200 125 expectedStatus: HttpStatusCode.OK_200
133 }) 126 })
134 127
135 expect(res.body.username).to.equal('root') 128 expect(res.body.username).to.equal('root')
@@ -147,59 +140,54 @@ describe('Test plugin helpers', function () {
147 this.timeout(60000) 140 this.timeout(60000)
148 141
149 { 142 {
150 const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' }) 143 const res = await servers[0].videos.quickUpload({ name: 'video server 1' })
151 videoUUIDServer1 = res.uuid 144 videoUUIDServer1 = res.uuid
152 } 145 }
153 146
154 { 147 {
155 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' }) 148 await servers[1].videos.quickUpload({ name: 'video server 2' })
156 } 149 }
157 150
158 await waitJobs(servers) 151 await waitJobs(servers)
159 152
160 const res = await getVideosList(servers[0].url) 153 const { data } = await servers[0].videos.list()
161 const videos = res.body.data
162 154
163 expect(videos).to.have.lengthOf(2) 155 expect(data).to.have.lengthOf(2)
164 }) 156 })
165 157
166 it('Should mute server 2', async function () { 158 it('Should mute server 2', async function () {
167 this.timeout(10000) 159 this.timeout(10000)
168 await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` }) 160 await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` })
169 161
170 const res = await getVideosList(servers[0].url) 162 const { data } = await servers[0].videos.list()
171 const videos = res.body.data
172 163
173 expect(videos).to.have.lengthOf(1) 164 expect(data).to.have.lengthOf(1)
174 expect(videos[0].name).to.equal('video server 1') 165 expect(data[0].name).to.equal('video server 1')
175 }) 166 })
176 167
177 it('Should unmute server 2', async function () { 168 it('Should unmute server 2', async function () {
178 await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` }) 169 await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` })
179 170
180 const res = await getVideosList(servers[0].url) 171 const { data } = await servers[0].videos.list()
181 const videos = res.body.data
182 172
183 expect(videos).to.have.lengthOf(2) 173 expect(data).to.have.lengthOf(2)
184 }) 174 })
185 175
186 it('Should mute account of server 2', async function () { 176 it('Should mute account of server 2', async function () {
187 await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` }) 177 await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` })
188 178
189 const res = await getVideosList(servers[0].url) 179 const { data } = await servers[0].videos.list()
190 const videos = res.body.data
191 180
192 expect(videos).to.have.lengthOf(1) 181 expect(data).to.have.lengthOf(1)
193 expect(videos[0].name).to.equal('video server 1') 182 expect(data[0].name).to.equal('video server 1')
194 }) 183 })
195 184
196 it('Should unmute account of server 2', async function () { 185 it('Should unmute account of server 2', async function () {
197 await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` }) 186 await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` })
198 187
199 const res = await getVideosList(servers[0].url) 188 const { data } = await servers[0].videos.list()
200 const videos = res.body.data
201 189
202 expect(videos).to.have.lengthOf(2) 190 expect(data).to.have.lengthOf(2)
203 }) 191 })
204 192
205 it('Should blacklist video', async function () { 193 it('Should blacklist video', async function () {
@@ -210,11 +198,10 @@ describe('Test plugin helpers', function () {
210 await waitJobs(servers) 198 await waitJobs(servers)
211 199
212 for (const server of servers) { 200 for (const server of servers) {
213 const res = await getVideosList(server.url) 201 const { data } = await server.videos.list()
214 const videos = res.body.data
215 202
216 expect(videos).to.have.lengthOf(1) 203 expect(data).to.have.lengthOf(1)
217 expect(videos[0].name).to.equal('video server 2') 204 expect(data[0].name).to.equal('video server 2')
218 } 205 }
219 }) 206 })
220 207
@@ -226,10 +213,9 @@ describe('Test plugin helpers', function () {
226 await waitJobs(servers) 213 await waitJobs(servers)
227 214
228 for (const server of servers) { 215 for (const server of servers) {
229 const res = await getVideosList(server.url) 216 const { data } = await server.videos.list()
230 const videos = res.body.data
231 217
232 expect(videos).to.have.lengthOf(2) 218 expect(data).to.have.lengthOf(2)
233 } 219 }
234 }) 220 })
235 }) 221 })
@@ -238,7 +224,7 @@ describe('Test plugin helpers', function () {
238 let videoUUID: string 224 let videoUUID: string
239 225
240 before(async () => { 226 before(async () => {
241 const res = await uploadVideoAndGetId({ server: servers[0], videoName: 'video1' }) 227 const res = await servers[0].videos.quickUpload({ name: 'video1' })
242 videoUUID = res.uuid 228 videoUUID = res.uuid
243 }) 229 })
244 230
@@ -246,25 +232,25 @@ describe('Test plugin helpers', function () {
246 this.timeout(40000) 232 this.timeout(40000)
247 233
248 // Should not throw -> video exists 234 // Should not throw -> video exists
249 await getVideo(servers[0].url, videoUUID) 235 await servers[0].videos.get({ id: videoUUID })
250 // Should delete the video 236 // Should delete the video
251 await viewVideo(servers[0].url, videoUUID) 237 await servers[0].videos.view({ id: videoUUID })
252 238
253 await waitUntilLog(servers[0], 'Video deleted by plugin four.') 239 await servers[0].servers.waitUntilLog('Video deleted by plugin four.')
254 240
255 try { 241 try {
256 // Should throw because the video should have been deleted 242 // Should throw because the video should have been deleted
257 await getVideo(servers[0].url, videoUUID) 243 await servers[0].videos.get({ id: videoUUID })
258 throw new Error('Video exists') 244 throw new Error('Video exists')
259 } catch (err) { 245 } catch (err) {
260 if (err.message.includes('exists')) throw err 246 if (err.message.includes('exists')) throw err
261 } 247 }
262 248
263 await checkVideoFilesWereRemoved(videoUUID, servers[0].internalServerNumber) 249 await checkVideoFilesWereRemoved(videoUUID, servers[0])
264 }) 250 })
265 251
266 it('Should have fetched the video by URL', async function () { 252 it('Should have fetched the video by URL', async function () {
267 await waitUntilLog(servers[0], `video from DB uuid is ${videoUUID}`) 253 await servers[0].servers.waitUntilLog(`video from DB uuid is ${videoUUID}`)
268 }) 254 })
269 }) 255 })
270 256
diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts
index 24e6a1e83..b1ac9e2fe 100644
--- a/server/tests/plugins/plugin-router.ts
+++ b/server/tests/plugins/plugin-router.ts
@@ -1,19 +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 { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' 4import { expect } from 'chai'
5import { 5import {
6 getPluginTestPath, 6 cleanupTests,
7 installPlugin, 7 createSingleServer,
8 makeGetRequest, 8 makeGetRequest,
9 makePostBodyRequest, 9 makePostBodyRequest,
10 setAccessTokensToServers, uninstallPlugin 10 PeerTubeServer,
11} from '../../../shared/extra-utils' 11 PluginsCommand,
12import { expect } from 'chai' 12 setAccessTokensToServers
13import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 13} from '@shared/extra-utils'
14import { HttpStatusCode } from '@shared/models'
14 15
15describe('Test plugin helpers', function () { 16describe('Test plugin helpers', function () {
16 let server: ServerInfo 17 let server: PeerTubeServer
17 const basePaths = [ 18 const basePaths = [
18 '/plugins/test-five/router/', 19 '/plugins/test-five/router/',
19 '/plugins/test-five/0.0.1/router/' 20 '/plugins/test-five/0.0.1/router/'
@@ -22,14 +23,10 @@ describe('Test plugin helpers', function () {
22 before(async function () { 23 before(async function () {
23 this.timeout(30000) 24 this.timeout(30000)
24 25
25 server = await flushAndRunServer(1) 26 server = await createSingleServer(1)
26 await setAccessTokensToServers([ server ]) 27 await setAccessTokensToServers([ server ])
27 28
28 await installPlugin({ 29 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-five') })
29 url: server.url,
30 accessToken: server.accessToken,
31 path: getPluginTestPath('-five')
32 })
33 }) 30 })
34 31
35 it('Should answer "pong"', async function () { 32 it('Should answer "pong"', async function () {
@@ -37,7 +34,7 @@ describe('Test plugin helpers', function () {
37 const res = await makeGetRequest({ 34 const res = await makeGetRequest({
38 url: server.url, 35 url: server.url,
39 path: path + 'ping', 36 path: path + 'ping',
40 statusCodeExpected: HttpStatusCode.OK_200 37 expectedStatus: HttpStatusCode.OK_200
41 }) 38 })
42 39
43 expect(res.body.message).to.equal('pong') 40 expect(res.body.message).to.equal('pong')
@@ -50,7 +47,7 @@ describe('Test plugin helpers', function () {
50 url: server.url, 47 url: server.url,
51 path: path + 'is-authenticated', 48 path: path + 'is-authenticated',
52 token: server.accessToken, 49 token: server.accessToken,
53 statusCodeExpected: 200 50 expectedStatus: 200
54 }) 51 })
55 52
56 expect(res.body.isAuthenticated).to.equal(true) 53 expect(res.body.isAuthenticated).to.equal(true)
@@ -58,7 +55,7 @@ describe('Test plugin helpers', function () {
58 const secRes = await makeGetRequest({ 55 const secRes = await makeGetRequest({
59 url: server.url, 56 url: server.url,
60 path: path + 'is-authenticated', 57 path: path + 'is-authenticated',
61 statusCodeExpected: 200 58 expectedStatus: 200
62 }) 59 })
63 60
64 expect(secRes.body.isAuthenticated).to.equal(false) 61 expect(secRes.body.isAuthenticated).to.equal(false)
@@ -77,7 +74,7 @@ describe('Test plugin helpers', function () {
77 url: server.url, 74 url: server.url,
78 path: path + 'form/post/mirror', 75 path: path + 'form/post/mirror',
79 fields: body, 76 fields: body,
80 statusCodeExpected: HttpStatusCode.OK_200 77 expectedStatus: HttpStatusCode.OK_200
81 }) 78 })
82 79
83 expect(res.body).to.deep.equal(body) 80 expect(res.body).to.deep.equal(body)
@@ -85,24 +82,20 @@ describe('Test plugin helpers', function () {
85 }) 82 })
86 83
87 it('Should remove the plugin and remove the routes', async function () { 84 it('Should remove the plugin and remove the routes', async function () {
88 await uninstallPlugin({ 85 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-five' })
89 url: server.url,
90 accessToken: server.accessToken,
91 npmName: 'peertube-plugin-test-five'
92 })
93 86
94 for (const path of basePaths) { 87 for (const path of basePaths) {
95 await makeGetRequest({ 88 await makeGetRequest({
96 url: server.url, 89 url: server.url,
97 path: path + 'ping', 90 path: path + 'ping',
98 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 91 expectedStatus: HttpStatusCode.NOT_FOUND_404
99 }) 92 })
100 93
101 await makePostBodyRequest({ 94 await makePostBodyRequest({
102 url: server.url, 95 url: server.url,
103 path: path + 'ping', 96 path: path + 'ping',
104 fields: {}, 97 fields: {},
105 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 98 expectedStatus: HttpStatusCode.NOT_FOUND_404
106 }) 99 })
107 } 100 }
108 }) 101 })
diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.ts
index 3c46b2585..e20c36dba 100644
--- a/server/tests/plugins/plugin-storage.ts
+++ b/server/tests/plugins/plugin-storage.ts
@@ -4,37 +4,32 @@ import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { pathExists, readdir, readFile } from 'fs-extra' 5import { pathExists, readdir, readFile } from 'fs-extra'
6import { join } from 'path' 6import { join } from 'path'
7import { HttpStatusCode } from '@shared/core-utils'
8import { 7import {
9 buildServerDirectory, 8 cleanupTests,
10 getPluginTestPath, 9 createSingleServer,
11 installPlugin,
12 makeGetRequest, 10 makeGetRequest,
13 setAccessTokensToServers, 11 PeerTubeServer,
14 uninstallPlugin 12 PluginsCommand,
15} from '../../../shared/extra-utils' 13 setAccessTokensToServers
16import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' 14} from '@shared/extra-utils'
15import { HttpStatusCode } from '@shared/models'
17 16
18describe('Test plugin storage', function () { 17describe('Test plugin storage', function () {
19 let server: ServerInfo 18 let server: PeerTubeServer
20 19
21 before(async function () { 20 before(async function () {
22 this.timeout(30000) 21 this.timeout(30000)
23 22
24 server = await flushAndRunServer(1) 23 server = await createSingleServer(1)
25 await setAccessTokensToServers([ server ]) 24 await setAccessTokensToServers([ server ])
26 25
27 await installPlugin({ 26 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
28 url: server.url,
29 accessToken: server.accessToken,
30 path: getPluginTestPath('-six')
31 })
32 }) 27 })
33 28
34 describe('DB storage', function () { 29 describe('DB storage', function () {
35 30
36 it('Should correctly store a subkey', async function () { 31 it('Should correctly store a subkey', async function () {
37 await waitUntilLog(server, 'superkey stored value is toto') 32 await server.servers.waitUntilLog('superkey stored value is toto')
38 }) 33 })
39 }) 34 })
40 35
@@ -50,12 +45,12 @@ describe('Test plugin storage', function () {
50 } 45 }
51 46
52 before(function () { 47 before(function () {
53 dataPath = buildServerDirectory(server, 'plugins/data') 48 dataPath = server.servers.buildDirectory('plugins/data')
54 pluginDataPath = join(dataPath, 'peertube-plugin-test-six') 49 pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
55 }) 50 })
56 51
57 it('Should have created the directory on install', async function () { 52 it('Should have created the directory on install', async function () {
58 const dataPath = buildServerDirectory(server, 'plugins/data') 53 const dataPath = server.servers.buildDirectory('plugins/data')
59 const pluginDataPath = join(dataPath, 'peertube-plugin-test-six') 54 const pluginDataPath = join(dataPath, 'peertube-plugin-test-six')
60 55
61 expect(await pathExists(dataPath)).to.be.true 56 expect(await pathExists(dataPath)).to.be.true
@@ -68,7 +63,7 @@ describe('Test plugin storage', function () {
68 url: server.url, 63 url: server.url,
69 token: server.accessToken, 64 token: server.accessToken,
70 path: '/plugins/test-six/router/create-file', 65 path: '/plugins/test-six/router/create-file',
71 statusCodeExpected: HttpStatusCode.OK_200 66 expectedStatus: HttpStatusCode.OK_200
72 }) 67 })
73 68
74 const content = await getFileContent() 69 const content = await getFileContent()
@@ -76,22 +71,14 @@ describe('Test plugin storage', function () {
76 }) 71 })
77 72
78 it('Should still have the file after an uninstallation', async function () { 73 it('Should still have the file after an uninstallation', async function () {
79 await uninstallPlugin({ 74 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-six' })
80 url: server.url,
81 accessToken: server.accessToken,
82 npmName: 'peertube-plugin-test-six'
83 })
84 75
85 const content = await getFileContent() 76 const content = await getFileContent()
86 expect(content).to.equal('Prince Ali') 77 expect(content).to.equal('Prince Ali')
87 }) 78 })
88 79
89 it('Should still have the file after the reinstallation', async function () { 80 it('Should still have the file after the reinstallation', async function () {
90 await installPlugin({ 81 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-six') })
91 url: server.url,
92 accessToken: server.accessToken,
93 path: getPluginTestPath('-six')
94 })
95 82
96 const content = await getFileContent() 83 const content = await getFileContent()
97 expect(content).to.equal('Prince Ali') 84 expect(content).to.equal('Prince Ali')
diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts
index eefb2294d..0bf1fab01 100644
--- a/server/tests/plugins/plugin-transcoding.ts
+++ b/server/tests/plugins/plugin-transcoding.ts
@@ -4,77 +4,72 @@ import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { join } from 'path' 5import { join } from 'path'
6import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' 6import { getAudioStream, getVideoFileFPS, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'
7import { ServerConfig, VideoDetails, VideoPrivacy } from '@shared/models'
8import { 7import {
9 buildServerDirectory, 8 cleanupTests,
10 createLive, 9 createSingleServer,
11 getConfig, 10 PeerTubeServer,
12 getPluginTestPath, 11 PluginsCommand,
13 getVideo,
14 installPlugin,
15 sendRTMPStreamInVideo,
16 setAccessTokensToServers, 12 setAccessTokensToServers,
17 setDefaultVideoChannel, 13 setDefaultVideoChannel,
18 testFfmpegStreamError, 14 testFfmpegStreamError,
19 uninstallPlugin, 15 waitJobs
20 updateCustomSubConfig, 16} from '@shared/extra-utils'
21 uploadVideoAndGetId, 17import { VideoPrivacy } from '@shared/models'
22 waitJobs, 18
23 waitUntilLivePublished 19async function createLiveWrapper (server: PeerTubeServer) {
24} from '../../../shared/extra-utils'
25import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
26
27async function createLiveWrapper (server: ServerInfo) {
28 const liveAttributes = { 20 const liveAttributes = {
29 name: 'live video', 21 name: 'live video',
30 channelId: server.videoChannel.id, 22 channelId: server.store.channel.id,
31 privacy: VideoPrivacy.PUBLIC 23 privacy: VideoPrivacy.PUBLIC
32 } 24 }
33 25
34 const res = await createLive(server.url, server.accessToken, liveAttributes) 26 const { uuid } = await server.live.create({ fields: liveAttributes })
35 return res.body.video.uuid 27
28 return uuid
36} 29}
37 30
38function updateConf (server: ServerInfo, vodProfile: string, liveProfile: string) { 31function updateConf (server: PeerTubeServer, vodProfile: string, liveProfile: string) {
39 return updateCustomSubConfig(server.url, server.accessToken, { 32 return server.config.updateCustomSubConfig({
40 transcoding: { 33 newConfig: {
41 enabled: true,
42 profile: vodProfile,
43 hls: {
44 enabled: true
45 },
46 webtorrent: {
47 enabled: true
48 },
49 resolutions: {
50 '240p': true,
51 '360p': false,
52 '480p': false,
53 '720p': true
54 }
55 },
56 live: {
57 transcoding: { 34 transcoding: {
58 profile: liveProfile,
59 enabled: true, 35 enabled: true,
36 profile: vodProfile,
37 hls: {
38 enabled: true
39 },
40 webtorrent: {
41 enabled: true
42 },
60 resolutions: { 43 resolutions: {
61 '240p': true, 44 '240p': true,
62 '360p': false, 45 '360p': false,
63 '480p': false, 46 '480p': false,
64 '720p': true 47 '720p': true
65 } 48 }
49 },
50 live: {
51 transcoding: {
52 profile: liveProfile,
53 enabled: true,
54 resolutions: {
55 '240p': true,
56 '360p': false,
57 '480p': false,
58 '720p': true
59 }
60 }
66 } 61 }
67 } 62 }
68 }) 63 })
69} 64}
70 65
71describe('Test transcoding plugins', function () { 66describe('Test transcoding plugins', function () {
72 let server: ServerInfo 67 let server: PeerTubeServer
73 68
74 before(async function () { 69 before(async function () {
75 this.timeout(60000) 70 this.timeout(60000)
76 71
77 server = await flushAndRunServer(1) 72 server = await createSingleServer(1)
78 await setAccessTokensToServers([ server ]) 73 await setAccessTokensToServers([ server ])
79 await setDefaultVideoChannel([ server ]) 74 await setDefaultVideoChannel([ server ])
80 75
@@ -84,8 +79,7 @@ describe('Test transcoding plugins', function () {
84 describe('When using a plugin adding profiles to existing encoders', function () { 79 describe('When using a plugin adding profiles to existing encoders', function () {
85 80
86 async function checkVideoFPS (uuid: string, type: 'above' | 'below', fps: number) { 81 async function checkVideoFPS (uuid: string, type: 'above' | 'below', fps: number) {
87 const res = await getVideo(server.url, uuid) 82 const video = await server.videos.get({ id: uuid })
88 const video = res.body as VideoDetails
89 const files = video.files.concat(...video.streamingPlaylists.map(p => p.files)) 83 const files = video.files.concat(...video.streamingPlaylists.map(p => p.files))
90 84
91 for (const file of files) { 85 for (const file of files) {
@@ -109,16 +103,11 @@ describe('Test transcoding plugins', function () {
109 } 103 }
110 104
111 before(async function () { 105 before(async function () {
112 await installPlugin({ 106 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-transcoding-one') })
113 url: server.url,
114 accessToken: server.accessToken,
115 path: getPluginTestPath('-transcoding-one')
116 })
117 }) 107 })
118 108
119 it('Should have the appropriate available profiles', async function () { 109 it('Should have the appropriate available profiles', async function () {
120 const res = await getConfig(server.url) 110 const config = await server.config.getConfig()
121 const config = res.body as ServerConfig
122 111
123 expect(config.transcoding.availableProfiles).to.have.members([ 'default', 'low-vod', 'input-options-vod', 'bad-scale-vod' ]) 112 expect(config.transcoding.availableProfiles).to.have.members([ 'default', 'low-vod', 'input-options-vod', 'bad-scale-vod' ])
124 expect(config.live.transcoding.availableProfiles).to.have.members([ 'default', 'low-live', 'input-options-live', 'bad-scale-live' ]) 113 expect(config.live.transcoding.availableProfiles).to.have.members([ 'default', 'low-live', 'input-options-live', 'bad-scale-live' ])
@@ -127,7 +116,7 @@ describe('Test transcoding plugins', function () {
127 it('Should not use the plugin profile if not chosen by the admin', async function () { 116 it('Should not use the plugin profile if not chosen by the admin', async function () {
128 this.timeout(240000) 117 this.timeout(240000)
129 118
130 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid 119 const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
131 await waitJobs([ server ]) 120 await waitJobs([ server ])
132 121
133 await checkVideoFPS(videoUUID, 'above', 20) 122 await checkVideoFPS(videoUUID, 'above', 20)
@@ -138,7 +127,7 @@ describe('Test transcoding plugins', function () {
138 127
139 await updateConf(server, 'low-vod', 'default') 128 await updateConf(server, 'low-vod', 'default')
140 129
141 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid 130 const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
142 await waitJobs([ server ]) 131 await waitJobs([ server ])
143 132
144 await checkVideoFPS(videoUUID, 'below', 12) 133 await checkVideoFPS(videoUUID, 'below', 12)
@@ -149,7 +138,7 @@ describe('Test transcoding plugins', function () {
149 138
150 await updateConf(server, 'input-options-vod', 'default') 139 await updateConf(server, 'input-options-vod', 'default')
151 140
152 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid 141 const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
153 await waitJobs([ server ]) 142 await waitJobs([ server ])
154 143
155 await checkVideoFPS(videoUUID, 'below', 6) 144 await checkVideoFPS(videoUUID, 'below', 6)
@@ -160,13 +149,11 @@ describe('Test transcoding plugins', function () {
160 149
161 await updateConf(server, 'bad-scale-vod', 'default') 150 await updateConf(server, 'bad-scale-vod', 'default')
162 151
163 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid 152 const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
164 await waitJobs([ server ]) 153 await waitJobs([ server ])
165 154
166 // Transcoding failed 155 // Transcoding failed
167 const res = await getVideo(server.url, videoUUID) 156 const video = await server.videos.get({ id: videoUUID })
168 const video: VideoDetails = res.body
169
170 expect(video.files).to.have.lengthOf(1) 157 expect(video.files).to.have.lengthOf(1)
171 expect(video.streamingPlaylists).to.have.lengthOf(0) 158 expect(video.streamingPlaylists).to.have.lengthOf(0)
172 }) 159 })
@@ -176,8 +163,8 @@ describe('Test transcoding plugins', function () {
176 163
177 const liveVideoId = await createLiveWrapper(server) 164 const liveVideoId = await createLiveWrapper(server)
178 165
179 await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') 166 await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
180 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) 167 await server.live.waitUntilPublished({ videoId: liveVideoId })
181 await waitJobs([ server ]) 168 await waitJobs([ server ])
182 169
183 await checkLiveFPS(liveVideoId, 'above', 20) 170 await checkLiveFPS(liveVideoId, 'above', 20)
@@ -190,8 +177,8 @@ describe('Test transcoding plugins', function () {
190 177
191 const liveVideoId = await createLiveWrapper(server) 178 const liveVideoId = await createLiveWrapper(server)
192 179
193 await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') 180 await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
194 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) 181 await server.live.waitUntilPublished({ videoId: liveVideoId })
195 await waitJobs([ server ]) 182 await waitJobs([ server ])
196 183
197 await checkLiveFPS(liveVideoId, 'below', 12) 184 await checkLiveFPS(liveVideoId, 'below', 12)
@@ -204,8 +191,8 @@ describe('Test transcoding plugins', function () {
204 191
205 const liveVideoId = await createLiveWrapper(server) 192 const liveVideoId = await createLiveWrapper(server)
206 193
207 await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') 194 await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
208 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) 195 await server.live.waitUntilPublished({ videoId: liveVideoId })
209 await waitJobs([ server ]) 196 await waitJobs([ server ])
210 197
211 await checkLiveFPS(liveVideoId, 'below', 6) 198 await checkLiveFPS(liveVideoId, 'below', 6)
@@ -218,22 +205,21 @@ describe('Test transcoding plugins', function () {
218 205
219 const liveVideoId = await createLiveWrapper(server) 206 const liveVideoId = await createLiveWrapper(server)
220 207
221 const command = await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') 208 const command = await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
222 await testFfmpegStreamError(command, true) 209 await testFfmpegStreamError(command, true)
223 }) 210 })
224 211
225 it('Should default to the default profile if the specified profile does not exist', async function () { 212 it('Should default to the default profile if the specified profile does not exist', async function () {
226 this.timeout(240000) 213 this.timeout(240000)
227 214
228 await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-transcoding-one' }) 215 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-transcoding-one' })
229 216
230 const res = await getConfig(server.url) 217 const config = await server.config.getConfig()
231 const config = res.body as ServerConfig
232 218
233 expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ]) 219 expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ])
234 expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ]) 220 expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ])
235 221
236 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video' })).uuid 222 const videoUUID = (await server.videos.quickUpload({ name: 'video' })).uuid
237 await waitJobs([ server ]) 223 await waitJobs([ server ])
238 224
239 await checkVideoFPS(videoUUID, 'above', 20) 225 await checkVideoFPS(videoUUID, 'above', 20)
@@ -244,11 +230,7 @@ describe('Test transcoding plugins', function () {
244 describe('When using a plugin adding new encoders', function () { 230 describe('When using a plugin adding new encoders', function () {
245 231
246 before(async function () { 232 before(async function () {
247 await installPlugin({ 233 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-transcoding-two') })
248 url: server.url,
249 accessToken: server.accessToken,
250 path: getPluginTestPath('-transcoding-two')
251 })
252 234
253 await updateConf(server, 'test-vod-profile', 'test-live-profile') 235 await updateConf(server, 'test-vod-profile', 'test-live-profile')
254 }) 236 })
@@ -256,10 +238,10 @@ describe('Test transcoding plugins', function () {
256 it('Should use the new vod encoders', async function () { 238 it('Should use the new vod encoders', async function () {
257 this.timeout(240000) 239 this.timeout(240000)
258 240
259 const videoUUID = (await uploadVideoAndGetId({ server, videoName: 'video', fixture: 'video_short_240p.mp4' })).uuid 241 const videoUUID = (await server.videos.quickUpload({ name: 'video', fixture: 'video_short_240p.mp4' })).uuid
260 await waitJobs([ server ]) 242 await waitJobs([ server ])
261 243
262 const path = buildServerDirectory(server, join('videos', videoUUID + '-240.mp4')) 244 const path = server.servers.buildDirectory(join('videos', videoUUID + '-240.mp4'))
263 const audioProbe = await getAudioStream(path) 245 const audioProbe = await getAudioStream(path)
264 expect(audioProbe.audioStream.codec_name).to.equal('opus') 246 expect(audioProbe.audioStream.codec_name).to.equal('opus')
265 247
@@ -272,8 +254,8 @@ describe('Test transcoding plugins', function () {
272 254
273 const liveVideoId = await createLiveWrapper(server) 255 const liveVideoId = await createLiveWrapper(server)
274 256
275 await sendRTMPStreamInVideo(server.url, server.accessToken, liveVideoId, 'video_short2.webm') 257 await server.live.sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
276 await waitUntilLivePublished(server.url, server.accessToken, liveVideoId) 258 await server.live.waitUntilPublished({ videoId: liveVideoId })
277 await waitJobs([ server ]) 259 await waitJobs([ server ])
278 260
279 const playlistUrl = `${server.url}/static/streaming-playlists/hls/${liveVideoId}/0.m3u8` 261 const playlistUrl = `${server.url}/static/streaming-playlists/hls/${liveVideoId}/0.m3u8`
diff --git a/server/tests/plugins/plugin-unloading.ts b/server/tests/plugins/plugin-unloading.ts
index 74ca82e2f..6bf2fda9b 100644
--- a/server/tests/plugins/plugin-unloading.ts
+++ b/server/tests/plugins/plugin-unloading.ts
@@ -1,42 +1,36 @@
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 { expect } from 'chai'
4import { 5import {
5 cleanupTests, 6 cleanupTests,
6 flushAndRunServer, 7 createSingleServer,
7 getPluginTestPath,
8 makeGetRequest, 8 makeGetRequest,
9 installPlugin, 9 PeerTubeServer,
10 uninstallPlugin, 10 PluginsCommand,
11 ServerInfo,
12 setAccessTokensToServers 11 setAccessTokensToServers
13} from '../../../shared/extra-utils' 12} from '@shared/extra-utils'
14import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' 13import { HttpStatusCode } from '@shared/models'
15import { expect } from 'chai'
16 14
17describe('Test plugins module unloading', function () { 15describe('Test plugins module unloading', function () {
18 let server: ServerInfo = null 16 let server: PeerTubeServer = null
19 const requestPath = '/plugins/test-unloading/router/get' 17 const requestPath = '/plugins/test-unloading/router/get'
20 let value: string = null 18 let value: string = null
21 19
22 before(async function () { 20 before(async function () {
23 this.timeout(30000) 21 this.timeout(30000)
24 22
25 server = await flushAndRunServer(1) 23 server = await createSingleServer(1)
26 await setAccessTokensToServers([ server ]) 24 await setAccessTokensToServers([ server ])
27 25
28 await installPlugin({ 26 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-unloading') })
29 url: server.url,
30 accessToken: server.accessToken,
31 path: getPluginTestPath('-unloading')
32 })
33 }) 27 })
34 28
35 it('Should return a numeric value', async function () { 29 it('Should return a numeric value', async function () {
36 const res = await makeGetRequest({ 30 const res = await makeGetRequest({
37 url: server.url, 31 url: server.url,
38 path: requestPath, 32 path: requestPath,
39 statusCodeExpected: HttpStatusCode.OK_200 33 expectedStatus: HttpStatusCode.OK_200
40 }) 34 })
41 35
42 expect(res.body.message).to.match(/^\d+$/) 36 expect(res.body.message).to.match(/^\d+$/)
@@ -47,36 +41,29 @@ describe('Test plugins module unloading', function () {
47 const res = await makeGetRequest({ 41 const res = await makeGetRequest({
48 url: server.url, 42 url: server.url,
49 path: requestPath, 43 path: requestPath,
50 statusCodeExpected: HttpStatusCode.OK_200 44 expectedStatus: HttpStatusCode.OK_200
51 }) 45 })
52 46
53 expect(res.body.message).to.be.equal(value) 47 expect(res.body.message).to.be.equal(value)
54 }) 48 })
55 49
56 it('Should uninstall the plugin and free the route', async function () { 50 it('Should uninstall the plugin and free the route', async function () {
57 await uninstallPlugin({ 51 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-unloading' })
58 url: server.url,
59 accessToken: server.accessToken,
60 npmName: 'peertube-plugin-test-unloading'
61 })
62 52
63 await makeGetRequest({ 53 await makeGetRequest({
64 url: server.url, 54 url: server.url,
65 path: requestPath, 55 path: requestPath,
66 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 56 expectedStatus: HttpStatusCode.NOT_FOUND_404
67 }) 57 })
68 }) 58 })
69 59
70 it('Should return a different numeric value', async function () { 60 it('Should return a different numeric value', async function () {
71 await installPlugin({ 61 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-unloading') })
72 url: server.url, 62
73 accessToken: server.accessToken,
74 path: getPluginTestPath('-unloading')
75 })
76 const res = await makeGetRequest({ 63 const res = await makeGetRequest({
77 url: server.url, 64 url: server.url,
78 path: requestPath, 65 path: requestPath,
79 statusCodeExpected: HttpStatusCode.OK_200 66 expectedStatus: HttpStatusCode.OK_200
80 }) 67 })
81 68
82 expect(res.body.message).to.match(/^\d+$/) 69 expect(res.body.message).to.match(/^\d+$/)
diff --git a/server/tests/plugins/translations.ts b/server/tests/plugins/translations.ts
index 9fd2ba1c5..8b25c6b75 100644
--- a/server/tests/plugins/translations.ts
+++ b/server/tests/plugins/translations.ts
@@ -1,50 +1,37 @@
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 { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' 4import * as chai from 'chai'
6import { 5import { cleanupTests, createSingleServer, PeerTubeServer, PluginsCommand, setAccessTokensToServers } from '@shared/extra-utils'
7 getPluginTestPath,
8 getPluginTranslations,
9 installPlugin,
10 setAccessTokensToServers,
11 uninstallPlugin
12} from '../../../shared/extra-utils'
13 6
14const expect = chai.expect 7const expect = chai.expect
15 8
16describe('Test plugin translations', function () { 9describe('Test plugin translations', function () {
17 let server: ServerInfo 10 let server: PeerTubeServer
11 let command: PluginsCommand
18 12
19 before(async function () { 13 before(async function () {
20 this.timeout(30000) 14 this.timeout(30000)
21 15
22 server = await flushAndRunServer(1) 16 server = await createSingleServer(1)
23 await setAccessTokensToServers([ server ]) 17 await setAccessTokensToServers([ server ])
24 18
25 await installPlugin({ 19 command = server.plugins
26 url: server.url,
27 accessToken: server.accessToken,
28 path: getPluginTestPath()
29 })
30 20
31 await installPlugin({ 21 await command.install({ path: PluginsCommand.getPluginTestPath() })
32 url: server.url, 22 await command.install({ path: PluginsCommand.getPluginTestPath('-filter-translations') })
33 accessToken: server.accessToken,
34 path: getPluginTestPath('-filter-translations')
35 })
36 }) 23 })
37 24
38 it('Should not have translations for locale pt', async function () { 25 it('Should not have translations for locale pt', async function () {
39 const res = await getPluginTranslations({ url: server.url, locale: 'pt' }) 26 const body = await command.getTranslations({ locale: 'pt' })
40 27
41 expect(res.body).to.deep.equal({}) 28 expect(body).to.deep.equal({})
42 }) 29 })
43 30
44 it('Should have translations for locale fr', async function () { 31 it('Should have translations for locale fr', async function () {
45 const res = await getPluginTranslations({ url: server.url, locale: 'fr-FR' }) 32 const body = await command.getTranslations({ locale: 'fr-FR' })
46 33
47 expect(res.body).to.deep.equal({ 34 expect(body).to.deep.equal({
48 'peertube-plugin-test': { 35 'peertube-plugin-test': {
49 Hi: 'Coucou' 36 Hi: 'Coucou'
50 }, 37 },
@@ -55,9 +42,9 @@ describe('Test plugin translations', function () {
55 }) 42 })
56 43
57 it('Should have translations of locale it', async function () { 44 it('Should have translations of locale it', async function () {
58 const res = await getPluginTranslations({ url: server.url, locale: 'it-IT' }) 45 const body = await command.getTranslations({ locale: 'it-IT' })
59 46
60 expect(res.body).to.deep.equal({ 47 expect(body).to.deep.equal({
61 'peertube-plugin-test-filter-translations': { 48 'peertube-plugin-test-filter-translations': {
62 'Hello world': 'Ciao, mondo!' 49 'Hello world': 'Ciao, mondo!'
63 } 50 }
@@ -65,12 +52,12 @@ describe('Test plugin translations', function () {
65 }) 52 })
66 53
67 it('Should remove the plugin and remove the locales', async function () { 54 it('Should remove the plugin and remove the locales', async function () {
68 await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-filter-translations' }) 55 await command.uninstall({ npmName: 'peertube-plugin-test-filter-translations' })
69 56
70 { 57 {
71 const res = await getPluginTranslations({ url: server.url, locale: 'fr-FR' }) 58 const body = await command.getTranslations({ locale: 'fr-FR' })
72 59
73 expect(res.body).to.deep.equal({ 60 expect(body).to.deep.equal({
74 'peertube-plugin-test': { 61 'peertube-plugin-test': {
75 Hi: 'Coucou' 62 Hi: 'Coucou'
76 } 63 }
@@ -78,9 +65,9 @@ describe('Test plugin translations', function () {
78 } 65 }
79 66
80 { 67 {
81 const res = await getPluginTranslations({ url: server.url, locale: 'it-IT' }) 68 const body = await command.getTranslations({ locale: 'it-IT' })
82 69
83 expect(res.body).to.deep.equal({}) 70 expect(body).to.deep.equal({})
84 } 71 }
85 }) 72 })
86 73
diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts
index 7b1312f88..19cba6c2c 100644
--- a/server/tests/plugins/video-constants.ts
+++ b/server/tests/plugins/video-constants.ts
@@ -1,47 +1,33 @@
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 { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' 4import * as chai from 'chai'
6import { 5import {
7 createVideoPlaylist, 6 cleanupTests,
8 getPluginTestPath, 7 createSingleServer,
9 getVideo,
10 getVideoCategories,
11 getVideoLanguages,
12 getVideoLicences,
13 getVideoPlaylistPrivacies,
14 getVideoPrivacies,
15 installPlugin,
16 makeGetRequest, 8 makeGetRequest,
17 setAccessTokensToServers, 9 PeerTubeServer,
18 uninstallPlugin, 10 PluginsCommand,
19 uploadVideo 11 setAccessTokensToServers
20} from '../../../shared/extra-utils' 12} from '@shared/extra-utils'
21import { VideoDetails, VideoPlaylistPrivacy } from '../../../shared/models/videos' 13import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
22import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
23 14
24const expect = chai.expect 15const expect = chai.expect
25 16
26describe('Test plugin altering video constants', function () { 17describe('Test plugin altering video constants', function () {
27 let server: ServerInfo 18 let server: PeerTubeServer
28 19
29 before(async function () { 20 before(async function () {
30 this.timeout(30000) 21 this.timeout(30000)
31 22
32 server = await flushAndRunServer(1) 23 server = await createSingleServer(1)
33 await setAccessTokensToServers([ server ]) 24 await setAccessTokensToServers([ server ])
34 25
35 await installPlugin({ 26 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
36 url: server.url,
37 accessToken: server.accessToken,
38 path: getPluginTestPath('-video-constants')
39 })
40 }) 27 })
41 28
42 it('Should have updated languages', async function () { 29 it('Should have updated languages', async function () {
43 const res = await getVideoLanguages(server.url) 30 const languages = await server.videos.getLanguages()
44 const languages = res.body
45 31
46 expect(languages['en']).to.not.exist 32 expect(languages['en']).to.not.exist
47 expect(languages['fr']).to.not.exist 33 expect(languages['fr']).to.not.exist
@@ -52,8 +38,7 @@ describe('Test plugin altering video constants', function () {
52 }) 38 })
53 39
54 it('Should have updated categories', async function () { 40 it('Should have updated categories', async function () {
55 const res = await getVideoCategories(server.url) 41 const categories = await server.videos.getCategories()
56 const categories = res.body
57 42
58 expect(categories[1]).to.not.exist 43 expect(categories[1]).to.not.exist
59 expect(categories[2]).to.not.exist 44 expect(categories[2]).to.not.exist
@@ -63,8 +48,7 @@ describe('Test plugin altering video constants', function () {
63 }) 48 })
64 49
65 it('Should have updated licences', async function () { 50 it('Should have updated licences', async function () {
66 const res = await getVideoLicences(server.url) 51 const licences = await server.videos.getLicences()
67 const licences = res.body
68 52
69 expect(licences[1]).to.not.exist 53 expect(licences[1]).to.not.exist
70 expect(licences[7]).to.not.exist 54 expect(licences[7]).to.not.exist
@@ -74,8 +58,7 @@ describe('Test plugin altering video constants', function () {
74 }) 58 })
75 59
76 it('Should have updated video privacies', async function () { 60 it('Should have updated video privacies', async function () {
77 const res = await getVideoPrivacies(server.url) 61 const privacies = await server.videos.getPrivacies()
78 const privacies = res.body
79 62
80 expect(privacies[1]).to.exist 63 expect(privacies[1]).to.exist
81 expect(privacies[2]).to.not.exist 64 expect(privacies[2]).to.not.exist
@@ -84,8 +67,7 @@ describe('Test plugin altering video constants', function () {
84 }) 67 })
85 68
86 it('Should have updated playlist privacies', async function () { 69 it('Should have updated playlist privacies', async function () {
87 const res = await getVideoPlaylistPrivacies(server.url) 70 const playlistPrivacies = await server.playlists.getPrivacies()
88 const playlistPrivacies = res.body
89 71
90 expect(playlistPrivacies[1]).to.exist 72 expect(playlistPrivacies[1]).to.exist
91 expect(playlistPrivacies[2]).to.exist 73 expect(playlistPrivacies[2]).to.exist
@@ -93,38 +75,30 @@ describe('Test plugin altering video constants', function () {
93 }) 75 })
94 76
95 it('Should not be able to create a video with this privacy', async function () { 77 it('Should not be able to create a video with this privacy', async function () {
96 const attrs = { name: 'video', privacy: 2 } 78 const attributes = { name: 'video', privacy: 2 }
97 await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400) 79 await server.videos.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
98 }) 80 })
99 81
100 it('Should not be able to create a video with this privacy', async function () { 82 it('Should not be able to create a video with this privacy', async function () {
101 const attrs = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE } 83 const attributes = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
102 await createVideoPlaylist({ 84 await server.playlists.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
103 url: server.url,
104 token: server.accessToken,
105 playlistAttrs: attrs,
106 expectedStatus: HttpStatusCode.BAD_REQUEST_400
107 })
108 }) 85 })
109 86
110 it('Should be able to upload a video with these values', async function () { 87 it('Should be able to upload a video with these values', async function () {
111 const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' } 88 const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
112 const resUpload = await uploadVideo(server.url, server.accessToken, attrs) 89 const { uuid } = await server.videos.upload({ attributes })
113 90
114 const res = await getVideo(server.url, resUpload.body.video.uuid) 91 const video = await server.videos.get({ id: uuid })
115
116 const video: VideoDetails = res.body
117 expect(video.language.label).to.equal('Al Bhed 2') 92 expect(video.language.label).to.equal('Al Bhed 2')
118 expect(video.licence.label).to.equal('Best licence') 93 expect(video.licence.label).to.equal('Best licence')
119 expect(video.category.label).to.equal('Best category') 94 expect(video.category.label).to.equal('Best category')
120 }) 95 })
121 96
122 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () { 97 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
123 await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-video-constants' }) 98 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
124 99
125 { 100 {
126 const res = await getVideoLanguages(server.url) 101 const languages = await server.videos.getLanguages()
127 const languages = res.body
128 102
129 expect(languages['en']).to.equal('English') 103 expect(languages['en']).to.equal('English')
130 expect(languages['fr']).to.equal('French') 104 expect(languages['fr']).to.equal('French')
@@ -135,8 +109,7 @@ describe('Test plugin altering video constants', function () {
135 } 109 }
136 110
137 { 111 {
138 const res = await getVideoCategories(server.url) 112 const categories = await server.videos.getCategories()
139 const categories = res.body
140 113
141 expect(categories[1]).to.equal('Music') 114 expect(categories[1]).to.equal('Music')
142 expect(categories[2]).to.equal('Films') 115 expect(categories[2]).to.equal('Films')
@@ -146,8 +119,7 @@ describe('Test plugin altering video constants', function () {
146 } 119 }
147 120
148 { 121 {
149 const res = await getVideoLicences(server.url) 122 const licences = await server.videos.getLicences()
150 const licences = res.body
151 123
152 expect(licences[1]).to.equal('Attribution') 124 expect(licences[1]).to.equal('Attribution')
153 expect(licences[7]).to.equal('Public Domain Dedication') 125 expect(licences[7]).to.equal('Public Domain Dedication')
@@ -157,8 +129,7 @@ describe('Test plugin altering video constants', function () {
157 } 129 }
158 130
159 { 131 {
160 const res = await getVideoPrivacies(server.url) 132 const privacies = await server.videos.getPrivacies()
161 const privacies = res.body
162 133
163 expect(privacies[1]).to.exist 134 expect(privacies[1]).to.exist
164 expect(privacies[2]).to.exist 135 expect(privacies[2]).to.exist
@@ -167,8 +138,7 @@ describe('Test plugin altering video constants', function () {
167 } 138 }
168 139
169 { 140 {
170 const res = await getVideoPlaylistPrivacies(server.url) 141 const playlistPrivacies = await server.playlists.getPrivacies()
171 const playlistPrivacies = res.body
172 142
173 expect(playlistPrivacies[1]).to.exist 143 expect(playlistPrivacies[1]).to.exist
174 expect(playlistPrivacies[2]).to.exist 144 expect(playlistPrivacies[2]).to.exist
@@ -177,35 +147,34 @@ describe('Test plugin altering video constants', function () {
177 }) 147 })
178 148
179 it('Should be able to reset categories', async function () { 149 it('Should be able to reset categories', async function () {
180 await installPlugin({ 150 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
181 url: server.url,
182 accessToken: server.accessToken,
183 path: getPluginTestPath('-video-constants')
184 })
185 151
186 let { body: categories } = await getVideoCategories(server.url) 152 {
153 const categories = await server.videos.getCategories()
187 154
188 expect(categories[1]).to.not.exist 155 expect(categories[1]).to.not.exist
189 expect(categories[2]).to.not.exist 156 expect(categories[2]).to.not.exist
190 157
191 expect(categories[42]).to.exist 158 expect(categories[42]).to.exist
192 expect(categories[43]).to.exist 159 expect(categories[43]).to.exist
160 }
193 161
194 await makeGetRequest({ 162 await makeGetRequest({
195 url: server.url, 163 url: server.url,
196 token: server.accessToken, 164 token: server.accessToken,
197 path: '/plugins/test-video-constants/router/reset-categories', 165 path: '/plugins/test-video-constants/router/reset-categories',
198 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 166 expectedStatus: HttpStatusCode.NO_CONTENT_204
199 }) 167 })
200 168
201 const { body } = await getVideoCategories(server.url) 169 {
202 categories = body 170 const categories = await server.videos.getCategories()
203 171
204 expect(categories[1]).to.exist 172 expect(categories[1]).to.exist
205 expect(categories[2]).to.exist 173 expect(categories[2]).to.exist
206 174
207 expect(categories[42]).to.not.exist 175 expect(categories[42]).to.not.exist
208 expect(categories[43]).to.not.exist 176 expect(categories[43]).to.not.exist
177 }
209 }) 178 })
210 179
211 after(async function () { 180 after(async function () {