]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import { expect } from 'chai' | |
5 | import { | |
6 | checkVideoFilesWereRemoved, | |
7 | cleanupTests, | |
8 | createMultipleServers, | |
9 | doubleFollow, | |
10 | makeGetRequest, | |
11 | makePostBodyRequest, | |
12 | PeerTubeServer, | |
13 | PluginsCommand, | |
14 | setAccessTokensToServers, | |
15 | waitJobs | |
16 | } from '@shared/extra-utils' | |
17 | import { HttpStatusCode } from '@shared/models' | |
18 | ||
19 | function postCommand (server: PeerTubeServer, command: string, bodyArg?: object) { | |
20 | const body = { command } | |
21 | if (bodyArg) Object.assign(body, bodyArg) | |
22 | ||
23 | return makePostBodyRequest({ | |
24 | url: server.url, | |
25 | path: '/plugins/test-four/router/commander', | |
26 | fields: body, | |
27 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | |
28 | }) | |
29 | } | |
30 | ||
31 | describe('Test plugin helpers', function () { | |
32 | let servers: PeerTubeServer[] | |
33 | ||
34 | before(async function () { | |
35 | this.timeout(60000) | |
36 | ||
37 | servers = await createMultipleServers(2) | |
38 | await setAccessTokensToServers(servers) | |
39 | ||
40 | await doubleFollow(servers[0], servers[1]) | |
41 | ||
42 | await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-four') }) | |
43 | }) | |
44 | ||
45 | describe('Logger', function () { | |
46 | ||
47 | it('Should have logged things', async function () { | |
48 | await servers[0].servers.waitUntilLog('localhost:' + servers[0].port + ' peertube-plugin-test-four', 1, false) | |
49 | await servers[0].servers.waitUntilLog('Hello world from plugin four', 1) | |
50 | }) | |
51 | }) | |
52 | ||
53 | describe('Database', function () { | |
54 | ||
55 | it('Should have made a query', async function () { | |
56 | await servers[0].servers.waitUntilLog(`root email is admin${servers[0].internalServerNumber}@example.com`) | |
57 | }) | |
58 | }) | |
59 | ||
60 | describe('Config', function () { | |
61 | ||
62 | it('Should have the correct webserver url', async function () { | |
63 | await servers[0].servers.waitUntilLog(`server url is http://localhost:${servers[0].port}`) | |
64 | }) | |
65 | ||
66 | it('Should have the correct config', async function () { | |
67 | const res = await makeGetRequest({ | |
68 | url: servers[0].url, | |
69 | path: '/plugins/test-four/router/server-config', | |
70 | expectedStatus: HttpStatusCode.OK_200 | |
71 | }) | |
72 | ||
73 | expect(res.body.serverConfig).to.exist | |
74 | expect(res.body.serverConfig.instance.name).to.equal('PeerTube') | |
75 | }) | |
76 | }) | |
77 | ||
78 | describe('Server', function () { | |
79 | ||
80 | it('Should get the server actor', async function () { | |
81 | await servers[0].servers.waitUntilLog('server actor name is peertube') | |
82 | }) | |
83 | }) | |
84 | ||
85 | describe('Plugin', function () { | |
86 | ||
87 | it('Should get the base static route', async function () { | |
88 | const res = await makeGetRequest({ | |
89 | url: servers[0].url, | |
90 | path: '/plugins/test-four/router/static-route', | |
91 | expectedStatus: HttpStatusCode.OK_200 | |
92 | }) | |
93 | ||
94 | expect(res.body.staticRoute).to.equal('/plugins/test-four/0.0.1/static/') | |
95 | }) | |
96 | ||
97 | it('Should get the base static route', async function () { | |
98 | const baseRouter = '/plugins/test-four/0.0.1/router/' | |
99 | ||
100 | const res = await makeGetRequest({ | |
101 | url: servers[0].url, | |
102 | path: baseRouter + 'router-route', | |
103 | expectedStatus: HttpStatusCode.OK_200 | |
104 | }) | |
105 | ||
106 | expect(res.body.routerRoute).to.equal(baseRouter) | |
107 | }) | |
108 | }) | |
109 | ||
110 | describe('User', function () { | |
111 | ||
112 | it('Should not get a user if not authenticated', async function () { | |
113 | await makeGetRequest({ | |
114 | url: servers[0].url, | |
115 | path: '/plugins/test-four/router/user', | |
116 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | |
117 | }) | |
118 | }) | |
119 | ||
120 | it('Should get a user if authenticated', async function () { | |
121 | const res = await makeGetRequest({ | |
122 | url: servers[0].url, | |
123 | token: servers[0].accessToken, | |
124 | path: '/plugins/test-four/router/user', | |
125 | expectedStatus: HttpStatusCode.OK_200 | |
126 | }) | |
127 | ||
128 | expect(res.body.username).to.equal('root') | |
129 | expect(res.body.displayName).to.equal('root') | |
130 | expect(res.body.isAdmin).to.be.true | |
131 | expect(res.body.isModerator).to.be.false | |
132 | expect(res.body.isUser).to.be.false | |
133 | }) | |
134 | }) | |
135 | ||
136 | describe('Moderation', function () { | |
137 | let videoUUIDServer1: string | |
138 | ||
139 | before(async function () { | |
140 | this.timeout(60000) | |
141 | ||
142 | { | |
143 | const res = await servers[0].videos.quickUpload({ name: 'video server 1' }) | |
144 | videoUUIDServer1 = res.uuid | |
145 | } | |
146 | ||
147 | { | |
148 | await servers[1].videos.quickUpload({ name: 'video server 2' }) | |
149 | } | |
150 | ||
151 | await waitJobs(servers) | |
152 | ||
153 | const { data } = await servers[0].videos.list() | |
154 | ||
155 | expect(data).to.have.lengthOf(2) | |
156 | }) | |
157 | ||
158 | it('Should mute server 2', async function () { | |
159 | this.timeout(10000) | |
160 | await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` }) | |
161 | ||
162 | const { data } = await servers[0].videos.list() | |
163 | ||
164 | expect(data).to.have.lengthOf(1) | |
165 | expect(data[0].name).to.equal('video server 1') | |
166 | }) | |
167 | ||
168 | it('Should unmute server 2', async function () { | |
169 | await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` }) | |
170 | ||
171 | const { data } = await servers[0].videos.list() | |
172 | ||
173 | expect(data).to.have.lengthOf(2) | |
174 | }) | |
175 | ||
176 | it('Should mute account of server 2', async function () { | |
177 | await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` }) | |
178 | ||
179 | const { data } = await servers[0].videos.list() | |
180 | ||
181 | expect(data).to.have.lengthOf(1) | |
182 | expect(data[0].name).to.equal('video server 1') | |
183 | }) | |
184 | ||
185 | it('Should unmute account of server 2', async function () { | |
186 | await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` }) | |
187 | ||
188 | const { data } = await servers[0].videos.list() | |
189 | ||
190 | expect(data).to.have.lengthOf(2) | |
191 | }) | |
192 | ||
193 | it('Should blacklist video', async function () { | |
194 | this.timeout(10000) | |
195 | ||
196 | await postCommand(servers[0], 'blacklist', { videoUUID: videoUUIDServer1, unfederate: true }) | |
197 | ||
198 | await waitJobs(servers) | |
199 | ||
200 | for (const server of servers) { | |
201 | const { data } = await server.videos.list() | |
202 | ||
203 | expect(data).to.have.lengthOf(1) | |
204 | expect(data[0].name).to.equal('video server 2') | |
205 | } | |
206 | }) | |
207 | ||
208 | it('Should unblacklist video', async function () { | |
209 | this.timeout(10000) | |
210 | ||
211 | await postCommand(servers[0], 'unblacklist', { videoUUID: videoUUIDServer1 }) | |
212 | ||
213 | await waitJobs(servers) | |
214 | ||
215 | for (const server of servers) { | |
216 | const { data } = await server.videos.list() | |
217 | ||
218 | expect(data).to.have.lengthOf(2) | |
219 | } | |
220 | }) | |
221 | }) | |
222 | ||
223 | describe('Videos', function () { | |
224 | let videoUUID: string | |
225 | ||
226 | before(async () => { | |
227 | const res = await servers[0].videos.quickUpload({ name: 'video1' }) | |
228 | videoUUID = res.uuid | |
229 | }) | |
230 | ||
231 | it('Should remove a video after a view', async function () { | |
232 | this.timeout(40000) | |
233 | ||
234 | // Should not throw -> video exists | |
235 | const video = await servers[0].videos.get({ id: videoUUID }) | |
236 | // Should delete the video | |
237 | await servers[0].videos.view({ id: videoUUID }) | |
238 | ||
239 | await servers[0].servers.waitUntilLog('Video deleted by plugin four.') | |
240 | ||
241 | try { | |
242 | // Should throw because the video should have been deleted | |
243 | await servers[0].videos.get({ id: videoUUID }) | |
244 | throw new Error('Video exists') | |
245 | } catch (err) { | |
246 | if (err.message.includes('exists')) throw err | |
247 | } | |
248 | ||
249 | await checkVideoFilesWereRemoved({ server: servers[0], video }) | |
250 | }) | |
251 | ||
252 | it('Should have fetched the video by URL', async function () { | |
253 | await servers[0].servers.waitUntilLog(`video from DB uuid is ${videoUUID}`) | |
254 | }) | |
255 | }) | |
256 | ||
257 | after(async function () { | |
258 | await cleanupTests(servers) | |
259 | }) | |
260 | }) |