1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import * as libxmljs from 'libxmljs'
7 addAccountToAccountBlocklist,
8 addAccountToServerBlocklist,
9 removeAccountFromServerBlocklist
10 } from '@shared/extra-utils/users/blocklist'
11 import { VideoPrivacy } from '@shared/models'
16 flushAndRunMultipleServers,
21 setAccessTokensToServers,
26 } from '../../../shared/extra-utils'
27 import { waitJobs } from '../../../shared/extra-utils/server/jobs'
28 import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
29 import { User } from '../../../shared/models/users'
31 chai.use(require('chai-xml'))
32 chai.use(require('chai-json-schema'))
33 chai.config.includeStack = true
34 const expect = chai.expect
36 describe('Test syndication feeds', () => {
37 let servers: ServerInfo[] = []
38 let serverHLSOnly: ServerInfo
39 let userAccessToken: string
40 let rootAccountId: number
41 let rootChannelId: number
42 let userAccountId: number
43 let userChannelId: number
45 before(async function () {
49 servers = await flushAndRunMultipleServers(2)
50 serverHLSOnly = await flushAndRunServer(3, {
53 webtorrent: { enabled: false },
54 hls: { enabled: true }
58 await setAccessTokensToServers([ ...servers, serverHLSOnly ])
59 await doubleFollow(servers[0], servers[1])
62 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
63 const user: User = res.body
64 rootAccountId = user.account.id
65 rootChannelId = user.videoChannels[0].id
69 const attr = { username: 'john', password: 'password' }
70 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
71 userAccessToken = await userLogin(servers[0], attr)
73 const res = await getMyUserInformation(servers[0].url, userAccessToken)
74 const user: User = res.body
75 userAccountId = user.account.id
76 userChannelId = user.videoChannels[0].id
80 await uploadVideo(servers[0].url, userAccessToken, { name: 'user video' })
84 const videoAttributes = {
85 name: 'my super name for server 1',
86 description: 'my super description for server 1',
87 fixture: 'video_short.webm'
89 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
90 const videoId = res.body.video.id
92 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1')
93 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2')
97 const videoAttributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED }
98 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
99 const videoId = res.body.video.id
101 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'comment on unlisted video')
104 await waitJobs(servers)
107 describe('All feed', function () {
109 it('Should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () {
110 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
111 const rss = await getXMLfeed(servers[0].url, feed)
112 expect(rss.text).xml.to.be.valid()
114 const atom = await getXMLfeed(servers[0].url, feed, 'atom')
115 expect(atom.text).xml.to.be.valid()
119 it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () {
120 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
121 const json = await getJSONfeed(servers[0].url, feed)
122 expect(JSON.parse(json.text)).to.be.jsonSchema({ type: 'object' })
127 describe('Videos feed', function () {
129 it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () {
130 for (const server of servers) {
131 const rss = await getXMLfeed(server.url, 'videos')
132 const xmlDoc = libxmljs.parseXmlString(rss.text)
133 const xmlEnclosure = xmlDoc.get('/rss/channel/item/enclosure')
134 expect(xmlEnclosure).to.exist
135 expect(xmlEnclosure.attr('type').value()).to.be.equal('application/x-bittorrent')
136 expect(xmlEnclosure.attr('length').value()).to.be.equal('218910')
137 expect(xmlEnclosure.attr('url').value()).to.contain('720.torrent')
141 it('Should contain a valid \'attachments\' object (covers JSON feed 1.0 endpoint)', async function () {
142 for (const server of servers) {
143 const json = await getJSONfeed(server.url, 'videos')
144 const jsonObj = JSON.parse(json.text)
145 expect(jsonObj.items.length).to.be.equal(2)
146 expect(jsonObj.items[0].attachments).to.exist
147 expect(jsonObj.items[0].attachments.length).to.be.eq(1)
148 expect(jsonObj.items[0].attachments[0].mime_type).to.be.eq('application/x-bittorrent')
149 expect(jsonObj.items[0].attachments[0].size_in_bytes).to.be.eq(218910)
150 expect(jsonObj.items[0].attachments[0].url).to.contain('720.torrent')
154 it('Should filter by account', async function () {
156 const json = await getJSONfeed(servers[0].url, 'videos', { accountId: rootAccountId })
157 const jsonObj = JSON.parse(json.text)
158 expect(jsonObj.items.length).to.be.equal(1)
159 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
160 expect(jsonObj.items[0].author.name).to.equal('root')
164 const json = await getJSONfeed(servers[0].url, 'videos', { accountId: userAccountId })
165 const jsonObj = JSON.parse(json.text)
166 expect(jsonObj.items.length).to.be.equal(1)
167 expect(jsonObj.items[0].title).to.equal('user video')
168 expect(jsonObj.items[0].author.name).to.equal('john')
171 for (const server of servers) {
173 const json = await getJSONfeed(server.url, 'videos', { accountName: 'root@localhost:' + servers[0].port })
174 const jsonObj = JSON.parse(json.text)
175 expect(jsonObj.items.length).to.be.equal(1)
176 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
180 const json = await getJSONfeed(server.url, 'videos', { accountName: 'john@localhost:' + servers[0].port })
181 const jsonObj = JSON.parse(json.text)
182 expect(jsonObj.items.length).to.be.equal(1)
183 expect(jsonObj.items[0].title).to.equal('user video')
188 it('Should filter by video channel', async function () {
190 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: rootChannelId })
191 const jsonObj = JSON.parse(json.text)
192 expect(jsonObj.items.length).to.be.equal(1)
193 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
194 expect(jsonObj.items[0].author.name).to.equal('root')
198 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: userChannelId })
199 const jsonObj = JSON.parse(json.text)
200 expect(jsonObj.items.length).to.be.equal(1)
201 expect(jsonObj.items[0].title).to.equal('user video')
202 expect(jsonObj.items[0].author.name).to.equal('john')
205 for (const server of servers) {
207 const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'root_channel@localhost:' + servers[0].port })
208 const jsonObj = JSON.parse(json.text)
209 expect(jsonObj.items.length).to.be.equal(1)
210 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
214 const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'john_channel@localhost:' + servers[0].port })
215 const jsonObj = JSON.parse(json.text)
216 expect(jsonObj.items.length).to.be.equal(1)
217 expect(jsonObj.items[0].title).to.equal('user video')
222 it('Should correctly have videos feed with HLS only', async function () {
225 await uploadVideo(serverHLSOnly.url, serverHLSOnly.accessToken, { name: 'hls only video' })
227 await waitJobs([ serverHLSOnly ])
229 const json = await getJSONfeed(serverHLSOnly.url, 'videos')
230 const jsonObj = JSON.parse(json.text)
231 expect(jsonObj.items.length).to.be.equal(1)
232 expect(jsonObj.items[0].attachments).to.exist
233 expect(jsonObj.items[0].attachments.length).to.be.eq(4)
235 for (let i = 0; i < 4; i++) {
236 expect(jsonObj.items[0].attachments[i].mime_type).to.be.eq('application/x-bittorrent')
237 expect(jsonObj.items[0].attachments[i].size_in_bytes).to.be.greaterThan(0)
238 expect(jsonObj.items[0].attachments[i].url).to.exist
243 describe('Video comments feed', function () {
245 it('Should contain valid comments (covers JSON feed 1.0 endpoint) and not from unlisted videos', async function () {
246 for (const server of servers) {
247 const json = await getJSONfeed(server.url, 'video-comments')
249 const jsonObj = JSON.parse(json.text)
250 expect(jsonObj.items.length).to.be.equal(2)
251 expect(jsonObj.items[0].html_content).to.equal('super comment 2')
252 expect(jsonObj.items[1].html_content).to.equal('super comment 1')
256 it('Should not list comments from muted accounts or instances', async function () {
259 const remoteHandle = 'root@localhost:' + servers[0].port
261 await addAccountToServerBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)
264 const json = await getJSONfeed(servers[1].url, 'video-comments', { version: 2 })
265 const jsonObj = JSON.parse(json.text)
266 expect(jsonObj.items.length).to.be.equal(0)
269 await removeAccountFromServerBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)
272 const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid
273 await waitJobs(servers)
274 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'super comment')
275 await waitJobs(servers)
277 const json = await getJSONfeed(servers[1].url, 'video-comments', { version: 3 })
278 const jsonObj = JSON.parse(json.text)
279 expect(jsonObj.items.length).to.be.equal(3)
282 await addAccountToAccountBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)
285 const json = await getJSONfeed(servers[1].url, 'video-comments', { version: 4 })
286 const jsonObj = JSON.parse(json.text)
287 expect(jsonObj.items.length).to.be.equal(2)
292 after(async function () {
293 await cleanupTests([ ...servers, serverHLSOnly ])