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