]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { | |
6 | cleanupTests, | |
7 | createUser, | |
8 | doubleFollow, | |
9 | flushAndRunMultipleServers, | |
10 | getJSONfeed, | |
11 | getMyUserInformation, | |
12 | getXMLfeed, | |
13 | ServerInfo, | |
14 | setAccessTokensToServers, | |
15 | uploadVideo, | |
16 | userLogin | |
17 | } from '../../../shared/extra-utils' | |
18 | import * as libxmljs from 'libxmljs' | |
19 | import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments' | |
20 | import { waitJobs } from '../../../shared/extra-utils/server/jobs' | |
21 | import { User } from '../../../shared/models/users' | |
22 | import { VideoPrivacy } from '@shared/models' | |
23 | import { addAccountToServerBlocklist } from '@shared/extra-utils/users/blocklist' | |
24 | ||
25 | chai.use(require('chai-xml')) | |
26 | chai.use(require('chai-json-schema')) | |
27 | chai.config.includeStack = true | |
28 | const expect = chai.expect | |
29 | ||
30 | describe('Test syndication feeds', () => { | |
31 | let servers: ServerInfo[] = [] | |
32 | let userAccessToken: string | |
33 | let rootAccountId: number | |
34 | let rootChannelId: number | |
35 | let userAccountId: number | |
36 | let userChannelId: number | |
37 | ||
38 | before(async function () { | |
39 | this.timeout(120000) | |
40 | ||
41 | // Run servers | |
42 | servers = await flushAndRunMultipleServers(2) | |
43 | ||
44 | await setAccessTokensToServers(servers) | |
45 | await doubleFollow(servers[0], servers[1]) | |
46 | ||
47 | { | |
48 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | |
49 | const user: User = res.body | |
50 | rootAccountId = user.account.id | |
51 | rootChannelId = user.videoChannels[0].id | |
52 | } | |
53 | ||
54 | { | |
55 | const attr = { username: 'john', password: 'password' } | |
56 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password }) | |
57 | userAccessToken = await userLogin(servers[0], attr) | |
58 | ||
59 | const res = await getMyUserInformation(servers[0].url, userAccessToken) | |
60 | const user: User = res.body | |
61 | userAccountId = user.account.id | |
62 | userChannelId = user.videoChannels[0].id | |
63 | } | |
64 | ||
65 | { | |
66 | await uploadVideo(servers[0].url, userAccessToken, { name: 'user video' }) | |
67 | } | |
68 | ||
69 | { | |
70 | const videoAttributes = { | |
71 | name: 'my super name for server 1', | |
72 | description: 'my super description for server 1', | |
73 | fixture: 'video_short.webm' | |
74 | } | |
75 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | |
76 | const videoId = res.body.video.id | |
77 | ||
78 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1') | |
79 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2') | |
80 | } | |
81 | ||
82 | { | |
83 | const videoAttributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED } | |
84 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | |
85 | const videoId = res.body.video.id | |
86 | ||
87 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'comment on unlisted video') | |
88 | } | |
89 | ||
90 | await waitJobs(servers) | |
91 | }) | |
92 | ||
93 | describe('All feed', function () { | |
94 | ||
95 | it('Should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () { | |
96 | for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) { | |
97 | const rss = await getXMLfeed(servers[0].url, feed) | |
98 | expect(rss.text).xml.to.be.valid() | |
99 | ||
100 | const atom = await getXMLfeed(servers[0].url, feed, 'atom') | |
101 | expect(atom.text).xml.to.be.valid() | |
102 | } | |
103 | }) | |
104 | ||
105 | it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () { | |
106 | for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) { | |
107 | const json = await getJSONfeed(servers[0].url, feed) | |
108 | expect(JSON.parse(json.text)).to.be.jsonSchema({ type: 'object' }) | |
109 | } | |
110 | }) | |
111 | }) | |
112 | ||
113 | describe('Videos feed', function () { | |
114 | it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () { | |
115 | for (const server of servers) { | |
116 | const rss = await getXMLfeed(server.url, 'videos') | |
117 | const xmlDoc = libxmljs.parseXmlString(rss.text) | |
118 | const xmlEnclosure = xmlDoc.get('/rss/channel/item/enclosure') | |
119 | expect(xmlEnclosure).to.exist | |
120 | expect(xmlEnclosure.attr('type').value()).to.be.equal('application/x-bittorrent') | |
121 | expect(xmlEnclosure.attr('length').value()).to.be.equal('218910') | |
122 | expect(xmlEnclosure.attr('url').value()).to.contain('720.torrent') | |
123 | } | |
124 | }) | |
125 | ||
126 | it('Should contain a valid \'attachments\' object (covers JSON feed 1.0 endpoint)', async function () { | |
127 | for (const server of servers) { | |
128 | const json = await getJSONfeed(server.url, 'videos') | |
129 | const jsonObj = JSON.parse(json.text) | |
130 | expect(jsonObj.items.length).to.be.equal(2) | |
131 | expect(jsonObj.items[0].attachments).to.exist | |
132 | expect(jsonObj.items[0].attachments.length).to.be.eq(1) | |
133 | expect(jsonObj.items[0].attachments[0].mime_type).to.be.eq('application/x-bittorrent') | |
134 | expect(jsonObj.items[0].attachments[0].size_in_bytes).to.be.eq(218910) | |
135 | expect(jsonObj.items[0].attachments[0].url).to.contain('720.torrent') | |
136 | } | |
137 | }) | |
138 | ||
139 | it('Should filter by account', async function () { | |
140 | { | |
141 | const json = await getJSONfeed(servers[0].url, 'videos', { accountId: rootAccountId }) | |
142 | const jsonObj = JSON.parse(json.text) | |
143 | expect(jsonObj.items.length).to.be.equal(1) | |
144 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') | |
145 | expect(jsonObj.items[0].author.name).to.equal('root') | |
146 | } | |
147 | ||
148 | { | |
149 | const json = await getJSONfeed(servers[0].url, 'videos', { accountId: userAccountId }) | |
150 | const jsonObj = JSON.parse(json.text) | |
151 | expect(jsonObj.items.length).to.be.equal(1) | |
152 | expect(jsonObj.items[0].title).to.equal('user video') | |
153 | expect(jsonObj.items[0].author.name).to.equal('john') | |
154 | } | |
155 | ||
156 | for (const server of servers) { | |
157 | { | |
158 | const json = await getJSONfeed(server.url, 'videos', { accountName: 'root@localhost:' + servers[0].port }) | |
159 | const jsonObj = JSON.parse(json.text) | |
160 | expect(jsonObj.items.length).to.be.equal(1) | |
161 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') | |
162 | } | |
163 | ||
164 | { | |
165 | const json = await getJSONfeed(server.url, 'videos', { accountName: 'john@localhost:' + servers[0].port }) | |
166 | const jsonObj = JSON.parse(json.text) | |
167 | expect(jsonObj.items.length).to.be.equal(1) | |
168 | expect(jsonObj.items[0].title).to.equal('user video') | |
169 | } | |
170 | } | |
171 | }) | |
172 | ||
173 | it('Should filter by video channel', async function () { | |
174 | { | |
175 | const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: rootChannelId }) | |
176 | const jsonObj = JSON.parse(json.text) | |
177 | expect(jsonObj.items.length).to.be.equal(1) | |
178 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') | |
179 | expect(jsonObj.items[0].author.name).to.equal('root') | |
180 | } | |
181 | ||
182 | { | |
183 | const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: userChannelId }) | |
184 | const jsonObj = JSON.parse(json.text) | |
185 | expect(jsonObj.items.length).to.be.equal(1) | |
186 | expect(jsonObj.items[0].title).to.equal('user video') | |
187 | expect(jsonObj.items[0].author.name).to.equal('john') | |
188 | } | |
189 | ||
190 | for (const server of servers) { | |
191 | { | |
192 | const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'root_channel@localhost:' + servers[0].port }) | |
193 | const jsonObj = JSON.parse(json.text) | |
194 | expect(jsonObj.items.length).to.be.equal(1) | |
195 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') | |
196 | } | |
197 | ||
198 | { | |
199 | const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'john_channel@localhost:' + servers[0].port }) | |
200 | const jsonObj = JSON.parse(json.text) | |
201 | expect(jsonObj.items.length).to.be.equal(1) | |
202 | expect(jsonObj.items[0].title).to.equal('user video') | |
203 | } | |
204 | } | |
205 | }) | |
206 | }) | |
207 | ||
208 | describe('Video comments feed', function () { | |
209 | ||
210 | it('Should contain valid comments (covers JSON feed 1.0 endpoint) and not from unlisted videos', async function () { | |
211 | for (const server of servers) { | |
212 | const json = await getJSONfeed(server.url, 'video-comments') | |
213 | ||
214 | const jsonObj = JSON.parse(json.text) | |
215 | expect(jsonObj.items.length).to.be.equal(2) | |
216 | expect(jsonObj.items[0].html_content).to.equal('super comment 2') | |
217 | expect(jsonObj.items[1].html_content).to.equal('super comment 1') | |
218 | } | |
219 | }) | |
220 | ||
221 | it('Should not list comments from muted accounts or instances', async function () { | |
222 | await addAccountToServerBlocklist(servers[1].url, servers[1].accessToken, 'root@localhost:' + servers[0].port) | |
223 | ||
224 | { | |
225 | const json = await getJSONfeed(servers[1].url, 'video-comments', { version: 2 }) | |
226 | const jsonObj = JSON.parse(json.text) | |
227 | expect(jsonObj.items.length).to.be.equal(0) | |
228 | } | |
229 | ||
230 | }) | |
231 | }) | |
232 | ||
233 | after(async function () { | |
234 | await cleanupTests(servers) | |
235 | }) | |
236 | }) |