]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
0e1dc3e7 C |
2 | |
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
012580d9 | 5 | import { omit } from 'lodash' |
c6d20c84 | 6 | import { Account, HTMLServerConfig, HttpStatusCode, ServerConfig, VideoPlaylistCreateResult, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' |
0e1dc3e7 | 7 | import { |
7c3b7976 | 8 | cleanupTests, |
254d3579 | 9 | createMultipleServers, |
4c7e60bc | 10 | doubleFollow, |
012580d9 | 11 | makeGetRequest, |
590fb506 | 12 | makeHTMLRequest, |
254d3579 | 13 | PeerTubeServer, |
a59f210f | 14 | setAccessTokensToServers, |
39433fa5 | 15 | setDefaultVideoChannel, |
a59f210f | 16 | waitJobs |
bf54587a | 17 | } from '../../shared/server-commands' |
590fb506 C |
18 | |
19 | const expect = chai.expect | |
5bcfd029 | 20 | |
aea0b0e7 | 21 | function checkIndexTags (html: string, title: string, description: string, css: string, config: ServerConfig) { |
5bcfd029 C |
22 | expect(html).to.contain('<title>' + title + '</title>') |
23 | expect(html).to.contain('<meta name="description" content="' + description + '" />') | |
24 | expect(html).to.contain('<style class="custom-css-style">' + css + '</style>') | |
aea0b0e7 C |
25 | |
26 | const htmlConfig: HTMLServerConfig = omit(config, 'signup') | |
afe501a6 C |
27 | const configObjectString = JSON.stringify(htmlConfig) |
28 | const configEscapedString = JSON.stringify(configObjectString) | |
29 | ||
30 | expect(html).to.contain(`<script type="application/javascript">window.PeerTubeServerConfig = ${configEscapedString}</script>`) | |
5bcfd029 | 31 | } |
0e1dc3e7 C |
32 | |
33 | describe('Test a client controllers', function () { | |
254d3579 | 34 | let servers: PeerTubeServer[] = [] |
39433fa5 C |
35 | let account: Account |
36 | ||
37 | const videoName = 'my super name for server 1' | |
a073c912 RK |
38 | const videoDescription = 'my<br> super __description__ for *server* 1<p></p>' |
39 | const videoDescriptionPlainText = 'my super description for server 1' | |
39433fa5 C |
40 | |
41 | const playlistName = 'super playlist name' | |
42 | const playlistDescription = 'super playlist description' | |
d4a8e7a6 | 43 | let playlist: VideoPlaylistCreateResult |
39433fa5 C |
44 | |
45 | const channelDescription = 'my super channel description' | |
0e1dc3e7 | 46 | |
a1eda903 C |
47 | const watchVideoBasePaths = [ '/videos/watch/', '/w/' ] |
48 | const watchPlaylistBasePaths = [ '/videos/watch/playlist/', '/w/p/' ] | |
49 | ||
d4a8e7a6 | 50 | let videoIds: (string | number)[] = [] |
c6d20c84 C |
51 | let privateVideoId: string |
52 | let internalVideoId: string | |
53 | let unlistedVideoId: string | |
54 | ||
d4a8e7a6 C |
55 | let playlistIds: (string | number)[] = [] |
56 | ||
0e1dc3e7 C |
57 | before(async function () { |
58 | this.timeout(120000) | |
59 | ||
254d3579 | 60 | servers = await createMultipleServers(2) |
e5024f51 TC |
61 | |
62 | await setAccessTokensToServers(servers) | |
63 | ||
e5024f51 TC |
64 | await doubleFollow(servers[0], servers[1]) |
65 | ||
a59f210f | 66 | await setDefaultVideoChannel(servers) |
0e1dc3e7 | 67 | |
89d241a7 C |
68 | await servers[0].channels.update({ |
69 | channelName: servers[0].store.channel.name, | |
a5461888 C |
70 | attributes: { description: channelDescription } |
71 | }) | |
8d987ec6 | 72 | |
c6d20c84 | 73 | // Public video |
8d987ec6 | 74 | |
d23dd9fb C |
75 | { |
76 | const attributes = { name: videoName, description: videoDescription } | |
89d241a7 | 77 | await servers[0].videos.upload({ attributes }) |
0e1dc3e7 | 78 | |
89d241a7 | 79 | const { data } = await servers[0].videos.list() |
d23dd9fb | 80 | expect(data.length).to.equal(1) |
0e1dc3e7 | 81 | |
d23dd9fb | 82 | const video = data[0] |
89d241a7 | 83 | servers[0].store.video = video |
d23dd9fb C |
84 | videoIds = [ video.id, video.uuid, video.shortUUID ] |
85 | } | |
8d987ec6 | 86 | |
c6d20c84 C |
87 | { |
88 | ({ uuid: privateVideoId } = await servers[0].videos.quickUpload({ name: 'private', privacy: VideoPrivacy.PRIVATE })); | |
89 | ({ uuid: unlistedVideoId } = await servers[0].videos.quickUpload({ name: 'unlisted', privacy: VideoPrivacy.UNLISTED })); | |
90 | ({ uuid: internalVideoId } = await servers[0].videos.quickUpload({ name: 'internal', privacy: VideoPrivacy.INTERNAL })) | |
91 | } | |
92 | ||
8d987ec6 K |
93 | // Playlist |
94 | ||
d23dd9fb C |
95 | { |
96 | const attributes = { | |
97 | displayName: playlistName, | |
98 | description: playlistDescription, | |
99 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
89d241a7 | 100 | videoChannelId: servers[0].store.channel.id |
d23dd9fb | 101 | } |
8d987ec6 | 102 | |
89d241a7 | 103 | playlist = await servers[0].playlists.create({ attributes }) |
d23dd9fb | 104 | playlistIds = [ playlist.id, playlist.shortUUID, playlist.uuid ] |
8d987ec6 | 105 | |
89d241a7 | 106 | await servers[0].playlists.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: servers[0].store.video.id } }) |
d23dd9fb | 107 | } |
8d987ec6 K |
108 | |
109 | // Account | |
110 | ||
d23dd9fb | 111 | { |
89d241a7 | 112 | await servers[0].users.updateMe({ description: 'my account description' }) |
8d987ec6 | 113 | |
89d241a7 | 114 | account = await servers[0].accounts.get({ accountName: `${servers[0].store.user.username}@${servers[0].host}` }) |
d23dd9fb | 115 | } |
a59f210f C |
116 | |
117 | await waitJobs(servers) | |
0e1dc3e7 C |
118 | }) |
119 | ||
6fad8e51 | 120 | describe('oEmbed', function () { |
a1eda903 | 121 | |
6fad8e51 | 122 | it('Should have valid oEmbed discovery tags for videos', async function () { |
a1eda903 | 123 | for (const basePath of watchVideoBasePaths) { |
d4a8e7a6 C |
124 | for (const id of videoIds) { |
125 | const res = await makeGetRequest({ | |
126 | url: servers[0].url, | |
127 | path: basePath + id, | |
128 | accept: 'text/html', | |
c0e8b12e | 129 | expectedStatus: HttpStatusCode.OK_200 |
d4a8e7a6 | 130 | }) |
0e1dc3e7 | 131 | |
d4a8e7a6 | 132 | const port = servers[0].port |
0e1dc3e7 | 133 | |
d4a8e7a6 | 134 | const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' + |
a892c54a | 135 | `url=http%3A%2F%2Flocalhost%3A${port}%2Fw%2F${servers[0].store.video.shortUUID}" ` + |
89d241a7 | 136 | `title="${servers[0].store.video.name}" />` |
8d987ec6 | 137 | |
d4a8e7a6 C |
138 | expect(res.text).to.contain(expectedLink) |
139 | } | |
a1eda903 | 140 | } |
6fad8e51 | 141 | }) |
8d987ec6 | 142 | |
6fad8e51 | 143 | it('Should have valid oEmbed discovery tags for a playlist', async function () { |
a1eda903 | 144 | for (const basePath of watchPlaylistBasePaths) { |
d4a8e7a6 C |
145 | for (const id of playlistIds) { |
146 | const res = await makeGetRequest({ | |
147 | url: servers[0].url, | |
148 | path: basePath + id, | |
149 | accept: 'text/html', | |
c0e8b12e | 150 | expectedStatus: HttpStatusCode.OK_200 |
d4a8e7a6 | 151 | }) |
6fad8e51 | 152 | |
d4a8e7a6 | 153 | const port = servers[0].port |
8d987ec6 | 154 | |
d4a8e7a6 | 155 | const expectedLink = '<link rel="alternate" type="application/json+oembed" href="http://localhost:' + port + '/services/oembed?' + |
a892c54a | 156 | `url=http%3A%2F%2Flocalhost%3A${port}%2Fw%2Fp%2F${playlist.shortUUID}" ` + |
d4a8e7a6 | 157 | `title="${playlistName}" />` |
8d987ec6 | 158 | |
d4a8e7a6 C |
159 | expect(res.text).to.contain(expectedLink) |
160 | } | |
a1eda903 | 161 | } |
6fad8e51 | 162 | }) |
8d987ec6 K |
163 | }) |
164 | ||
6fad8e51 | 165 | describe('Open Graph', function () { |
8d987ec6 | 166 | |
012580d9 | 167 | async function accountPageTest (path: string) { |
c0e8b12e | 168 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
012580d9 | 169 | const text = res.text |
9a911038 | 170 | |
012580d9 C |
171 | expect(text).to.contain(`<meta property="og:title" content="${account.displayName}" />`) |
172 | expect(text).to.contain(`<meta property="og:description" content="${account.description}" />`) | |
173 | expect(text).to.contain('<meta property="og:type" content="website" />') | |
89d241a7 | 174 | expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/accounts/${servers[0].store.user.username}" />`) |
012580d9 | 175 | } |
9a911038 | 176 | |
012580d9 | 177 | async function channelPageTest (path: string) { |
c0e8b12e | 178 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
012580d9 | 179 | const text = res.text |
0e1dc3e7 | 180 | |
89d241a7 | 181 | expect(text).to.contain(`<meta property="og:title" content="${servers[0].store.channel.displayName}" />`) |
012580d9 C |
182 | expect(text).to.contain(`<meta property="og:description" content="${channelDescription}" />`) |
183 | expect(text).to.contain('<meta property="og:type" content="website" />') | |
89d241a7 | 184 | expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/video-channels/${servers[0].store.channel.name}" />`) |
012580d9 C |
185 | } |
186 | ||
a1eda903 | 187 | async function watchVideoPageTest (path: string) { |
c0e8b12e | 188 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
a1eda903 C |
189 | const text = res.text |
190 | ||
191 | expect(text).to.contain(`<meta property="og:title" content="${videoName}" />`) | |
192 | expect(text).to.contain(`<meta property="og:description" content="${videoDescriptionPlainText}" />`) | |
193 | expect(text).to.contain('<meta property="og:type" content="video" />') | |
a892c54a | 194 | expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/w/${servers[0].store.video.shortUUID}" />`) |
a1eda903 C |
195 | } |
196 | ||
197 | async function watchPlaylistPageTest (path: string) { | |
c0e8b12e | 198 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
a1eda903 C |
199 | const text = res.text |
200 | ||
201 | expect(text).to.contain(`<meta property="og:title" content="${playlistName}" />`) | |
202 | expect(text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`) | |
203 | expect(text).to.contain('<meta property="og:type" content="video" />') | |
a892c54a | 204 | expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/w/p/${playlist.shortUUID}" />`) |
a1eda903 C |
205 | } |
206 | ||
012580d9 | 207 | it('Should have valid Open Graph tags on the account page', async function () { |
89d241a7 C |
208 | await accountPageTest('/accounts/' + servers[0].store.user.username) |
209 | await accountPageTest('/a/' + servers[0].store.user.username) | |
210 | await accountPageTest('/@' + servers[0].store.user.username) | |
6fad8e51 | 211 | }) |
d8755eed | 212 | |
6fad8e51 | 213 | it('Should have valid Open Graph tags on the channel page', async function () { |
89d241a7 C |
214 | await channelPageTest('/video-channels/' + servers[0].store.channel.name) |
215 | await channelPageTest('/c/' + servers[0].store.channel.name) | |
216 | await channelPageTest('/@' + servers[0].store.channel.name) | |
6fad8e51 | 217 | }) |
d8755eed | 218 | |
a1eda903 | 219 | it('Should have valid Open Graph tags on the watch page', async function () { |
d4a8e7a6 C |
220 | for (const path of watchVideoBasePaths) { |
221 | for (const id of videoIds) { | |
222 | await watchVideoPageTest(path + id) | |
223 | } | |
224 | } | |
6fad8e51 | 225 | }) |
8d987ec6 | 226 | |
6fad8e51 | 227 | it('Should have valid Open Graph tags on the watch playlist page', async function () { |
d4a8e7a6 C |
228 | for (const path of watchPlaylistBasePaths) { |
229 | for (const id of playlistIds) { | |
230 | await watchPlaylistPageTest(path + id) | |
231 | } | |
232 | } | |
6fad8e51 | 233 | }) |
8d987ec6 K |
234 | }) |
235 | ||
6fad8e51 | 236 | describe('Twitter card', async function () { |
8d987ec6 | 237 | |
012580d9 | 238 | describe('Not whitelisted', function () { |
8d987ec6 | 239 | |
012580d9 | 240 | async function accountPageTest (path: string) { |
c0e8b12e | 241 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
012580d9 | 242 | const text = res.text |
8d987ec6 | 243 | |
012580d9 C |
244 | expect(text).to.contain('<meta property="twitter:card" content="summary" />') |
245 | expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | |
246 | expect(text).to.contain(`<meta property="twitter:title" content="${account.name}" />`) | |
247 | expect(text).to.contain(`<meta property="twitter:description" content="${account.description}" />`) | |
248 | } | |
8be1afa1 | 249 | |
012580d9 | 250 | async function channelPageTest (path: string) { |
c0e8b12e | 251 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
012580d9 | 252 | const text = res.text |
8be1afa1 | 253 | |
012580d9 C |
254 | expect(text).to.contain('<meta property="twitter:card" content="summary" />') |
255 | expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | |
89d241a7 | 256 | expect(text).to.contain(`<meta property="twitter:title" content="${servers[0].store.channel.displayName}" />`) |
012580d9 | 257 | expect(text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`) |
9a911038 K |
258 | } |
259 | ||
a1eda903 | 260 | async function watchVideoPageTest (path: string) { |
c0e8b12e | 261 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
a1eda903 | 262 | const text = res.text |
8be1afa1 | 263 | |
a1eda903 C |
264 | expect(text).to.contain('<meta property="twitter:card" content="summary_large_image" />') |
265 | expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | |
266 | expect(text).to.contain(`<meta property="twitter:title" content="${videoName}" />`) | |
267 | expect(text).to.contain(`<meta property="twitter:description" content="${videoDescriptionPlainText}" />`) | |
268 | } | |
269 | ||
270 | async function watchPlaylistPageTest (path: string) { | |
c0e8b12e | 271 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
a1eda903 C |
272 | const text = res.text |
273 | ||
274 | expect(text).to.contain('<meta property="twitter:card" content="summary" />') | |
275 | expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | |
276 | expect(text).to.contain(`<meta property="twitter:title" content="${playlistName}" />`) | |
277 | expect(text).to.contain(`<meta property="twitter:description" content="${playlistDescription}" />`) | |
278 | } | |
279 | ||
280 | it('Should have valid twitter card on the watch video page', async function () { | |
d4a8e7a6 C |
281 | for (const path of watchVideoBasePaths) { |
282 | for (const id of videoIds) { | |
283 | await watchVideoPageTest(path + id) | |
284 | } | |
285 | } | |
012580d9 | 286 | }) |
9a911038 | 287 | |
012580d9 | 288 | it('Should have valid twitter card on the watch playlist page', async function () { |
d4a8e7a6 C |
289 | for (const path of watchPlaylistBasePaths) { |
290 | for (const id of playlistIds) { | |
291 | await watchPlaylistPageTest(path + id) | |
292 | } | |
293 | } | |
012580d9 C |
294 | }) |
295 | ||
296 | it('Should have valid twitter card on the account page', async function () { | |
297 | await accountPageTest('/accounts/' + account.name) | |
298 | await accountPageTest('/a/' + account.name) | |
299 | await accountPageTest('/@' + account.name) | |
300 | }) | |
301 | ||
302 | it('Should have valid twitter card on the channel page', async function () { | |
89d241a7 C |
303 | await channelPageTest('/video-channels/' + servers[0].store.channel.name) |
304 | await channelPageTest('/c/' + servers[0].store.channel.name) | |
305 | await channelPageTest('/@' + servers[0].store.channel.name) | |
012580d9 | 306 | }) |
6fad8e51 | 307 | }) |
8d987ec6 | 308 | |
012580d9 | 309 | describe('Whitelisted', function () { |
8d987ec6 | 310 | |
012580d9 | 311 | before(async function () { |
89d241a7 | 312 | const config = await servers[0].config.getCustomConfig() |
012580d9 C |
313 | config.services.twitter = { |
314 | username: '@Kuja', | |
315 | whitelisted: true | |
316 | } | |
8d987ec6 | 317 | |
89d241a7 | 318 | await servers[0].config.updateCustomConfig({ newCustomConfig: config }) |
012580d9 | 319 | }) |
8d987ec6 | 320 | |
012580d9 | 321 | async function accountPageTest (path: string) { |
c0e8b12e | 322 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
012580d9 | 323 | const text = res.text |
8be1afa1 | 324 | |
012580d9 C |
325 | expect(text).to.contain('<meta property="twitter:card" content="summary" />') |
326 | expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />') | |
9a911038 K |
327 | } |
328 | ||
012580d9 | 329 | async function channelPageTest (path: string) { |
c0e8b12e | 330 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
012580d9 | 331 | const text = res.text |
9a911038 | 332 | |
012580d9 C |
333 | expect(text).to.contain('<meta property="twitter:card" content="summary" />') |
334 | expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />') | |
335 | } | |
9a911038 | 336 | |
a1eda903 | 337 | async function watchVideoPageTest (path: string) { |
c0e8b12e | 338 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
a1eda903 | 339 | const text = res.text |
6fad8e51 | 340 | |
a1eda903 C |
341 | expect(text).to.contain('<meta property="twitter:card" content="player" />') |
342 | expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />') | |
343 | } | |
344 | ||
345 | async function watchPlaylistPageTest (path: string) { | |
c0e8b12e | 346 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
a1eda903 C |
347 | const text = res.text |
348 | ||
349 | expect(text).to.contain('<meta property="twitter:card" content="player" />') | |
350 | expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />') | |
351 | } | |
352 | ||
353 | it('Should have valid twitter card on the watch video page', async function () { | |
d4a8e7a6 C |
354 | for (const path of watchVideoBasePaths) { |
355 | for (const id of videoIds) { | |
356 | await watchVideoPageTest(path + id) | |
357 | } | |
358 | } | |
012580d9 | 359 | }) |
9a911038 | 360 | |
012580d9 | 361 | it('Should have valid twitter card on the watch playlist page', async function () { |
d4a8e7a6 C |
362 | for (const path of watchPlaylistBasePaths) { |
363 | for (const id of playlistIds) { | |
364 | await watchPlaylistPageTest(path + id) | |
365 | } | |
366 | } | |
012580d9 C |
367 | }) |
368 | ||
369 | it('Should have valid twitter card on the account page', async function () { | |
370 | await accountPageTest('/accounts/' + account.name) | |
371 | await accountPageTest('/a/' + account.name) | |
372 | await accountPageTest('/@' + account.name) | |
373 | }) | |
374 | ||
375 | it('Should have valid twitter card on the channel page', async function () { | |
89d241a7 C |
376 | await channelPageTest('/video-channels/' + servers[0].store.channel.name) |
377 | await channelPageTest('/c/' + servers[0].store.channel.name) | |
378 | await channelPageTest('/@' + servers[0].store.channel.name) | |
012580d9 | 379 | }) |
6fad8e51 | 380 | }) |
5bcfd029 C |
381 | }) |
382 | ||
6fad8e51 C |
383 | describe('Index HTML', function () { |
384 | ||
385 | it('Should have valid index html tags (title, description...)', async function () { | |
89d241a7 | 386 | const config = await servers[0].config.getConfig() |
a59f210f | 387 | const res = await makeHTMLRequest(servers[0].url, '/videos/trending') |
6fad8e51 C |
388 | |
389 | const description = 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' | |
65e6e260 | 390 | checkIndexTags(res.text, 'PeerTube', description, '', config) |
590fb506 | 391 | }) |
5bcfd029 | 392 | |
6fad8e51 | 393 | it('Should update the customized configuration and have the correct index html tags', async function () { |
89d241a7 | 394 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
395 | newConfig: { |
396 | instance: { | |
397 | name: 'PeerTube updated', | |
398 | shortDescription: 'my short description', | |
399 | description: 'my super description', | |
400 | terms: 'my super terms', | |
401 | defaultNSFWPolicy: 'blur', | |
402 | defaultClientRoute: '/videos/recently-added', | |
403 | customizations: { | |
404 | javascript: 'alert("coucou")', | |
405 | css: 'body { background-color: red; }' | |
406 | } | |
6fad8e51 C |
407 | } |
408 | } | |
409 | }) | |
5bcfd029 | 410 | |
89d241a7 | 411 | const config = await servers[0].config.getConfig() |
a59f210f | 412 | const res = await makeHTMLRequest(servers[0].url, '/videos/trending') |
6fad8e51 | 413 | |
65e6e260 | 414 | checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', config) |
6fad8e51 | 415 | }) |
5bcfd029 | 416 | |
6fad8e51 | 417 | it('Should have valid index html updated tags (title, description...)', async function () { |
89d241a7 | 418 | const config = await servers[0].config.getConfig() |
a59f210f | 419 | const res = await makeHTMLRequest(servers[0].url, '/videos/trending') |
5bcfd029 | 420 | |
65e6e260 | 421 | checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', config) |
6fad8e51 | 422 | }) |
e5024f51 TC |
423 | |
424 | it('Should use the original video URL for the canonical tag', async function () { | |
a1eda903 | 425 | for (const basePath of watchVideoBasePaths) { |
d4a8e7a6 C |
426 | for (const id of videoIds) { |
427 | const res = await makeHTMLRequest(servers[1].url, basePath + id) | |
89d241a7 | 428 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/videos/watch/${servers[0].store.video.uuid}" />`) |
d4a8e7a6 | 429 | } |
a1eda903 | 430 | } |
a59f210f C |
431 | }) |
432 | ||
433 | it('Should use the original account URL for the canonical tag', async function () { | |
65e6e260 | 434 | const accountURLtest = res => { |
9a911038 K |
435 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/accounts/root" />`) |
436 | } | |
437 | ||
438 | accountURLtest(await makeHTMLRequest(servers[1].url, '/accounts/root@' + servers[0].host)) | |
439 | accountURLtest(await makeHTMLRequest(servers[1].url, '/a/root@' + servers[0].host)) | |
440 | accountURLtest(await makeHTMLRequest(servers[1].url, '/@root@' + servers[0].host)) | |
a59f210f C |
441 | }) |
442 | ||
443 | it('Should use the original channel URL for the canonical tag', async function () { | |
65e6e260 | 444 | const channelURLtests = res => { |
9a911038 K |
445 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-channels/root_channel" />`) |
446 | } | |
447 | ||
448 | channelURLtests(await makeHTMLRequest(servers[1].url, '/video-channels/root_channel@' + servers[0].host)) | |
449 | channelURLtests(await makeHTMLRequest(servers[1].url, '/c/root_channel@' + servers[0].host)) | |
450 | channelURLtests(await makeHTMLRequest(servers[1].url, '/@root_channel@' + servers[0].host)) | |
a59f210f C |
451 | }) |
452 | ||
453 | it('Should use the original playlist URL for the canonical tag', async function () { | |
a1eda903 | 454 | for (const basePath of watchPlaylistBasePaths) { |
d4a8e7a6 C |
455 | for (const id of playlistIds) { |
456 | const res = await makeHTMLRequest(servers[1].url, basePath + id) | |
457 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-playlists/${playlist.uuid}" />`) | |
458 | } | |
a1eda903 | 459 | } |
e5024f51 | 460 | }) |
352819ef C |
461 | |
462 | it('Should add noindex meta tag for remote accounts', async function () { | |
463 | const handle = 'root@' + servers[0].host | |
464 | const paths = [ '/accounts/', '/a/', '/@' ] | |
465 | ||
466 | for (const path of paths) { | |
467 | { | |
468 | const { text } = await makeHTMLRequest(servers[1].url, path + handle) | |
469 | expect(text).to.contain('<meta name="robots" content="noindex" />') | |
470 | } | |
471 | ||
472 | { | |
473 | const { text } = await makeHTMLRequest(servers[0].url, path + handle) | |
474 | expect(text).to.not.contain('<meta name="robots" content="noindex" />') | |
475 | } | |
476 | } | |
477 | }) | |
478 | ||
c6d20c84 C |
479 | it('Should add noindex meta tag for remote channels', async function () { |
480 | const handle = 'root_channel@' + servers[0].host | |
481 | const paths = [ '/video-channels/', '/c/', '/@' ] | |
482 | ||
483 | for (const path of paths) { | |
484 | { | |
485 | const { text } = await makeHTMLRequest(servers[1].url, path + handle) | |
486 | expect(text).to.contain('<meta name="robots" content="noindex" />') | |
487 | } | |
488 | ||
489 | { | |
490 | const { text } = await makeHTMLRequest(servers[0].url, path + handle) | |
491 | expect(text).to.not.contain('<meta name="robots" content="noindex" />') | |
492 | } | |
493 | } | |
494 | }) | |
495 | ||
496 | it('Should not display internal/private video', async function () { | |
497 | for (const basePath of watchVideoBasePaths) { | |
498 | for (const id of [ privateVideoId, internalVideoId ]) { | |
499 | const res = await makeGetRequest({ | |
500 | url: servers[0].url, | |
501 | path: basePath + id, | |
502 | accept: 'text/html', | |
503 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | |
504 | }) | |
505 | ||
506 | expect(res.text).to.not.contain('internal') | |
507 | expect(res.text).to.not.contain('private') | |
508 | } | |
509 | } | |
510 | }) | |
511 | ||
512 | it('Should add noindex meta tag for unlisted video', async function () { | |
513 | for (const basePath of watchVideoBasePaths) { | |
514 | const res = await makeGetRequest({ | |
515 | url: servers[0].url, | |
516 | path: basePath + unlistedVideoId, | |
517 | accept: 'text/html', | |
518 | expectedStatus: HttpStatusCode.OK_200 | |
519 | }) | |
520 | ||
521 | expect(res.text).to.contain('unlisted') | |
522 | expect(res.text).to.contain('<meta name="robots" content="noindex" />') | |
523 | } | |
524 | }) | |
525 | ||
352819ef C |
526 | it('Should add noindex meta tag for remote accounts', async function () { |
527 | const handle = 'root_channel@' + servers[0].host | |
528 | const paths = [ '/video-channels/', '/c/', '/@' ] | |
529 | ||
530 | for (const path of paths) { | |
531 | { | |
532 | const { text } = await makeHTMLRequest(servers[1].url, path + handle) | |
533 | expect(text).to.contain('<meta name="robots" content="noindex" />') | |
534 | } | |
535 | ||
536 | { | |
537 | const { text } = await makeHTMLRequest(servers[0].url, path + handle) | |
538 | expect(text).to.not.contain('<meta name="robots" content="noindex" />') | |
539 | } | |
540 | } | |
541 | }) | |
5bcfd029 C |
542 | }) |
543 | ||
aea0b0e7 C |
544 | describe('Embed HTML', function () { |
545 | ||
546 | it('Should have the correct embed html tags', async function () { | |
89d241a7 C |
547 | const config = await servers[0].config.getConfig() |
548 | const res = await makeHTMLRequest(servers[0].url, servers[0].store.video.embedPath) | |
aea0b0e7 | 549 | |
65e6e260 | 550 | checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', config) |
aea0b0e7 C |
551 | }) |
552 | }) | |
553 | ||
7c3b7976 | 554 | after(async function () { |
a59f210f | 555 | await cleanupTests(servers) |
0e1dc3e7 C |
556 | }) |
557 | }) |