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