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