]>
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' |
c1bc8ee4 | 14 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
fe3a55b0 | 15 | import { |
7c3b7976 | 16 | cleanupTests, |
662fb3ab | 17 | createUser, |
fe3a55b0 C |
18 | doubleFollow, |
19 | flushAndRunMultipleServers, | |
18490b07 | 20 | flushAndRunServer, |
57cfff78 | 21 | getMyUserInformation, |
18490b07 | 22 | getUserScopedTokens, |
18490b07 | 23 | renewUserScopedTokens, |
fe3a55b0 C |
24 | ServerInfo, |
25 | setAccessTokensToServers, | |
57cfff78 | 26 | uploadVideo, |
696d83fd | 27 | uploadVideoAndGetId, |
18490b07 | 28 | userLogin |
94565d52 | 29 | } from '../../../shared/extra-utils' |
94565d52 | 30 | import { waitJobs } from '../../../shared/extra-utils/server/jobs' |
696d83fd | 31 | import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments' |
662fb3ab | 32 | import { User } from '../../../shared/models/users' |
fe3a55b0 C |
33 | |
34 | chai.use(require('chai-xml')) | |
35 | chai.use(require('chai-json-schema')) | |
36 | chai.config.includeStack = true | |
37 | const expect = chai.expect | |
38 | ||
39 | describe('Test syndication feeds', () => { | |
40 | let servers: ServerInfo[] = [] | |
97816649 | 41 | let serverHLSOnly: ServerInfo |
662fb3ab | 42 | let userAccessToken: string |
57cfff78 C |
43 | let rootAccountId: number |
44 | let rootChannelId: number | |
45 | let userAccountId: number | |
46 | let userChannelId: number | |
afff310e | 47 | let userFeedToken: string |
fe3a55b0 C |
48 | |
49 | before(async function () { | |
50 | this.timeout(120000) | |
51 | ||
52 | // Run servers | |
53 | servers = await flushAndRunMultipleServers(2) | |
97816649 C |
54 | serverHLSOnly = await flushAndRunServer(3, { |
55 | transcoding: { | |
56 | enabled: true, | |
57 | webtorrent: { enabled: false }, | |
58 | hls: { enabled: true } | |
59 | } | |
60 | }) | |
fe3a55b0 | 61 | |
97816649 | 62 | await setAccessTokensToServers([ ...servers, serverHLSOnly ]) |
fe3a55b0 C |
63 | await doubleFollow(servers[0], servers[1]) |
64 | ||
662fb3ab C |
65 | { |
66 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | |
67 | const user: User = res.body | |
57cfff78 C |
68 | rootAccountId = user.account.id |
69 | rootChannelId = user.videoChannels[0].id | |
fe3a55b0 | 70 | } |
fe3a55b0 | 71 | |
662fb3ab C |
72 | { |
73 | const attr = { username: 'john', password: 'password' } | |
a1587156 | 74 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password }) |
662fb3ab C |
75 | userAccessToken = await userLogin(servers[0], attr) |
76 | ||
77 | const res = await getMyUserInformation(servers[0].url, userAccessToken) | |
78 | const user: User = res.body | |
57cfff78 C |
79 | userAccountId = user.account.id |
80 | userChannelId = user.videoChannels[0].id | |
afff310e RK |
81 | |
82 | const res2 = await getUserScopedTokens(servers[0].url, userAccessToken) | |
83 | const token: ScopedToken = res2.body | |
84 | userFeedToken = token.feedToken | |
662fb3ab C |
85 | } |
86 | ||
87 | { | |
a1587156 | 88 | await uploadVideo(servers[0].url, userAccessToken, { name: 'user video' }) |
662fb3ab C |
89 | } |
90 | ||
91 | { | |
92 | const videoAttributes = { | |
93 | name: 'my super name for server 1', | |
94 | description: 'my super description for server 1', | |
95 | fixture: 'video_short.webm' | |
96 | } | |
a1587156 | 97 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) |
662fb3ab C |
98 | const videoId = res.body.video.id |
99 | ||
a1587156 C |
100 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1') |
101 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2') | |
662fb3ab | 102 | } |
fe3a55b0 | 103 | |
68b6fd21 C |
104 | { |
105 | const videoAttributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED } | |
106 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | |
107 | const videoId = res.body.video.id | |
108 | ||
109 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'comment on unlisted video') | |
110 | } | |
111 | ||
3cd0734f | 112 | await waitJobs(servers) |
fe3a55b0 C |
113 | }) |
114 | ||
115 | describe('All feed', function () { | |
116 | ||
117 | it('Should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () { | |
118 | for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) { | |
c1bc8ee4 C |
119 | const rss = await servers[0].feedCommand.getXML({ feed }) |
120 | expect(rss).xml.to.be.valid() | |
fe3a55b0 | 121 | |
c1bc8ee4 C |
122 | const atom = await servers[0].feedCommand.getXML({ feed, format: 'atom' }) |
123 | expect(atom).xml.to.be.valid() | |
fe3a55b0 C |
124 | } |
125 | }) | |
126 | ||
127 | it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () { | |
128 | for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) { | |
c1bc8ee4 C |
129 | const jsonText = await servers[0].feedCommand.getJSON({ feed }) |
130 | expect(JSON.parse(jsonText)).to.be.jsonSchema({ type: 'object' }) | |
fe3a55b0 C |
131 | } |
132 | }) | |
133 | }) | |
134 | ||
135 | describe('Videos feed', function () { | |
97816649 | 136 | |
fe3a55b0 C |
137 | it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () { |
138 | for (const server of servers) { | |
c1bc8ee4 C |
139 | const rss = await server.feedCommand.getXML({ feed: 'videos' }) |
140 | expect(xmlParser.validate(rss)).to.be.true | |
b70025bf | 141 | |
c1bc8ee4 | 142 | const xmlDoc = xmlParser.parse(rss, { parseAttributeValue: true, ignoreAttributes: false }) |
b70025bf C |
143 | |
144 | const enclosure = xmlDoc.rss.channel.item[0].enclosure | |
145 | expect(enclosure).to.exist | |
146 | expect(enclosure['@_type']).to.equal('application/x-bittorrent') | |
147 | expect(enclosure['@_length']).to.equal(218910) | |
148 | expect(enclosure['@_url']).to.contain('720.torrent') | |
fe3a55b0 C |
149 | } |
150 | }) | |
151 | ||
152 | it('Should contain a valid \'attachments\' object (covers JSON feed 1.0 endpoint)', async function () { | |
153 | for (const server of servers) { | |
c1bc8ee4 C |
154 | const json = await server.feedCommand.getJSON({ feed: 'videos' }) |
155 | const jsonObj = JSON.parse(json) | |
662fb3ab | 156 | expect(jsonObj.items.length).to.be.equal(2) |
a1587156 C |
157 | expect(jsonObj.items[0].attachments).to.exist |
158 | expect(jsonObj.items[0].attachments.length).to.be.eq(1) | |
159 | expect(jsonObj.items[0].attachments[0].mime_type).to.be.eq('application/x-bittorrent') | |
160 | expect(jsonObj.items[0].attachments[0].size_in_bytes).to.be.eq(218910) | |
161 | expect(jsonObj.items[0].attachments[0].url).to.contain('720.torrent') | |
fe3a55b0 C |
162 | } |
163 | }) | |
662fb3ab C |
164 | |
165 | it('Should filter by account', async function () { | |
57cfff78 | 166 | { |
c1bc8ee4 C |
167 | const json = await servers[0].feedCommand.getJSON({ feed: 'videos', query: { accountId: rootAccountId } }) |
168 | const jsonObj = JSON.parse(json) | |
57cfff78 | 169 | expect(jsonObj.items.length).to.be.equal(1) |
a1587156 C |
170 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') |
171 | expect(jsonObj.items[0].author.name).to.equal('root') | |
57cfff78 C |
172 | } |
173 | ||
174 | { | |
c1bc8ee4 C |
175 | const json = await servers[0].feedCommand.getJSON({ feed: 'videos', query: { accountId: userAccountId } }) |
176 | const jsonObj = JSON.parse(json) | |
57cfff78 | 177 | expect(jsonObj.items.length).to.be.equal(1) |
a1587156 C |
178 | expect(jsonObj.items[0].title).to.equal('user video') |
179 | expect(jsonObj.items[0].author.name).to.equal('john') | |
57cfff78 C |
180 | } |
181 | ||
662fb3ab C |
182 | for (const server of servers) { |
183 | { | |
c1bc8ee4 C |
184 | const json = await server.feedCommand.getJSON({ feed: 'videos', query: { accountName: 'root@localhost:' + servers[0].port } }) |
185 | const jsonObj = JSON.parse(json) | |
662fb3ab | 186 | expect(jsonObj.items.length).to.be.equal(1) |
a1587156 | 187 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') |
662fb3ab C |
188 | } |
189 | ||
190 | { | |
c1bc8ee4 C |
191 | const json = await server.feedCommand.getJSON({ feed: 'videos', query: { accountName: 'john@localhost:' + servers[0].port } }) |
192 | const jsonObj = JSON.parse(json) | |
662fb3ab | 193 | expect(jsonObj.items.length).to.be.equal(1) |
a1587156 | 194 | expect(jsonObj.items[0].title).to.equal('user video') |
662fb3ab C |
195 | } |
196 | } | |
57cfff78 | 197 | }) |
662fb3ab | 198 | |
57cfff78 | 199 | it('Should filter by video channel', async function () { |
662fb3ab | 200 | { |
c1bc8ee4 C |
201 | const json = await servers[0].feedCommand.getJSON({ feed: 'videos', query: { videoChannelId: rootChannelId } }) |
202 | const jsonObj = JSON.parse(json) | |
662fb3ab | 203 | expect(jsonObj.items.length).to.be.equal(1) |
a1587156 C |
204 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') |
205 | expect(jsonObj.items[0].author.name).to.equal('root') | |
662fb3ab C |
206 | } |
207 | ||
208 | { | |
c1bc8ee4 C |
209 | const json = await servers[0].feedCommand.getJSON({ feed: 'videos', query: { videoChannelId: userChannelId } }) |
210 | const jsonObj = JSON.parse(json) | |
662fb3ab | 211 | expect(jsonObj.items.length).to.be.equal(1) |
a1587156 C |
212 | expect(jsonObj.items[0].title).to.equal('user video') |
213 | expect(jsonObj.items[0].author.name).to.equal('john') | |
662fb3ab | 214 | } |
662fb3ab | 215 | |
662fb3ab C |
216 | for (const server of servers) { |
217 | { | |
c1bc8ee4 C |
218 | const query = { videoChannelName: 'root_channel@localhost:' + servers[0].port } |
219 | const json = await server.feedCommand.getJSON({ feed: 'videos', query }) | |
220 | const jsonObj = JSON.parse(json) | |
662fb3ab | 221 | expect(jsonObj.items.length).to.be.equal(1) |
a1587156 | 222 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') |
662fb3ab C |
223 | } |
224 | ||
225 | { | |
c1bc8ee4 C |
226 | const query = { videoChannelName: 'john_channel@localhost:' + servers[0].port } |
227 | const json = await server.feedCommand.getJSON({ feed: 'videos', query }) | |
228 | const jsonObj = JSON.parse(json) | |
662fb3ab | 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 | ||
c1bc8ee4 C |
242 | const json = await serverHLSOnly.feedCommand.getJSON({ feed: 'videos' }) |
243 | const jsonObj = JSON.parse(json) | |
97816649 C |
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 | 259 | for (const server of servers) { |
c1bc8ee4 | 260 | const json = await server.feedCommand.getJSON({ feed: 'video-comments' }) |
fe3a55b0 | 261 | |
c1bc8ee4 | 262 | const jsonObj = JSON.parse(json) |
fe3a55b0 | 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 | { | |
c1bc8ee4 C |
277 | const json = await servers[1].feedCommand.getJSON({ feed: 'video-comments', query: { version: 2 } }) |
278 | const jsonObj = JSON.parse(json) | |
1df8a4d7 C |
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 | ||
c1bc8ee4 C |
290 | const json = await servers[1].feedCommand.getJSON({ feed: 'video-comments', query: { version: 3 } }) |
291 | const jsonObj = JSON.parse(json) | |
696d83fd C |
292 | expect(jsonObj.items.length).to.be.equal(3) |
293 | } | |
294 | ||
295 | await addAccountToAccountBlocklist(servers[1].url, servers[1].accessToken, remoteHandle) | |
296 | ||
297 | { | |
c1bc8ee4 C |
298 | const json = await servers[1].feedCommand.getJSON({ feed: 'video-comments', query: { version: 4 } }) |
299 | const jsonObj = JSON.parse(json) | |
696d83fd C |
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 | ||
c1bc8ee4 C |
330 | const query = { accountId: feeduserAccountId, token: feeduserFeedToken } |
331 | const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query }) | |
332 | const jsonObj = JSON.parse(json) | |
afff310e RK |
333 | expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos |
334 | } | |
335 | }) | |
336 | ||
18490b07 | 337 | it('Should fail with an invalid token', async function () { |
c1bc8ee4 C |
338 | const query = { accountId: feeduserAccountId, token: 'toto' } |
339 | await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
18490b07 C |
340 | }) |
341 | ||
342 | it('Should fail with a token of another user', async function () { | |
c1bc8ee4 C |
343 | const query = { accountId: feeduserAccountId, token: userFeedToken } |
344 | await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
18490b07 C |
345 | }) |
346 | ||
afff310e | 347 | it('Should list no videos for a user with videos but no subscriptions', async function () { |
18490b07 C |
348 | const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken) |
349 | expect(res.body.total).to.equal(0) | |
afff310e | 350 | |
c1bc8ee4 C |
351 | const query = { accountId: userAccountId, token: userFeedToken } |
352 | const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query }) | |
353 | const jsonObj = JSON.parse(json) | |
18490b07 | 354 | expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos |
afff310e RK |
355 | }) |
356 | ||
357 | it('Should list self videos for a user with a subscription to themselves', async function () { | |
358 | this.timeout(30000) | |
359 | ||
360 | await addUserSubscription(servers[0].url, userAccessToken, 'john_channel@localhost:' + servers[0].port) | |
361 | await waitJobs(servers) | |
362 | ||
363 | { | |
364 | const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken) | |
365 | expect(res.body.total).to.equal(1) | |
366 | expect(res.body.data[0].name).to.equal('user video') | |
367 | ||
c1bc8ee4 C |
368 | const query = { accountId: userAccountId, token: userFeedToken, version: 1 } |
369 | const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query }) | |
370 | const jsonObj = JSON.parse(json) | |
afff310e RK |
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 | ||
c1bc8ee4 C |
385 | const query = { accountId: userAccountId, token: userFeedToken, version: 2 } |
386 | const json = await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query }) | |
387 | const jsonObj = JSON.parse(json) | |
afff310e RK |
388 | expect(jsonObj.items.length).to.be.equal(2) // subscribed to root, it should not list the instance's videos but list root/john's |
389 | } | |
390 | }) | |
391 | ||
18490b07 C |
392 | it('Should renew the token, and so have an invalid old token', async function () { |
393 | await renewUserScopedTokens(servers[0].url, userAccessToken) | |
394 | ||
c1bc8ee4 C |
395 | const query = { accountId: userAccountId, token: userFeedToken, version: 3 } |
396 | await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
18490b07 C |
397 | }) |
398 | ||
399 | it('Should succeed with the new token', async function () { | |
400 | const res2 = await getUserScopedTokens(servers[0].url, userAccessToken) | |
401 | const token: ScopedToken = res2.body | |
402 | userFeedToken = token.feedToken | |
403 | ||
c1bc8ee4 C |
404 | const query = { accountId: userAccountId, token: userFeedToken, version: 4 } |
405 | await servers[0].feedCommand.getJSON({ feed: 'subscriptions', query }) | |
18490b07 C |
406 | }) |
407 | ||
afff310e RK |
408 | }) |
409 | ||
7c3b7976 | 410 | after(async function () { |
97816649 | 411 | await cleanupTests([ ...servers, serverHLSOnly ]) |
fe3a55b0 C |
412 | }) |
413 | }) |