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