]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/feeds/feeds.ts
Fix RSS feed when HLS only is enabled
[github/Chocobozzz/PeerTube.git] / server / tests / feeds / feeds.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
fe3a55b0 2
fe3a55b0 3import 'mocha'
696d83fd
C
4import * as chai from 'chai'
5import * as libxmljs from 'libxmljs'
6import {
7 addAccountToAccountBlocklist,
8 addAccountToServerBlocklist,
9 removeAccountFromServerBlocklist
10} from '@shared/extra-utils/users/blocklist'
11import { VideoPrivacy } from '@shared/models'
fe3a55b0 12import {
7c3b7976 13 cleanupTests,
662fb3ab 14 createUser,
fe3a55b0
C
15 doubleFollow,
16 flushAndRunMultipleServers,
57cfff78
C
17 getJSONfeed,
18 getMyUserInformation,
fe3a55b0 19 getXMLfeed,
fe3a55b0
C
20 ServerInfo,
21 setAccessTokensToServers,
57cfff78 22 uploadVideo,
696d83fd 23 uploadVideoAndGetId,
97816649
C
24 userLogin,
25 flushAndRunServer
94565d52 26} from '../../../shared/extra-utils'
94565d52 27import { waitJobs } from '../../../shared/extra-utils/server/jobs'
696d83fd 28import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
662fb3ab 29import { User } from '../../../shared/models/users'
fe3a55b0
C
30
31chai.use(require('chai-xml'))
32chai.use(require('chai-json-schema'))
33chai.config.includeStack = true
34const expect = chai.expect
35
36describe('Test syndication feeds', () => {
37 let servers: ServerInfo[] = []
97816649 38 let serverHLSOnly: ServerInfo
662fb3ab 39 let userAccessToken: string
57cfff78
C
40 let rootAccountId: number
41 let rootChannelId: number
42 let userAccountId: number
43 let userChannelId: number
fe3a55b0
C
44
45 before(async function () {
46 this.timeout(120000)
47
48 // Run servers
49 servers = await flushAndRunMultipleServers(2)
97816649
C
50 serverHLSOnly = await flushAndRunServer(3, {
51 transcoding: {
52 enabled: true,
53 webtorrent: { enabled: false },
54 hls: { enabled: true }
55 }
56 })
fe3a55b0 57
97816649 58 await setAccessTokensToServers([ ...servers, serverHLSOnly ])
fe3a55b0
C
59 await doubleFollow(servers[0], servers[1])
60
662fb3ab
C
61 {
62 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
63 const user: User = res.body
57cfff78
C
64 rootAccountId = user.account.id
65 rootChannelId = user.videoChannels[0].id
fe3a55b0 66 }
fe3a55b0 67
662fb3ab
C
68 {
69 const attr = { username: 'john', password: 'password' }
a1587156 70 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
662fb3ab
C
71 userAccessToken = await userLogin(servers[0], attr)
72
73 const res = await getMyUserInformation(servers[0].url, userAccessToken)
74 const user: User = res.body
57cfff78
C
75 userAccountId = user.account.id
76 userChannelId = user.videoChannels[0].id
662fb3ab
C
77 }
78
79 {
a1587156 80 await uploadVideo(servers[0].url, userAccessToken, { name: 'user video' })
662fb3ab
C
81 }
82
83 {
84 const videoAttributes = {
85 name: 'my super name for server 1',
86 description: 'my super description for server 1',
87 fixture: 'video_short.webm'
88 }
a1587156 89 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
662fb3ab
C
90 const videoId = res.body.video.id
91
a1587156
C
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')
662fb3ab 94 }
fe3a55b0 95
68b6fd21
C
96 {
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
100
101 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'comment on unlisted video')
102 }
103
3cd0734f 104 await waitJobs(servers)
fe3a55b0
C
105 })
106
107 describe('All feed', function () {
108
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' ]) {
a1587156 111 const rss = await getXMLfeed(servers[0].url, feed)
fe3a55b0
C
112 expect(rss.text).xml.to.be.valid()
113
a1587156 114 const atom = await getXMLfeed(servers[0].url, feed, 'atom')
fe3a55b0
C
115 expect(atom.text).xml.to.be.valid()
116 }
117 })
118
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' ]) {
a1587156
C
121 const json = await getJSONfeed(servers[0].url, feed)
122 expect(JSON.parse(json.text)).to.be.jsonSchema({ type: 'object' })
fe3a55b0
C
123 }
124 })
125 })
126
127 describe('Videos feed', function () {
97816649 128
fe3a55b0
C
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')
138 }
139 })
140
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)
662fb3ab 145 expect(jsonObj.items.length).to.be.equal(2)
a1587156
C
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')
fe3a55b0
C
151 }
152 })
662fb3ab
C
153
154 it('Should filter by account', async function () {
57cfff78
C
155 {
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)
a1587156
C
159 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
160 expect(jsonObj.items[0].author.name).to.equal('root')
57cfff78
C
161 }
162
163 {
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)
a1587156
C
167 expect(jsonObj.items[0].title).to.equal('user video')
168 expect(jsonObj.items[0].author.name).to.equal('john')
57cfff78
C
169 }
170
662fb3ab
C
171 for (const server of servers) {
172 {
57cfff78 173 const json = await getJSONfeed(server.url, 'videos', { accountName: 'root@localhost:' + servers[0].port })
662fb3ab
C
174 const jsonObj = JSON.parse(json.text)
175 expect(jsonObj.items.length).to.be.equal(1)
a1587156 176 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
662fb3ab
C
177 }
178
179 {
57cfff78 180 const json = await getJSONfeed(server.url, 'videos', { accountName: 'john@localhost:' + servers[0].port })
662fb3ab
C
181 const jsonObj = JSON.parse(json.text)
182 expect(jsonObj.items.length).to.be.equal(1)
a1587156 183 expect(jsonObj.items[0].title).to.equal('user video')
662fb3ab
C
184 }
185 }
57cfff78 186 })
662fb3ab 187
57cfff78 188 it('Should filter by video channel', async function () {
662fb3ab 189 {
57cfff78 190 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: rootChannelId })
662fb3ab
C
191 const jsonObj = JSON.parse(json.text)
192 expect(jsonObj.items.length).to.be.equal(1)
a1587156
C
193 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
194 expect(jsonObj.items[0].author.name).to.equal('root')
662fb3ab
C
195 }
196
197 {
57cfff78 198 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: userChannelId })
662fb3ab
C
199 const jsonObj = JSON.parse(json.text)
200 expect(jsonObj.items.length).to.be.equal(1)
a1587156
C
201 expect(jsonObj.items[0].title).to.equal('user video')
202 expect(jsonObj.items[0].author.name).to.equal('john')
662fb3ab 203 }
662fb3ab 204
662fb3ab
C
205 for (const server of servers) {
206 {
57cfff78 207 const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'root_channel@localhost:' + servers[0].port })
662fb3ab
C
208 const jsonObj = JSON.parse(json.text)
209 expect(jsonObj.items.length).to.be.equal(1)
a1587156 210 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
662fb3ab
C
211 }
212
213 {
57cfff78 214 const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'john_channel@localhost:' + servers[0].port })
662fb3ab
C
215 const jsonObj = JSON.parse(json.text)
216 expect(jsonObj.items.length).to.be.equal(1)
a1587156 217 expect(jsonObj.items[0].title).to.equal('user video')
662fb3ab
C
218 }
219 }
662fb3ab 220 })
97816649
C
221
222 it('Should correctly have videos feed with HLS only', async function () {
223 this.timeout(120000)
224
225 await uploadVideo(serverHLSOnly.url, serverHLSOnly.accessToken, { name: 'hls only video' })
226
227 await waitJobs([ serverHLSOnly ])
228
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)
234
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
239 }
240 })
fe3a55b0
C
241 })
242
243 describe('Video comments feed', function () {
68b6fd21
C
244
245 it('Should contain valid comments (covers JSON feed 1.0 endpoint) and not from unlisted videos', async function () {
fe3a55b0
C
246 for (const server of servers) {
247 const json = await getJSONfeed(server.url, 'video-comments')
248
249 const jsonObj = JSON.parse(json.text)
250 expect(jsonObj.items.length).to.be.equal(2)
a1587156
C
251 expect(jsonObj.items[0].html_content).to.equal('super comment 2')
252 expect(jsonObj.items[1].html_content).to.equal('super comment 1')
fe3a55b0
C
253 }
254 })
1df8a4d7
C
255
256 it('Should not list comments from muted accounts or instances', async function () {
696d83fd
C
257 this.timeout(30000)
258
259 const remoteHandle = 'root@localhost:' + servers[0].port
260
261 await addAccountToServerBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)
1df8a4d7
C
262
263 {
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)
267 }
268
696d83fd
C
269 await removeAccountFromServerBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)
270
271 {
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)
276
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)
280 }
281
282 await addAccountToAccountBlocklist(servers[1].url, servers[1].accessToken, remoteHandle)
283
284 {
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)
288 }
1df8a4d7 289 })
fe3a55b0
C
290 })
291
7c3b7976 292 after(async function () {
97816649 293 await cleanupTests([ ...servers, serverHLSOnly ])
fe3a55b0
C
294 })
295})