]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
fe3a55b0 | 2 | |
fe3a55b0 | 3 | import 'mocha' |
696d83fd | 4 | import * as chai from 'chai' |
b70025bf | 5 | import * as xmlParser from 'fast-xml-parser' |
5f8bd4cb | 6 | import { HttpStatusCode } from '@shared/core-utils' |
696d83fd | 7 | import { |
5f8bd4cb C |
8 | addUserSubscription, |
9 | addVideoCommentThread, | |
7c3b7976 | 10 | cleanupTests, |
662fb3ab | 11 | createUser, |
fe3a55b0 C |
12 | doubleFollow, |
13 | flushAndRunMultipleServers, | |
18490b07 | 14 | flushAndRunServer, |
57cfff78 | 15 | getMyUserInformation, |
18490b07 | 16 | getUserScopedTokens, |
5f8bd4cb | 17 | listUserSubscriptionVideos, |
18490b07 | 18 | renewUserScopedTokens, |
fe3a55b0 C |
19 | ServerInfo, |
20 | setAccessTokensToServers, | |
57cfff78 | 21 | uploadVideo, |
696d83fd | 22 | uploadVideoAndGetId, |
5f8bd4cb C |
23 | userLogin, |
24 | waitJobs | |
25 | } from '@shared/extra-utils' | |
26 | import { User, VideoPrivacy } from '@shared/models' | |
27 | import { ScopedToken } from '@shared/models/users/user-scoped-token' | |
fe3a55b0 C |
28 | |
29 | chai.use(require('chai-xml')) | |
30 | chai.use(require('chai-json-schema')) | |
31 | chai.config.includeStack = true | |
32 | const expect = chai.expect | |
33 | ||
34 | describe('Test syndication feeds', () => { | |
35 | let servers: ServerInfo[] = [] | |
97816649 | 36 | let serverHLSOnly: ServerInfo |
662fb3ab | 37 | let userAccessToken: string |
57cfff78 C |
38 | let rootAccountId: number |
39 | let rootChannelId: number | |
40 | let userAccountId: number | |
41 | let userChannelId: number | |
afff310e | 42 | let userFeedToken: string |
fe3a55b0 C |
43 | |
44 | before(async function () { | |
45 | this.timeout(120000) | |
46 | ||
47 | // Run servers | |
48 | servers = await flushAndRunMultipleServers(2) | |
97816649 C |
49 | serverHLSOnly = await flushAndRunServer(3, { |
50 | transcoding: { | |
51 | enabled: true, | |
52 | webtorrent: { enabled: false }, | |
53 | hls: { enabled: true } | |
54 | } | |
55 | }) | |
fe3a55b0 | 56 | |
97816649 | 57 | await setAccessTokensToServers([ ...servers, serverHLSOnly ]) |
fe3a55b0 C |
58 | await doubleFollow(servers[0], servers[1]) |
59 | ||
662fb3ab C |
60 | { |
61 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | |
62 | const user: User = res.body | |
57cfff78 C |
63 | rootAccountId = user.account.id |
64 | rootChannelId = user.videoChannels[0].id | |
fe3a55b0 | 65 | } |
fe3a55b0 | 66 | |
662fb3ab C |
67 | { |
68 | const attr = { username: 'john', password: 'password' } | |
a1587156 | 69 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password }) |
662fb3ab C |
70 | userAccessToken = await userLogin(servers[0], attr) |
71 | ||
72 | const res = await getMyUserInformation(servers[0].url, userAccessToken) | |
73 | const user: User = res.body | |
57cfff78 C |
74 | userAccountId = user.account.id |
75 | userChannelId = user.videoChannels[0].id | |
afff310e RK |
76 | |
77 | const res2 = await getUserScopedTokens(servers[0].url, userAccessToken) | |
78 | const token: ScopedToken = res2.body | |
79 | userFeedToken = token.feedToken | |
662fb3ab C |
80 | } |
81 | ||
82 | { | |
a1587156 | 83 | await uploadVideo(servers[0].url, userAccessToken, { name: 'user video' }) |
662fb3ab C |
84 | } |
85 | ||
86 | { | |
87 | const videoAttributes = { | |
88 | name: 'my super name for server 1', | |
89 | description: 'my super description for server 1', | |
90 | fixture: 'video_short.webm' | |
91 | } | |
a1587156 | 92 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) |
662fb3ab C |
93 | const videoId = res.body.video.id |
94 | ||
a1587156 C |
95 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1') |
96 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2') | |
662fb3ab | 97 | } |
fe3a55b0 | 98 | |
68b6fd21 C |
99 | { |
100 | const videoAttributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED } | |
101 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | |
102 | const videoId = res.body.video.id | |
103 | ||
104 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'comment on unlisted video') | |
105 | } | |
106 | ||
3cd0734f | 107 | await waitJobs(servers) |
fe3a55b0 C |
108 | }) |
109 | ||
110 | describe('All feed', function () { | |
111 | ||
112 | it('Should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () { | |
113 | for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) { | |
c1bc8ee4 C |
114 | const rss = await servers[0].feedCommand.getXML({ feed }) |
115 | expect(rss).xml.to.be.valid() | |
fe3a55b0 | 116 | |
c1bc8ee4 C |
117 | const atom = await servers[0].feedCommand.getXML({ feed, format: 'atom' }) |
118 | expect(atom).xml.to.be.valid() | |
fe3a55b0 C |
119 | } |
120 | }) | |
121 | ||
122 | it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () { | |
123 | for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) { | |
c1bc8ee4 C |
124 | const jsonText = await servers[0].feedCommand.getJSON({ feed }) |
125 | expect(JSON.parse(jsonText)).to.be.jsonSchema({ type: 'object' }) | |
fe3a55b0 C |
126 | } |
127 | }) | |
128 | }) | |
129 | ||
130 | describe('Videos feed', function () { | |
97816649 | 131 | |
fe3a55b0 C |
132 | it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () { |
133 | for (const server of servers) { | |
c1bc8ee4 C |
134 | const rss = await server.feedCommand.getXML({ feed: 'videos' }) |
135 | expect(xmlParser.validate(rss)).to.be.true | |
b70025bf | 136 | |
c1bc8ee4 | 137 | const xmlDoc = xmlParser.parse(rss, { parseAttributeValue: true, ignoreAttributes: false }) |
b70025bf C |
138 | |
139 | const enclosure = xmlDoc.rss.channel.item[0].enclosure | |
140 | expect(enclosure).to.exist | |
141 | expect(enclosure['@_type']).to.equal('application/x-bittorrent') | |
142 | expect(enclosure['@_length']).to.equal(218910) | |
143 | expect(enclosure['@_url']).to.contain('720.torrent') | |
fe3a55b0 C |
144 | } |
145 | }) | |
146 | ||
147 | it('Should contain a valid \'attachments\' object (covers JSON feed 1.0 endpoint)', async function () { | |
148 | for (const server of servers) { | |
c1bc8ee4 C |
149 | const json = await server.feedCommand.getJSON({ feed: 'videos' }) |
150 | const jsonObj = JSON.parse(json) | |
662fb3ab | 151 | expect(jsonObj.items.length).to.be.equal(2) |
a1587156 C |
152 | expect(jsonObj.items[0].attachments).to.exist |
153 | expect(jsonObj.items[0].attachments.length).to.be.eq(1) | |
154 | expect(jsonObj.items[0].attachments[0].mime_type).to.be.eq('application/x-bittorrent') | |
155 | expect(jsonObj.items[0].attachments[0].size_in_bytes).to.be.eq(218910) | |
156 | expect(jsonObj.items[0].attachments[0].url).to.contain('720.torrent') | |
fe3a55b0 C |
157 | } |
158 | }) | |
662fb3ab C |
159 | |
160 | it('Should filter by account', async function () { | |
57cfff78 | 161 | { |
c1bc8ee4 C |
162 | const json = await servers[0].feedCommand.getJSON({ feed: 'videos', query: { accountId: rootAccountId } }) |
163 | const jsonObj = JSON.parse(json) | |
57cfff78 | 164 | expect(jsonObj.items.length).to.be.equal(1) |
a1587156 C |
165 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') |
166 | expect(jsonObj.items[0].author.name).to.equal('root') | |
57cfff78 C |
167 | } |
168 | ||
169 | { | |
c1bc8ee4 C |
170 | const json = await servers[0].feedCommand.getJSON({ feed: 'videos', query: { accountId: userAccountId } }) |
171 | const jsonObj = JSON.parse(json) | |
57cfff78 | 172 | expect(jsonObj.items.length).to.be.equal(1) |
a1587156 C |
173 | expect(jsonObj.items[0].title).to.equal('user video') |
174 | expect(jsonObj.items[0].author.name).to.equal('john') | |
57cfff78 C |
175 | } |
176 | ||
662fb3ab C |
177 | for (const server of servers) { |
178 | { | |
c1bc8ee4 C |
179 | const json = await server.feedCommand.getJSON({ feed: 'videos', query: { accountName: 'root@localhost:' + servers[0].port } }) |
180 | const jsonObj = JSON.parse(json) | |
662fb3ab | 181 | expect(jsonObj.items.length).to.be.equal(1) |
a1587156 | 182 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') |
662fb3ab C |
183 | } |
184 | ||
185 | { | |
c1bc8ee4 C |
186 | const json = await server.feedCommand.getJSON({ feed: 'videos', query: { accountName: 'john@localhost:' + servers[0].port } }) |
187 | const jsonObj = JSON.parse(json) | |
662fb3ab | 188 | expect(jsonObj.items.length).to.be.equal(1) |
a1587156 | 189 | expect(jsonObj.items[0].title).to.equal('user video') |
662fb3ab C |
190 | } |
191 | } | |
57cfff78 | 192 | }) |
662fb3ab | 193 | |
57cfff78 | 194 | it('Should filter by video channel', async function () { |
662fb3ab | 195 | { |
c1bc8ee4 C |
196 | const json = await servers[0].feedCommand.getJSON({ feed: 'videos', query: { videoChannelId: rootChannelId } }) |
197 | const jsonObj = JSON.parse(json) | |
662fb3ab | 198 | expect(jsonObj.items.length).to.be.equal(1) |
a1587156 C |
199 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') |
200 | expect(jsonObj.items[0].author.name).to.equal('root') | |
662fb3ab C |
201 | } |
202 | ||
203 | { | |
c1bc8ee4 C |
204 | const json = await servers[0].feedCommand.getJSON({ feed: 'videos', query: { videoChannelId: userChannelId } }) |
205 | const jsonObj = JSON.parse(json) | |
662fb3ab | 206 | expect(jsonObj.items.length).to.be.equal(1) |
a1587156 C |
207 | expect(jsonObj.items[0].title).to.equal('user video') |
208 | expect(jsonObj.items[0].author.name).to.equal('john') | |
662fb3ab | 209 | } |
662fb3ab | 210 | |
662fb3ab C |
211 | for (const server of servers) { |
212 | { | |
c1bc8ee4 C |
213 | const query = { videoChannelName: 'root_channel@localhost:' + servers[0].port } |
214 | const json = await server.feedCommand.getJSON({ feed: 'videos', query }) | |
215 | const jsonObj = JSON.parse(json) | |
662fb3ab | 216 | expect(jsonObj.items.length).to.be.equal(1) |
a1587156 | 217 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') |
662fb3ab C |
218 | } |
219 | ||
220 | { | |
c1bc8ee4 C |
221 | const query = { videoChannelName: 'john_channel@localhost:' + servers[0].port } |
222 | const json = await server.feedCommand.getJSON({ feed: 'videos', query }) | |
223 | const jsonObj = JSON.parse(json) | |
662fb3ab | 224 | expect(jsonObj.items.length).to.be.equal(1) |
a1587156 | 225 | expect(jsonObj.items[0].title).to.equal('user video') |
662fb3ab C |
226 | } |
227 | } | |
662fb3ab | 228 | }) |
97816649 C |
229 | |
230 | it('Should correctly have videos feed with HLS only', async function () { | |
231 | this.timeout(120000) | |
232 | ||
233 | await uploadVideo(serverHLSOnly.url, serverHLSOnly.accessToken, { name: 'hls only video' }) | |
234 | ||
235 | await waitJobs([ serverHLSOnly ]) | |
236 | ||
c1bc8ee4 C |
237 | const json = await serverHLSOnly.feedCommand.getJSON({ feed: 'videos' }) |
238 | const jsonObj = JSON.parse(json) | |
97816649 C |
239 | expect(jsonObj.items.length).to.be.equal(1) |
240 | expect(jsonObj.items[0].attachments).to.exist | |
241 | expect(jsonObj.items[0].attachments.length).to.be.eq(4) | |
242 | ||
243 | for (let i = 0; i < 4; i++) { | |
244 | expect(jsonObj.items[0].attachments[i].mime_type).to.be.eq('application/x-bittorrent') | |
245 | expect(jsonObj.items[0].attachments[i].size_in_bytes).to.be.greaterThan(0) | |
246 | expect(jsonObj.items[0].attachments[i].url).to.exist | |
247 | } | |
248 | }) | |
fe3a55b0 C |
249 | }) |
250 | ||
251 | describe('Video comments feed', function () { | |
68b6fd21 C |
252 | |
253 | it('Should contain valid comments (covers JSON feed 1.0 endpoint) and not from unlisted videos', async function () { | |
fe3a55b0 | 254 | for (const server of servers) { |
c1bc8ee4 | 255 | const json = await server.feedCommand.getJSON({ feed: 'video-comments' }) |
fe3a55b0 | 256 | |
c1bc8ee4 | 257 | const jsonObj = JSON.parse(json) |
fe3a55b0 | 258 | expect(jsonObj.items.length).to.be.equal(2) |
a1587156 C |
259 | expect(jsonObj.items[0].html_content).to.equal('super comment 2') |
260 | expect(jsonObj.items[1].html_content).to.equal('super comment 1') | |
fe3a55b0 C |
261 | } |
262 | }) | |
1df8a4d7 C |
263 | |
264 | it('Should not list comments from muted accounts or instances', async function () { | |
696d83fd C |
265 | this.timeout(30000) |
266 | ||
267 | const remoteHandle = 'root@localhost:' + servers[0].port | |
268 | ||
5f8bd4cb | 269 | await servers[1].blocklistCommand.addToServerBlocklist({ account: remoteHandle }) |
1df8a4d7 C |
270 | |
271 | { | |
c1bc8ee4 C |
272 | const json = await servers[1].feedCommand.getJSON({ feed: 'video-comments', query: { version: 2 } }) |
273 | const jsonObj = JSON.parse(json) | |
1df8a4d7 C |
274 | expect(jsonObj.items.length).to.be.equal(0) |
275 | } | |
276 | ||
5f8bd4cb | 277 | await servers[1].blocklistCommand.removeFromServerBlocklist({ account: remoteHandle }) |
696d83fd C |
278 | |
279 | { | |
280 | const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid | |
281 | await waitJobs(servers) | |
282 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'super comment') | |
283 | await waitJobs(servers) | |
284 | ||
c1bc8ee4 C |
285 | const json = await servers[1].feedCommand.getJSON({ feed: 'video-comments', query: { version: 3 } }) |
286 | const jsonObj = JSON.parse(json) | |
696d83fd C |
287 | expect(jsonObj.items.length).to.be.equal(3) |
288 | } | |
289 | ||
5f8bd4cb | 290 | await servers[1].blocklistCommand.addToMyBlocklist({ account: remoteHandle }) |
696d83fd C |
291 | |
292 | { | |
c1bc8ee4 C |
293 | const json = await servers[1].feedCommand.getJSON({ feed: 'video-comments', query: { version: 4 } }) |
294 | const jsonObj = JSON.parse(json) | |
696d83fd C |
295 | expect(jsonObj.items.length).to.be.equal(2) |
296 | } | |
1df8a4d7 | 297 | }) |
fe3a55b0 C |
298 | }) |
299 | ||
afff310e | 300 | describe('Video feed from my subscriptions', function () { |
18490b07 C |
301 | let feeduserAccountId: number |
302 | let feeduserFeedToken: string | |
afff310e RK |
303 | |
304 | it('Should list no videos for a user with no videos and no subscriptions', async function () { | |
afff310e RK |
305 | const attr = { username: 'feeduser', password: 'password' } |
306 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password }) | |
307 | const feeduserAccessToken = await userLogin(servers[0], attr) | |
308 | ||
309 | { | |
310 | const res = await getMyUserInformation(servers[0].url, feeduserAccessToken) | |
311 | const user: User = res.body | |
312 | feeduserAccountId = user.account.id | |
313 | } | |
314 | ||
315 | { | |
316 | const res = await getUserScopedTokens(servers[0].url, feeduserAccessToken) | |
317 | const token: ScopedToken = res.body | |
318 | feeduserFeedToken = token.feedToken | |
319 | } | |
320 | ||
321 | { | |
322 | const res = await listUserSubscriptionVideos(servers[0].url, feeduserAccessToken) | |
323 | expect(res.body.total).to.equal(0) | |
324 | ||
c1bc8ee4 C |
325 | const query = { accountId: feeduserAccountId, token: feeduserFeedToken } |
326 | const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query }) | |
327 | const jsonObj = JSON.parse(json) | |
afff310e RK |
328 | expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos |
329 | } | |
330 | }) | |
331 | ||
18490b07 | 332 | it('Should fail with an invalid token', async function () { |
c1bc8ee4 C |
333 | const query = { accountId: feeduserAccountId, token: 'toto' } |
334 | await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
18490b07 C |
335 | }) |
336 | ||
337 | it('Should fail with a token of another user', async function () { | |
c1bc8ee4 C |
338 | const query = { accountId: feeduserAccountId, token: userFeedToken } |
339 | await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
18490b07 C |
340 | }) |
341 | ||
afff310e | 342 | it('Should list no videos for a user with videos but no subscriptions', async function () { |
18490b07 C |
343 | const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken) |
344 | expect(res.body.total).to.equal(0) | |
afff310e | 345 | |
c1bc8ee4 C |
346 | const query = { accountId: userAccountId, token: userFeedToken } |
347 | const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query }) | |
348 | const jsonObj = JSON.parse(json) | |
18490b07 | 349 | expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos |
afff310e RK |
350 | }) |
351 | ||
352 | it('Should list self videos for a user with a subscription to themselves', async function () { | |
353 | this.timeout(30000) | |
354 | ||
355 | await addUserSubscription(servers[0].url, userAccessToken, 'john_channel@localhost:' + servers[0].port) | |
356 | await waitJobs(servers) | |
357 | ||
358 | { | |
359 | const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken) | |
360 | expect(res.body.total).to.equal(1) | |
361 | expect(res.body.data[0].name).to.equal('user video') | |
362 | ||
c1bc8ee4 C |
363 | const query = { accountId: userAccountId, token: userFeedToken, version: 1 } |
364 | const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query }) | |
365 | const jsonObj = JSON.parse(json) | |
afff310e RK |
366 | expect(jsonObj.items.length).to.be.equal(1) // subscribed to self, it should not list the instance's videos but list john's |
367 | } | |
368 | }) | |
369 | ||
370 | it('Should list videos of a user\'s subscription', async function () { | |
371 | this.timeout(30000) | |
372 | ||
373 | await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port) | |
374 | await waitJobs(servers) | |
375 | ||
376 | { | |
377 | const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken) | |
378 | expect(res.body.total).to.equal(2, "there should be 2 videos part of the subscription") | |
379 | ||
c1bc8ee4 C |
380 | const query = { accountId: userAccountId, token: userFeedToken, version: 2 } |
381 | const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query }) | |
382 | const jsonObj = JSON.parse(json) | |
afff310e RK |
383 | expect(jsonObj.items.length).to.be.equal(2) // subscribed to root, it should not list the instance's videos but list root/john's |
384 | } | |
385 | }) | |
386 | ||
18490b07 C |
387 | it('Should renew the token, and so have an invalid old token', async function () { |
388 | await renewUserScopedTokens(servers[0].url, userAccessToken) | |
389 | ||
c1bc8ee4 C |
390 | const query = { accountId: userAccountId, token: userFeedToken, version: 3 } |
391 | await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
18490b07 C |
392 | }) |
393 | ||
394 | it('Should succeed with the new token', async function () { | |
395 | const res2 = await getUserScopedTokens(servers[0].url, userAccessToken) | |
396 | const token: ScopedToken = res2.body | |
397 | userFeedToken = token.feedToken | |
398 | ||
c1bc8ee4 C |
399 | const query = { accountId: userAccountId, token: userFeedToken, version: 4 } |
400 | await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query }) | |
18490b07 C |
401 | }) |
402 | ||
afff310e RK |
403 | }) |
404 | ||
7c3b7976 | 405 | after(async function () { |
97816649 | 406 | await cleanupTests([ ...servers, serverHLSOnly ]) |
fe3a55b0 C |
407 | }) |
408 | }) |