]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/services.ts
Add filter hook to forbid embed access
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / services.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { Video, VideoPlaylistPrivacy } from '@shared/models'
6 import {
7 addVideoInPlaylist,
8 createVideoPlaylist,
9 getOEmbed,
10 getVideosList,
11 ServerInfo,
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
14 uploadVideo
15 } from '../../../../shared/extra-utils'
16 import { cleanupTests, flushAndRunServer } from '../../../../shared/extra-utils/server/servers'
17
18 const expect = chai.expect
19
20 describe('Test services', function () {
21 let server: ServerInfo = null
22 let playlistUUID: string
23 let video: Video
24
25 before(async function () {
26 this.timeout(30000)
27
28 server = await flushAndRunServer(1)
29
30 await setAccessTokensToServers([ server ])
31 await setDefaultVideoChannel([ server ])
32
33 {
34 const videoAttributes = {
35 name: 'my super name'
36 }
37 await uploadVideo(server.url, server.accessToken, videoAttributes)
38
39 const res = await getVideosList(server.url)
40 video = res.body.data[0]
41 }
42
43 {
44 const res = await createVideoPlaylist({
45 url: server.url,
46 token: server.accessToken,
47 playlistAttrs: {
48 displayName: 'The Life and Times of Scrooge McDuck',
49 privacy: VideoPlaylistPrivacy.PUBLIC,
50 videoChannelId: server.videoChannel.id
51 }
52 })
53
54 playlistUUID = res.body.videoPlaylist.uuid
55
56 await addVideoInPlaylist({
57 url: server.url,
58 token: server.accessToken,
59 playlistId: res.body.videoPlaylist.id,
60 elementAttrs: {
61 videoId: video.id
62 }
63 })
64 }
65 })
66
67 it('Should have a valid oEmbed video response', async function () {
68 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + video.uuid
69
70 const res = await getOEmbed(server.url, oembedUrl)
71 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
72 `src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
73 'frameborder="0" allowfullscreen></iframe>'
74 const expectedThumbnailUrl = 'http://localhost:' + server.port + video.previewPath
75
76 expect(res.body.html).to.equal(expectedHtml)
77 expect(res.body.title).to.equal(video.name)
78 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
79 expect(res.body.width).to.equal(560)
80 expect(res.body.height).to.equal(315)
81 expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
82 expect(res.body.thumbnail_width).to.equal(850)
83 expect(res.body.thumbnail_height).to.equal(480)
84 })
85
86 it('Should have a valid playlist oEmbed response', async function () {
87 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/playlist/' + playlistUUID
88
89 const res = await getOEmbed(server.url, oembedUrl)
90 const expectedHtml = '<iframe width="560" height="315" sandbox="allow-same-origin allow-scripts" ' +
91 `src="http://localhost:${server.port}/video-playlists/embed/${playlistUUID}" ` +
92 'frameborder="0" allowfullscreen></iframe>'
93
94 expect(res.body.html).to.equal(expectedHtml)
95 expect(res.body.title).to.equal('The Life and Times of Scrooge McDuck')
96 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
97 expect(res.body.width).to.equal(560)
98 expect(res.body.height).to.equal(315)
99 expect(res.body.thumbnail_url).exist
100 expect(res.body.thumbnail_width).to.equal(223)
101 expect(res.body.thumbnail_height).to.equal(122)
102 })
103
104 it('Should have a valid oEmbed response with small max height query', async function () {
105 const oembedUrl = 'http://localhost:' + server.port + '/videos/watch/' + video.uuid
106 const format = 'json'
107 const maxHeight = 50
108 const maxWidth = 50
109
110 const res = await getOEmbed(server.url, oembedUrl, format, maxHeight, maxWidth)
111 const expectedHtml = '<iframe width="50" height="50" sandbox="allow-same-origin allow-scripts" ' +
112 `src="http://localhost:${server.port}/videos/embed/${video.uuid}" ` +
113 'frameborder="0" allowfullscreen></iframe>'
114
115 expect(res.body.html).to.equal(expectedHtml)
116 expect(res.body.title).to.equal(video.name)
117 expect(res.body.author_name).to.equal(server.videoChannel.displayName)
118 expect(res.body.height).to.equal(50)
119 expect(res.body.width).to.equal(50)
120 expect(res.body).to.not.have.property('thumbnail_url')
121 expect(res.body).to.not.have.property('thumbnail_width')
122 expect(res.body).to.not.have.property('thumbnail_height')
123 })
124
125 after(async function () {
126 await cleanupTests([ server ])
127 })
128 })