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,
25 } from '../../../shared/extra-utils'
26 import { waitJobs } from '../../../shared/extra-utils/server/jobs'
27 import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
28 import { User } from '../../../shared/models/users'
30 chai.use(require('chai-xml'))
31 chai.use(require('chai-json-schema'))
32 chai.config.includeStack = true
33 const expect = chai.expect
35 describe('Test syndication feeds', () => {
36 let servers: ServerInfo[] = []
37 let userAccessToken: string
38 let rootAccountId: number
39 let rootChannelId: number
40 let userAccountId: number
41 let userChannelId: number
43 before(async function () {
47 servers = await flushAndRunMultipleServers(2)
49 await setAccessTokensToServers(servers)
50 await doubleFollow(servers[0], servers[1])
53 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
54 const user: User = res.body
55 rootAccountId = user.account.id
56 rootChannelId = user.videoChannels[0].id
60 const attr = { username: 'john', password: 'password' }
61 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
62 userAccessToken = await userLogin(servers[0], attr)
64 const res = await getMyUserInformation(servers[0].url, userAccessToken)
65 const user: User = res.body
66 userAccountId = user.account.id
67 userChannelId = user.videoChannels[0].id
71 await uploadVideo(servers[0].url, userAccessToken, { name: 'user video' })
75 const videoAttributes = {
76 name: 'my super name for server 1',
77 description: 'my super description for server 1',
78 fixture: 'video_short.webm'
80 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
81 const videoId = res.body.video.id
83 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1')
84 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2')
88 const videoAttributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED }
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, 'comment on unlisted video')
95 await waitJobs(servers)
98 describe('All feed', function () {
100 it('Should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () {
101 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
102 const rss = await getXMLfeed(servers[0].url, feed)
103 expect(rss.text).xml.to.be.valid()
105 const atom = await getXMLfeed(servers[0].url, feed, 'atom')
106 expect(atom.text).xml.to.be.valid()
110 it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () {
111 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
112 const json = await getJSONfeed(servers[0].url, feed)
113 expect(JSON.parse(json.text)).to.be.jsonSchema({ type: 'object' })
118 describe('Videos feed', function () {
119 it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () {
120 for (const server of servers) {
121 const rss = await getXMLfeed(server.url, 'videos')
122 const xmlDoc = libxmljs.parseXmlString(rss.text)
123 const xmlEnclosure = xmlDoc.get('/rss/channel/item/enclosure')
124 expect(xmlEnclosure).to.exist
125 expect(xmlEnclosure.attr('type').value()).to.be.equal('application/x-bittorrent')
126 expect(xmlEnclosure.attr('length').value()).to.be.equal('218910')
127 expect(xmlEnclosure.attr('url').value()).to.contain('720.torrent')
131 it('Should contain a valid \'attachments\' object (covers JSON feed 1.0 endpoint)', async function () {
132 for (const server of servers) {
133 const json = await getJSONfeed(server.url, 'videos')
134 const jsonObj = JSON.parse(json.text)
135 expect(jsonObj.items.length).to.be.equal(2)
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')
144 it('Should filter by account', async function () {
146 const json = await getJSONfeed(servers[0].url, 'videos', { accountId: rootAccountId })
147 const jsonObj = JSON.parse(json.text)
148 expect(jsonObj.items.length).to.be.equal(1)
149 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
150 expect(jsonObj.items[0].author.name).to.equal('root')
154 const json = await getJSONfeed(servers[0].url, 'videos', { accountId: userAccountId })
155 const jsonObj = JSON.parse(json.text)
156 expect(jsonObj.items.length).to.be.equal(1)
157 expect(jsonObj.items[0].title).to.equal('user video')
158 expect(jsonObj.items[0].author.name).to.equal('john')
161 for (const server of servers) {
163 const json = await getJSONfeed(server.url, 'videos', { accountName: 'root@localhost:' + servers[0].port })
164 const jsonObj = JSON.parse(json.text)
165 expect(jsonObj.items.length).to.be.equal(1)
166 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
170 const json = await getJSONfeed(server.url, 'videos', { accountName: 'john@localhost:' + servers[0].port })
171 const jsonObj = JSON.parse(json.text)
172 expect(jsonObj.items.length).to.be.equal(1)
173 expect(jsonObj.items[0].title).to.equal('user video')
178 it('Should filter by video channel', async function () {
180 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: rootChannelId })
181 const jsonObj = JSON.parse(json.text)
182 expect(jsonObj.items.length).to.be.equal(1)
183 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
184 expect(jsonObj.items[0].author.name).to.equal('root')
188 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: userChannelId })
189 const jsonObj = JSON.parse(json.text)
190 expect(jsonObj.items.length).to.be.equal(1)
191 expect(jsonObj.items[0].title).to.equal('user video')
192 expect(jsonObj.items[0].author.name).to.equal('john')
195 for (const server of servers) {
197 const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'root_channel@localhost:' + servers[0].port })
198 const jsonObj = JSON.parse(json.text)
199 expect(jsonObj.items.length).to.be.equal(1)
200 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
204 const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'john_channel@localhost:' + servers[0].port })
205 const jsonObj = JSON.parse(json.text)
206 expect(jsonObj.items.length).to.be.equal(1)
207 expect(jsonObj.items[0].title).to.equal('user video')
213 describe('Video comments feed', function () {
215 it('Should contain valid comments (covers JSON feed 1.0 endpoint) and not from unlisted videos', async function () {
216 for (const server of servers) {
217 const json = await getJSONfeed(server.url, 'video-comments')
219 const jsonObj = JSON.parse(json.text)
220 expect(jsonObj.items.length).to.be.equal(2)
221 expect(jsonObj.items[0].html_content).to.equal('super comment 2')
222 expect(jsonObj.items[1].html_content).to.equal('super comment 1')
226 it('Should not list comments from muted accounts or instances', async function () {
229 const remoteHandle = 'root@localhost:' + servers[0].port
231 await addAccountToServerBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)
234 const json = await getJSONfeed(servers[1].url, 'video-comments', { version: 2 })
235 const jsonObj = JSON.parse(json.text)
236 expect(jsonObj.items.length).to.be.equal(0)
239 await removeAccountFromServerBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)
242 const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid
243 await waitJobs(servers)
244 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'super comment')
245 await waitJobs(servers)
247 const json = await getJSONfeed(servers[1].url, 'video-comments', { version: 3 })
248 const jsonObj = JSON.parse(json.text)
249 expect(jsonObj.items.length).to.be.equal(3)
252 await addAccountToAccountBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)
255 const json = await getJSONfeed(servers[1].url, 'video-comments', { version: 4 })
256 const jsonObj = JSON.parse(json.text)
257 expect(jsonObj.items.length).to.be.equal(2)
262 after(async function () {
263 await cleanupTests(servers)