diff options
Diffstat (limited to 'server/tests/feeds')
-rw-r--r-- | server/tests/feeds/feeds.ts | 82 |
1 files changed, 52 insertions, 30 deletions
diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts index 437470327..7fac921a3 100644 --- a/server/tests/feeds/feeds.ts +++ b/server/tests/feeds/feeds.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | 4 | import 'mocha' |
@@ -19,6 +19,8 @@ import * as libxmljs from 'libxmljs' | |||
19 | import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments' | 19 | import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments' |
20 | import { waitJobs } from '../../../shared/extra-utils/server/jobs' | 20 | import { waitJobs } from '../../../shared/extra-utils/server/jobs' |
21 | import { User } from '../../../shared/models/users' | 21 | import { User } from '../../../shared/models/users' |
22 | import { VideoPrivacy } from '@shared/models' | ||
23 | import { addAccountToServerBlocklist } from '@shared/extra-utils/users/blocklist' | ||
22 | 24 | ||
23 | chai.use(require('chai-xml')) | 25 | chai.use(require('chai-xml')) |
24 | chai.use(require('chai-json-schema')) | 26 | chai.use(require('chai-json-schema')) |
@@ -51,7 +53,7 @@ describe('Test syndication feeds', () => { | |||
51 | 53 | ||
52 | { | 54 | { |
53 | const attr = { username: 'john', password: 'password' } | 55 | const attr = { username: 'john', password: 'password' } |
54 | await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: attr.username, password: attr.password }) | 56 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password }) |
55 | userAccessToken = await userLogin(servers[0], attr) | 57 | userAccessToken = await userLogin(servers[0], attr) |
56 | 58 | ||
57 | const res = await getMyUserInformation(servers[0].url, userAccessToken) | 59 | const res = await getMyUserInformation(servers[0].url, userAccessToken) |
@@ -61,7 +63,7 @@ describe('Test syndication feeds', () => { | |||
61 | } | 63 | } |
62 | 64 | ||
63 | { | 65 | { |
64 | await uploadVideo(servers[ 0 ].url, userAccessToken, { name: 'user video' }) | 66 | await uploadVideo(servers[0].url, userAccessToken, { name: 'user video' }) |
65 | } | 67 | } |
66 | 68 | ||
67 | { | 69 | { |
@@ -70,11 +72,19 @@ describe('Test syndication feeds', () => { | |||
70 | description: 'my super description for server 1', | 72 | description: 'my super description for server 1', |
71 | fixture: 'video_short.webm' | 73 | fixture: 'video_short.webm' |
72 | } | 74 | } |
73 | const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes) | 75 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) |
74 | const videoId = res.body.video.id | 76 | const videoId = res.body.video.id |
75 | 77 | ||
76 | await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoId, 'super comment 1') | 78 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1') |
77 | await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoId, 'super comment 2') | 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') | ||
78 | } | 88 | } |
79 | 89 | ||
80 | await waitJobs(servers) | 90 | await waitJobs(servers) |
@@ -84,18 +94,18 @@ describe('Test syndication feeds', () => { | |||
84 | 94 | ||
85 | it('Should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () { | 95 | it('Should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () { |
86 | for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) { | 96 | for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) { |
87 | const rss = await getXMLfeed(servers[ 0 ].url, feed) | 97 | const rss = await getXMLfeed(servers[0].url, feed) |
88 | expect(rss.text).xml.to.be.valid() | 98 | expect(rss.text).xml.to.be.valid() |
89 | 99 | ||
90 | const atom = await getXMLfeed(servers[ 0 ].url, feed, 'atom') | 100 | const atom = await getXMLfeed(servers[0].url, feed, 'atom') |
91 | expect(atom.text).xml.to.be.valid() | 101 | expect(atom.text).xml.to.be.valid() |
92 | } | 102 | } |
93 | }) | 103 | }) |
94 | 104 | ||
95 | it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () { | 105 | it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () { |
96 | for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) { | 106 | for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) { |
97 | const json = await getJSONfeed(servers[ 0 ].url, feed) | 107 | const json = await getJSONfeed(servers[0].url, feed) |
98 | expect(JSON.parse(json.text)).to.be.jsonSchema({ 'type': 'object' }) | 108 | expect(JSON.parse(json.text)).to.be.jsonSchema({ type: 'object' }) |
99 | } | 109 | } |
100 | }) | 110 | }) |
101 | }) | 111 | }) |
@@ -118,11 +128,11 @@ describe('Test syndication feeds', () => { | |||
118 | const json = await getJSONfeed(server.url, 'videos') | 128 | const json = await getJSONfeed(server.url, 'videos') |
119 | const jsonObj = JSON.parse(json.text) | 129 | const jsonObj = JSON.parse(json.text) |
120 | expect(jsonObj.items.length).to.be.equal(2) | 130 | expect(jsonObj.items.length).to.be.equal(2) |
121 | expect(jsonObj.items[ 0 ].attachments).to.exist | 131 | expect(jsonObj.items[0].attachments).to.exist |
122 | expect(jsonObj.items[ 0 ].attachments.length).to.be.eq(1) | 132 | expect(jsonObj.items[0].attachments.length).to.be.eq(1) |
123 | expect(jsonObj.items[ 0 ].attachments[ 0 ].mime_type).to.be.eq('application/x-bittorrent') | 133 | expect(jsonObj.items[0].attachments[0].mime_type).to.be.eq('application/x-bittorrent') |
124 | expect(jsonObj.items[ 0 ].attachments[ 0 ].size_in_bytes).to.be.eq(218910) | 134 | expect(jsonObj.items[0].attachments[0].size_in_bytes).to.be.eq(218910) |
125 | expect(jsonObj.items[ 0 ].attachments[ 0 ].url).to.contain('720.torrent') | 135 | expect(jsonObj.items[0].attachments[0].url).to.contain('720.torrent') |
126 | } | 136 | } |
127 | }) | 137 | }) |
128 | 138 | ||
@@ -131,16 +141,16 @@ describe('Test syndication feeds', () => { | |||
131 | const json = await getJSONfeed(servers[0].url, 'videos', { accountId: rootAccountId }) | 141 | const json = await getJSONfeed(servers[0].url, 'videos', { accountId: rootAccountId }) |
132 | const jsonObj = JSON.parse(json.text) | 142 | const jsonObj = JSON.parse(json.text) |
133 | expect(jsonObj.items.length).to.be.equal(1) | 143 | expect(jsonObj.items.length).to.be.equal(1) |
134 | expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1') | 144 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') |
135 | expect(jsonObj.items[ 0 ].author.name).to.equal('root') | 145 | expect(jsonObj.items[0].author.name).to.equal('root') |
136 | } | 146 | } |
137 | 147 | ||
138 | { | 148 | { |
139 | const json = await getJSONfeed(servers[0].url, 'videos', { accountId: userAccountId }) | 149 | const json = await getJSONfeed(servers[0].url, 'videos', { accountId: userAccountId }) |
140 | const jsonObj = JSON.parse(json.text) | 150 | const jsonObj = JSON.parse(json.text) |
141 | expect(jsonObj.items.length).to.be.equal(1) | 151 | expect(jsonObj.items.length).to.be.equal(1) |
142 | expect(jsonObj.items[ 0 ].title).to.equal('user video') | 152 | expect(jsonObj.items[0].title).to.equal('user video') |
143 | expect(jsonObj.items[ 0 ].author.name).to.equal('john') | 153 | expect(jsonObj.items[0].author.name).to.equal('john') |
144 | } | 154 | } |
145 | 155 | ||
146 | for (const server of servers) { | 156 | for (const server of servers) { |
@@ -148,14 +158,14 @@ describe('Test syndication feeds', () => { | |||
148 | const json = await getJSONfeed(server.url, 'videos', { accountName: 'root@localhost:' + servers[0].port }) | 158 | const json = await getJSONfeed(server.url, 'videos', { accountName: 'root@localhost:' + servers[0].port }) |
149 | const jsonObj = JSON.parse(json.text) | 159 | const jsonObj = JSON.parse(json.text) |
150 | expect(jsonObj.items.length).to.be.equal(1) | 160 | expect(jsonObj.items.length).to.be.equal(1) |
151 | expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1') | 161 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') |
152 | } | 162 | } |
153 | 163 | ||
154 | { | 164 | { |
155 | const json = await getJSONfeed(server.url, 'videos', { accountName: 'john@localhost:' + servers[0].port }) | 165 | const json = await getJSONfeed(server.url, 'videos', { accountName: 'john@localhost:' + servers[0].port }) |
156 | const jsonObj = JSON.parse(json.text) | 166 | const jsonObj = JSON.parse(json.text) |
157 | expect(jsonObj.items.length).to.be.equal(1) | 167 | expect(jsonObj.items.length).to.be.equal(1) |
158 | expect(jsonObj.items[ 0 ].title).to.equal('user video') | 168 | expect(jsonObj.items[0].title).to.equal('user video') |
159 | } | 169 | } |
160 | } | 170 | } |
161 | }) | 171 | }) |
@@ -165,16 +175,16 @@ describe('Test syndication feeds', () => { | |||
165 | const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: rootChannelId }) | 175 | const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: rootChannelId }) |
166 | const jsonObj = JSON.parse(json.text) | 176 | const jsonObj = JSON.parse(json.text) |
167 | expect(jsonObj.items.length).to.be.equal(1) | 177 | expect(jsonObj.items.length).to.be.equal(1) |
168 | expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1') | 178 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') |
169 | expect(jsonObj.items[ 0 ].author.name).to.equal('root') | 179 | expect(jsonObj.items[0].author.name).to.equal('root') |
170 | } | 180 | } |
171 | 181 | ||
172 | { | 182 | { |
173 | const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: userChannelId }) | 183 | const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: userChannelId }) |
174 | const jsonObj = JSON.parse(json.text) | 184 | const jsonObj = JSON.parse(json.text) |
175 | expect(jsonObj.items.length).to.be.equal(1) | 185 | expect(jsonObj.items.length).to.be.equal(1) |
176 | expect(jsonObj.items[ 0 ].title).to.equal('user video') | 186 | expect(jsonObj.items[0].title).to.equal('user video') |
177 | expect(jsonObj.items[ 0 ].author.name).to.equal('john') | 187 | expect(jsonObj.items[0].author.name).to.equal('john') |
178 | } | 188 | } |
179 | 189 | ||
180 | for (const server of servers) { | 190 | for (const server of servers) { |
@@ -182,30 +192,42 @@ describe('Test syndication feeds', () => { | |||
182 | const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'root_channel@localhost:' + servers[0].port }) | 192 | const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'root_channel@localhost:' + servers[0].port }) |
183 | const jsonObj = JSON.parse(json.text) | 193 | const jsonObj = JSON.parse(json.text) |
184 | expect(jsonObj.items.length).to.be.equal(1) | 194 | expect(jsonObj.items.length).to.be.equal(1) |
185 | expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1') | 195 | expect(jsonObj.items[0].title).to.equal('my super name for server 1') |
186 | } | 196 | } |
187 | 197 | ||
188 | { | 198 | { |
189 | const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'john_channel@localhost:' + servers[0].port }) | 199 | const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'john_channel@localhost:' + servers[0].port }) |
190 | const jsonObj = JSON.parse(json.text) | 200 | const jsonObj = JSON.parse(json.text) |
191 | expect(jsonObj.items.length).to.be.equal(1) | 201 | expect(jsonObj.items.length).to.be.equal(1) |
192 | expect(jsonObj.items[ 0 ].title).to.equal('user video') | 202 | expect(jsonObj.items[0].title).to.equal('user video') |
193 | } | 203 | } |
194 | } | 204 | } |
195 | }) | 205 | }) |
196 | }) | 206 | }) |
197 | 207 | ||
198 | describe('Video comments feed', function () { | 208 | describe('Video comments feed', function () { |
199 | it('Should contain valid comments (covers JSON feed 1.0 endpoint)', async function () { | 209 | |
210 | it('Should contain valid comments (covers JSON feed 1.0 endpoint) and not from unlisted videos', async function () { | ||
200 | for (const server of servers) { | 211 | for (const server of servers) { |
201 | const json = await getJSONfeed(server.url, 'video-comments') | 212 | const json = await getJSONfeed(server.url, 'video-comments') |
202 | 213 | ||
203 | const jsonObj = JSON.parse(json.text) | 214 | const jsonObj = JSON.parse(json.text) |
204 | expect(jsonObj.items.length).to.be.equal(2) | 215 | expect(jsonObj.items.length).to.be.equal(2) |
205 | expect(jsonObj.items[ 0 ].html_content).to.equal('super comment 2') | 216 | expect(jsonObj.items[0].html_content).to.equal('super comment 2') |
206 | expect(jsonObj.items[ 1 ].html_content).to.equal('super comment 1') | 217 | expect(jsonObj.items[1].html_content).to.equal('super comment 1') |
207 | } | 218 | } |
208 | }) | 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 | }) | ||
209 | }) | 231 | }) |
210 | 232 | ||
211 | after(async function () { | 233 | after(async function () { |