]>
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 | |
2732eeff C |
137 | const expectedLink = `<link rel="alternate" type="application/json+oembed" href="${servers[0].url}/services/oembed?` + |
138 | `url=http%3A%2F%2F${servers[0].hostname}%3A${servers[0].port}%2Fw%2F${servers[0].store.video.shortUUID}" ` + | |
139 | `title="${servers[0].store.video.name}" />` | |
8d987ec6 | 140 | |
d4a8e7a6 C |
141 | expect(res.text).to.contain(expectedLink) |
142 | } | |
a1eda903 | 143 | } |
6fad8e51 | 144 | }) |
8d987ec6 | 145 | |
6fad8e51 | 146 | it('Should have valid oEmbed discovery tags for a playlist', async function () { |
a1eda903 | 147 | for (const basePath of watchPlaylistBasePaths) { |
d4a8e7a6 C |
148 | for (const id of playlistIds) { |
149 | const res = await makeGetRequest({ | |
150 | url: servers[0].url, | |
151 | path: basePath + id, | |
152 | accept: 'text/html', | |
c0e8b12e | 153 | expectedStatus: HttpStatusCode.OK_200 |
d4a8e7a6 | 154 | }) |
6fad8e51 | 155 | |
2732eeff C |
156 | const expectedLink = `<link rel="alternate" type="application/json+oembed" href="${servers[0].url}/services/oembed?` + |
157 | `url=http%3A%2F%2F${servers[0].hostname}%3A${servers[0].port}%2Fw%2Fp%2F${playlist.shortUUID}" ` + | |
d4a8e7a6 | 158 | `title="${playlistName}" />` |
8d987ec6 | 159 | |
d4a8e7a6 C |
160 | expect(res.text).to.contain(expectedLink) |
161 | } | |
a1eda903 | 162 | } |
6fad8e51 | 163 | }) |
8d987ec6 K |
164 | }) |
165 | ||
6fad8e51 | 166 | describe('Open Graph', function () { |
8d987ec6 | 167 | |
012580d9 | 168 | async function accountPageTest (path: string) { |
c0e8b12e | 169 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
012580d9 | 170 | const text = res.text |
9a911038 | 171 | |
012580d9 C |
172 | expect(text).to.contain(`<meta property="og:title" content="${account.displayName}" />`) |
173 | expect(text).to.contain(`<meta property="og:description" content="${account.description}" />`) | |
174 | expect(text).to.contain('<meta property="og:type" content="website" />') | |
89d241a7 | 175 | expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/accounts/${servers[0].store.user.username}" />`) |
012580d9 | 176 | } |
9a911038 | 177 | |
012580d9 | 178 | async function channelPageTest (path: string) { |
c0e8b12e | 179 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
012580d9 | 180 | const text = res.text |
0e1dc3e7 | 181 | |
89d241a7 | 182 | expect(text).to.contain(`<meta property="og:title" content="${servers[0].store.channel.displayName}" />`) |
012580d9 C |
183 | expect(text).to.contain(`<meta property="og:description" content="${channelDescription}" />`) |
184 | expect(text).to.contain('<meta property="og:type" content="website" />') | |
89d241a7 | 185 | expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/video-channels/${servers[0].store.channel.name}" />`) |
012580d9 C |
186 | } |
187 | ||
a1eda903 | 188 | async function watchVideoPageTest (path: string) { |
c0e8b12e | 189 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
a1eda903 C |
190 | const text = res.text |
191 | ||
192 | expect(text).to.contain(`<meta property="og:title" content="${videoName}" />`) | |
193 | expect(text).to.contain(`<meta property="og:description" content="${videoDescriptionPlainText}" />`) | |
194 | expect(text).to.contain('<meta property="og:type" content="video" />') | |
a892c54a | 195 | expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/w/${servers[0].store.video.shortUUID}" />`) |
a1eda903 C |
196 | } |
197 | ||
198 | async function watchPlaylistPageTest (path: string) { | |
c0e8b12e | 199 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
a1eda903 C |
200 | const text = res.text |
201 | ||
202 | expect(text).to.contain(`<meta property="og:title" content="${playlistName}" />`) | |
203 | expect(text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`) | |
204 | expect(text).to.contain('<meta property="og:type" content="video" />') | |
a892c54a | 205 | expect(text).to.contain(`<meta property="og:url" content="${servers[0].url}/w/p/${playlist.shortUUID}" />`) |
a1eda903 C |
206 | } |
207 | ||
012580d9 | 208 | it('Should have valid Open Graph tags on the account page', async function () { |
89d241a7 C |
209 | await accountPageTest('/accounts/' + servers[0].store.user.username) |
210 | await accountPageTest('/a/' + servers[0].store.user.username) | |
211 | await accountPageTest('/@' + servers[0].store.user.username) | |
6fad8e51 | 212 | }) |
d8755eed | 213 | |
6fad8e51 | 214 | it('Should have valid Open Graph tags on the channel page', async function () { |
89d241a7 C |
215 | await channelPageTest('/video-channels/' + servers[0].store.channel.name) |
216 | await channelPageTest('/c/' + servers[0].store.channel.name) | |
217 | await channelPageTest('/@' + servers[0].store.channel.name) | |
6fad8e51 | 218 | }) |
d8755eed | 219 | |
a1eda903 | 220 | it('Should have valid Open Graph tags on the watch page', async function () { |
d4a8e7a6 C |
221 | for (const path of watchVideoBasePaths) { |
222 | for (const id of videoIds) { | |
223 | await watchVideoPageTest(path + id) | |
224 | } | |
225 | } | |
6fad8e51 | 226 | }) |
8d987ec6 | 227 | |
6fad8e51 | 228 | it('Should have valid Open Graph tags on the watch playlist page', async function () { |
d4a8e7a6 C |
229 | for (const path of watchPlaylistBasePaths) { |
230 | for (const id of playlistIds) { | |
231 | await watchPlaylistPageTest(path + id) | |
232 | } | |
233 | } | |
6fad8e51 | 234 | }) |
8d987ec6 K |
235 | }) |
236 | ||
6fad8e51 | 237 | describe('Twitter card', async function () { |
8d987ec6 | 238 | |
012580d9 | 239 | describe('Not whitelisted', function () { |
8d987ec6 | 240 | |
012580d9 | 241 | async function accountPageTest (path: string) { |
c0e8b12e | 242 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
012580d9 | 243 | const text = res.text |
8d987ec6 | 244 | |
012580d9 C |
245 | expect(text).to.contain('<meta property="twitter:card" content="summary" />') |
246 | expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | |
247 | expect(text).to.contain(`<meta property="twitter:title" content="${account.name}" />`) | |
248 | expect(text).to.contain(`<meta property="twitter:description" content="${account.description}" />`) | |
249 | } | |
8be1afa1 | 250 | |
012580d9 | 251 | async function channelPageTest (path: string) { |
c0e8b12e | 252 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
012580d9 | 253 | const text = res.text |
8be1afa1 | 254 | |
012580d9 C |
255 | expect(text).to.contain('<meta property="twitter:card" content="summary" />') |
256 | expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | |
89d241a7 | 257 | expect(text).to.contain(`<meta property="twitter:title" content="${servers[0].store.channel.displayName}" />`) |
012580d9 | 258 | expect(text).to.contain(`<meta property="twitter:description" content="${channelDescription}" />`) |
9a911038 K |
259 | } |
260 | ||
a1eda903 | 261 | async function watchVideoPageTest (path: string) { |
c0e8b12e | 262 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
a1eda903 | 263 | const text = res.text |
8be1afa1 | 264 | |
a1eda903 C |
265 | expect(text).to.contain('<meta property="twitter:card" content="summary_large_image" />') |
266 | expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | |
267 | expect(text).to.contain(`<meta property="twitter:title" content="${videoName}" />`) | |
268 | expect(text).to.contain(`<meta property="twitter:description" content="${videoDescriptionPlainText}" />`) | |
269 | } | |
270 | ||
271 | async function watchPlaylistPageTest (path: string) { | |
c0e8b12e | 272 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
a1eda903 C |
273 | const text = res.text |
274 | ||
275 | expect(text).to.contain('<meta property="twitter:card" content="summary" />') | |
276 | expect(text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') | |
277 | expect(text).to.contain(`<meta property="twitter:title" content="${playlistName}" />`) | |
278 | expect(text).to.contain(`<meta property="twitter:description" content="${playlistDescription}" />`) | |
279 | } | |
280 | ||
281 | it('Should have valid twitter card on the watch video page', async function () { | |
d4a8e7a6 C |
282 | for (const path of watchVideoBasePaths) { |
283 | for (const id of videoIds) { | |
284 | await watchVideoPageTest(path + id) | |
285 | } | |
286 | } | |
012580d9 | 287 | }) |
9a911038 | 288 | |
012580d9 | 289 | it('Should have valid twitter card on the watch playlist page', async function () { |
d4a8e7a6 C |
290 | for (const path of watchPlaylistBasePaths) { |
291 | for (const id of playlistIds) { | |
292 | await watchPlaylistPageTest(path + id) | |
293 | } | |
294 | } | |
012580d9 C |
295 | }) |
296 | ||
297 | it('Should have valid twitter card on the account page', async function () { | |
298 | await accountPageTest('/accounts/' + account.name) | |
299 | await accountPageTest('/a/' + account.name) | |
300 | await accountPageTest('/@' + account.name) | |
301 | }) | |
302 | ||
303 | it('Should have valid twitter card on the channel page', async function () { | |
89d241a7 C |
304 | await channelPageTest('/video-channels/' + servers[0].store.channel.name) |
305 | await channelPageTest('/c/' + servers[0].store.channel.name) | |
306 | await channelPageTest('/@' + servers[0].store.channel.name) | |
012580d9 | 307 | }) |
6fad8e51 | 308 | }) |
8d987ec6 | 309 | |
012580d9 | 310 | describe('Whitelisted', function () { |
8d987ec6 | 311 | |
012580d9 | 312 | before(async function () { |
89d241a7 | 313 | const config = await servers[0].config.getCustomConfig() |
012580d9 C |
314 | config.services.twitter = { |
315 | username: '@Kuja', | |
316 | whitelisted: true | |
317 | } | |
8d987ec6 | 318 | |
89d241a7 | 319 | await servers[0].config.updateCustomConfig({ newCustomConfig: config }) |
012580d9 | 320 | }) |
8d987ec6 | 321 | |
012580d9 | 322 | async function accountPageTest (path: string) { |
c0e8b12e | 323 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
012580d9 | 324 | const text = res.text |
8be1afa1 | 325 | |
012580d9 C |
326 | expect(text).to.contain('<meta property="twitter:card" content="summary" />') |
327 | expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />') | |
9a911038 K |
328 | } |
329 | ||
012580d9 | 330 | async function channelPageTest (path: string) { |
c0e8b12e | 331 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
012580d9 | 332 | const text = res.text |
9a911038 | 333 | |
012580d9 C |
334 | expect(text).to.contain('<meta property="twitter:card" content="summary" />') |
335 | expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />') | |
336 | } | |
9a911038 | 337 | |
a1eda903 | 338 | async function watchVideoPageTest (path: string) { |
c0e8b12e | 339 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
a1eda903 | 340 | const text = res.text |
6fad8e51 | 341 | |
a1eda903 C |
342 | expect(text).to.contain('<meta property="twitter:card" content="player" />') |
343 | expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />') | |
344 | } | |
345 | ||
346 | async function watchPlaylistPageTest (path: string) { | |
c0e8b12e | 347 | const res = await makeGetRequest({ url: servers[0].url, path, accept: 'text/html', expectedStatus: HttpStatusCode.OK_200 }) |
a1eda903 C |
348 | const text = res.text |
349 | ||
350 | expect(text).to.contain('<meta property="twitter:card" content="player" />') | |
351 | expect(text).to.contain('<meta property="twitter:site" content="@Kuja" />') | |
352 | } | |
353 | ||
354 | it('Should have valid twitter card on the watch video page', async function () { | |
d4a8e7a6 C |
355 | for (const path of watchVideoBasePaths) { |
356 | for (const id of videoIds) { | |
357 | await watchVideoPageTest(path + id) | |
358 | } | |
359 | } | |
012580d9 | 360 | }) |
9a911038 | 361 | |
012580d9 | 362 | it('Should have valid twitter card on the watch playlist page', async function () { |
d4a8e7a6 C |
363 | for (const path of watchPlaylistBasePaths) { |
364 | for (const id of playlistIds) { | |
365 | await watchPlaylistPageTest(path + id) | |
366 | } | |
367 | } | |
012580d9 C |
368 | }) |
369 | ||
370 | it('Should have valid twitter card on the account page', async function () { | |
371 | await accountPageTest('/accounts/' + account.name) | |
372 | await accountPageTest('/a/' + account.name) | |
373 | await accountPageTest('/@' + account.name) | |
374 | }) | |
375 | ||
376 | it('Should have valid twitter card on the channel page', async function () { | |
89d241a7 C |
377 | await channelPageTest('/video-channels/' + servers[0].store.channel.name) |
378 | await channelPageTest('/c/' + servers[0].store.channel.name) | |
379 | await channelPageTest('/@' + servers[0].store.channel.name) | |
012580d9 | 380 | }) |
6fad8e51 | 381 | }) |
5bcfd029 C |
382 | }) |
383 | ||
6fad8e51 C |
384 | describe('Index HTML', function () { |
385 | ||
386 | it('Should have valid index html tags (title, description...)', async function () { | |
89d241a7 | 387 | const config = await servers[0].config.getConfig() |
a59f210f | 388 | const res = await makeHTMLRequest(servers[0].url, '/videos/trending') |
6fad8e51 C |
389 | |
390 | const description = 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' | |
65e6e260 | 391 | checkIndexTags(res.text, 'PeerTube', description, '', config) |
590fb506 | 392 | }) |
5bcfd029 | 393 | |
6fad8e51 | 394 | it('Should update the customized configuration and have the correct index html tags', async function () { |
89d241a7 | 395 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
396 | newConfig: { |
397 | instance: { | |
398 | name: 'PeerTube updated', | |
399 | shortDescription: 'my short description', | |
400 | description: 'my super description', | |
401 | terms: 'my super terms', | |
402 | defaultNSFWPolicy: 'blur', | |
403 | defaultClientRoute: '/videos/recently-added', | |
404 | customizations: { | |
405 | javascript: 'alert("coucou")', | |
406 | css: 'body { background-color: red; }' | |
407 | } | |
6fad8e51 C |
408 | } |
409 | } | |
410 | }) | |
5bcfd029 | 411 | |
89d241a7 | 412 | const config = await servers[0].config.getConfig() |
a59f210f | 413 | const res = await makeHTMLRequest(servers[0].url, '/videos/trending') |
6fad8e51 | 414 | |
65e6e260 | 415 | checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', config) |
6fad8e51 | 416 | }) |
5bcfd029 | 417 | |
6fad8e51 | 418 | it('Should have valid index html updated tags (title, description...)', async function () { |
89d241a7 | 419 | const config = await servers[0].config.getConfig() |
a59f210f | 420 | const res = await makeHTMLRequest(servers[0].url, '/videos/trending') |
5bcfd029 | 421 | |
65e6e260 | 422 | checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', config) |
6fad8e51 | 423 | }) |
e5024f51 TC |
424 | |
425 | it('Should use the original video URL for the canonical tag', async function () { | |
a1eda903 | 426 | for (const basePath of watchVideoBasePaths) { |
d4a8e7a6 C |
427 | for (const id of videoIds) { |
428 | const res = await makeHTMLRequest(servers[1].url, basePath + id) | |
89d241a7 | 429 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/videos/watch/${servers[0].store.video.uuid}" />`) |
d4a8e7a6 | 430 | } |
a1eda903 | 431 | } |
a59f210f C |
432 | }) |
433 | ||
434 | it('Should use the original account URL for the canonical tag', async function () { | |
65e6e260 | 435 | const accountURLtest = res => { |
9a911038 K |
436 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/accounts/root" />`) |
437 | } | |
438 | ||
439 | accountURLtest(await makeHTMLRequest(servers[1].url, '/accounts/root@' + servers[0].host)) | |
440 | accountURLtest(await makeHTMLRequest(servers[1].url, '/a/root@' + servers[0].host)) | |
441 | accountURLtest(await makeHTMLRequest(servers[1].url, '/@root@' + servers[0].host)) | |
a59f210f C |
442 | }) |
443 | ||
444 | it('Should use the original channel URL for the canonical tag', async function () { | |
65e6e260 | 445 | const channelURLtests = res => { |
9a911038 K |
446 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-channels/root_channel" />`) |
447 | } | |
448 | ||
449 | channelURLtests(await makeHTMLRequest(servers[1].url, '/video-channels/root_channel@' + servers[0].host)) | |
450 | channelURLtests(await makeHTMLRequest(servers[1].url, '/c/root_channel@' + servers[0].host)) | |
451 | channelURLtests(await makeHTMLRequest(servers[1].url, '/@root_channel@' + servers[0].host)) | |
a59f210f C |
452 | }) |
453 | ||
454 | it('Should use the original playlist URL for the canonical tag', async function () { | |
a1eda903 | 455 | for (const basePath of watchPlaylistBasePaths) { |
d4a8e7a6 C |
456 | for (const id of playlistIds) { |
457 | const res = await makeHTMLRequest(servers[1].url, basePath + id) | |
458 | expect(res.text).to.contain(`<link rel="canonical" href="${servers[0].url}/video-playlists/${playlist.uuid}" />`) | |
459 | } | |
a1eda903 | 460 | } |
e5024f51 | 461 | }) |
352819ef C |
462 | |
463 | it('Should add noindex meta tag for remote accounts', async function () { | |
464 | const handle = 'root@' + servers[0].host | |
465 | const paths = [ '/accounts/', '/a/', '/@' ] | |
466 | ||
467 | for (const path of paths) { | |
468 | { | |
469 | const { text } = await makeHTMLRequest(servers[1].url, path + handle) | |
470 | expect(text).to.contain('<meta name="robots" content="noindex" />') | |
471 | } | |
472 | ||
473 | { | |
474 | const { text } = await makeHTMLRequest(servers[0].url, path + handle) | |
475 | expect(text).to.not.contain('<meta name="robots" content="noindex" />') | |
476 | } | |
477 | } | |
478 | }) | |
479 | ||
c6d20c84 C |
480 | it('Should add noindex meta tag for remote channels', async function () { |
481 | const handle = 'root_channel@' + servers[0].host | |
482 | const paths = [ '/video-channels/', '/c/', '/@' ] | |
483 | ||
484 | for (const path of paths) { | |
485 | { | |
486 | const { text } = await makeHTMLRequest(servers[1].url, path + handle) | |
487 | expect(text).to.contain('<meta name="robots" content="noindex" />') | |
488 | } | |
489 | ||
490 | { | |
491 | const { text } = await makeHTMLRequest(servers[0].url, path + handle) | |
492 | expect(text).to.not.contain('<meta name="robots" content="noindex" />') | |
493 | } | |
494 | } | |
495 | }) | |
496 | ||
497 | it('Should not display internal/private video', async function () { | |
498 | for (const basePath of watchVideoBasePaths) { | |
499 | for (const id of [ privateVideoId, internalVideoId ]) { | |
500 | const res = await makeGetRequest({ | |
501 | url: servers[0].url, | |
502 | path: basePath + id, | |
503 | accept: 'text/html', | |
504 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | |
505 | }) | |
506 | ||
507 | expect(res.text).to.not.contain('internal') | |
508 | expect(res.text).to.not.contain('private') | |
509 | } | |
510 | } | |
511 | }) | |
512 | ||
513 | it('Should add noindex meta tag for unlisted video', async function () { | |
514 | for (const basePath of watchVideoBasePaths) { | |
515 | const res = await makeGetRequest({ | |
516 | url: servers[0].url, | |
517 | path: basePath + unlistedVideoId, | |
518 | accept: 'text/html', | |
519 | expectedStatus: HttpStatusCode.OK_200 | |
520 | }) | |
521 | ||
522 | expect(res.text).to.contain('unlisted') | |
523 | expect(res.text).to.contain('<meta name="robots" content="noindex" />') | |
524 | } | |
525 | }) | |
5bcfd029 C |
526 | }) |
527 | ||
aea0b0e7 C |
528 | describe('Embed HTML', function () { |
529 | ||
530 | it('Should have the correct embed html tags', async function () { | |
89d241a7 C |
531 | const config = await servers[0].config.getConfig() |
532 | const res = await makeHTMLRequest(servers[0].url, servers[0].store.video.embedPath) | |
aea0b0e7 | 533 | |
65e6e260 | 534 | checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', config) |
aea0b0e7 C |
535 | }) |
536 | }) | |
537 | ||
7c3b7976 | 538 | after(async function () { |
a59f210f | 539 | await cleanupTests(servers) |
0e1dc3e7 C |
540 | }) |
541 | }) |