]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
d8755eed | 2 | |
d8755eed | 3 | import 'mocha' |
b3d9dedc | 4 | import { HttpStatusCode, VideoCreateResult, VideoPlaylistCreateResult, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' |
9639bd17 | 5 | import { |
7c3b7976 | 6 | cleanupTests, |
254d3579 | 7 | createSingleServer, |
7c3b7976 | 8 | makeGetRequest, |
254d3579 | 9 | PeerTubeServer, |
9639bd17 | 10 | setAccessTokensToServers, |
d23dd9fb | 11 | setDefaultVideoChannel |
bf54587a | 12 | } from '@shared/server-commands' |
d8755eed C |
13 | |
14 | describe('Test services API validators', function () { | |
254d3579 | 15 | let server: PeerTubeServer |
6fad8e51 | 16 | let playlistUUID: string |
d8755eed | 17 | |
b3d9dedc C |
18 | let privateVideo: VideoCreateResult |
19 | let unlistedVideo: VideoCreateResult | |
20 | ||
21 | let privatePlaylist: VideoPlaylistCreateResult | |
22 | let unlistedPlaylist: VideoPlaylistCreateResult | |
23 | ||
d8755eed C |
24 | // --------------------------------------------------------------- |
25 | ||
26 | before(async function () { | |
27 | this.timeout(60000) | |
28 | ||
254d3579 | 29 | server = await createSingleServer(1) |
d8755eed | 30 | await setAccessTokensToServers([ server ]) |
6fad8e51 C |
31 | await setDefaultVideoChannel([ server ]) |
32 | ||
83903cb6 | 33 | server.store.videoCreated = await server.videos.upload({ attributes: { name: 'my super name' } }) |
6fad8e51 | 34 | |
b3d9dedc C |
35 | privateVideo = await server.videos.quickUpload({ name: 'private', privacy: VideoPrivacy.PRIVATE }) |
36 | unlistedVideo = await server.videos.quickUpload({ name: 'unlisted', privacy: VideoPrivacy.UNLISTED }) | |
37 | ||
6fad8e51 | 38 | { |
89d241a7 | 39 | const created = await server.playlists.create({ |
e6346d59 | 40 | attributes: { |
6fad8e51 C |
41 | displayName: 'super playlist', |
42 | privacy: VideoPlaylistPrivacy.PUBLIC, | |
89d241a7 | 43 | videoChannelId: server.store.channel.id |
6fad8e51 C |
44 | } |
45 | }) | |
46 | ||
e6346d59 | 47 | playlistUUID = created.uuid |
b3d9dedc C |
48 | |
49 | privatePlaylist = await server.playlists.create({ | |
50 | attributes: { | |
51 | displayName: 'private', | |
52 | privacy: VideoPlaylistPrivacy.PRIVATE, | |
53 | videoChannelId: server.store.channel.id | |
54 | } | |
55 | }) | |
56 | ||
57 | unlistedPlaylist = await server.playlists.create({ | |
58 | attributes: { | |
59 | displayName: 'unlisted', | |
60 | privacy: VideoPlaylistPrivacy.UNLISTED, | |
61 | videoChannelId: server.store.channel.id | |
62 | } | |
63 | }) | |
6fad8e51 | 64 | } |
d8755eed C |
65 | }) |
66 | ||
67 | describe('Test oEmbed API validators', function () { | |
d8755eed C |
68 | |
69 | it('Should fail with an invalid url', async function () { | |
70 | const embedUrl = 'hello.com' | |
331128ed | 71 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
72 | }) |
73 | ||
74 | it('Should fail with an invalid host', async function () { | |
83903cb6 | 75 | const embedUrl = 'http://hello.com/videos/watch/' + server.store.videoCreated.uuid |
331128ed | 76 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
77 | }) |
78 | ||
6fad8e51 | 79 | it('Should fail with an invalid element id', async function () { |
7c3b7976 | 80 | const embedUrl = `http://localhost:${server.port}/videos/watch/blabla` |
331128ed | 81 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
82 | }) |
83 | ||
6fad8e51 | 84 | it('Should fail with an unknown element', async function () { |
7c3b7976 | 85 | const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c` |
2d53be02 | 86 | await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_FOUND_404) |
d8755eed C |
87 | }) |
88 | ||
89 | it('Should fail with an invalid path', async function () { | |
83903cb6 | 90 | const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.store.videoCreated.uuid}` |
d8755eed | 91 | |
331128ed | 92 | await checkParamEmbed(server, embedUrl) |
d8755eed C |
93 | }) |
94 | ||
95 | it('Should fail with an invalid max height', async function () { | |
83903cb6 | 96 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}` |
d8755eed | 97 | |
2d53be02 | 98 | await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' }) |
d8755eed C |
99 | }) |
100 | ||
101 | it('Should fail with an invalid max width', async function () { | |
83903cb6 | 102 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}` |
d8755eed | 103 | |
2d53be02 | 104 | await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' }) |
d8755eed C |
105 | }) |
106 | ||
107 | it('Should fail with an invalid format', async function () { | |
83903cb6 | 108 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}` |
d8755eed | 109 | |
2d53be02 | 110 | await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' }) |
d8755eed C |
111 | }) |
112 | ||
113 | it('Should fail with a non supported format', async function () { | |
83903cb6 | 114 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}` |
d8755eed | 115 | |
2d53be02 | 116 | await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' }) |
331128ed C |
117 | }) |
118 | ||
b3d9dedc C |
119 | it('Should fail with a private video', async function () { |
120 | const embedUrl = `http://localhost:${server.port}/videos/watch/${privateVideo.uuid}` | |
121 | ||
122 | await checkParamEmbed(server, embedUrl, HttpStatusCode.FORBIDDEN_403) | |
123 | }) | |
124 | ||
125 | it('Should fail with an unlisted video with the int id', async function () { | |
126 | const embedUrl = `http://localhost:${server.port}/videos/watch/${unlistedVideo.id}` | |
127 | ||
128 | await checkParamEmbed(server, embedUrl, HttpStatusCode.FORBIDDEN_403) | |
129 | }) | |
130 | ||
131 | it('Should succeed with an unlisted video using the uuid id', async function () { | |
132 | for (const uuid of [ unlistedVideo.uuid, unlistedVideo.shortUUID ]) { | |
133 | const embedUrl = `http://localhost:${server.port}/videos/watch/${uuid}` | |
134 | ||
135 | await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200) | |
136 | } | |
137 | }) | |
138 | ||
139 | it('Should fail with a private playlist', async function () { | |
140 | const embedUrl = `http://localhost:${server.port}/videos/watch/playlist/${privatePlaylist.uuid}` | |
141 | ||
142 | await checkParamEmbed(server, embedUrl, HttpStatusCode.FORBIDDEN_403) | |
143 | }) | |
144 | ||
145 | it('Should fail with an unlisted playlist using the int id', async function () { | |
146 | const embedUrl = `http://localhost:${server.port}/videos/watch/playlist/${unlistedPlaylist.id}` | |
147 | ||
148 | await checkParamEmbed(server, embedUrl, HttpStatusCode.FORBIDDEN_403) | |
149 | }) | |
150 | ||
151 | it('Should succeed with an unlisted playlist using the uuid id', async function () { | |
152 | for (const uuid of [ unlistedPlaylist.uuid, unlistedPlaylist.shortUUID ]) { | |
153 | const embedUrl = `http://localhost:${server.port}/videos/watch/playlist/${uuid}` | |
154 | ||
155 | await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200) | |
156 | } | |
157 | }) | |
158 | ||
6fad8e51 | 159 | it('Should succeed with the correct params with a video', async function () { |
83903cb6 | 160 | const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.videoCreated.uuid}` |
331128ed C |
161 | const query = { |
162 | format: 'json', | |
163 | maxheight: 400, | |
164 | maxwidth: 400 | |
165 | } | |
166 | ||
2d53be02 | 167 | await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query) |
d8755eed | 168 | }) |
6fad8e51 C |
169 | |
170 | it('Should succeed with the correct params with a playlist', async function () { | |
171 | const embedUrl = `http://localhost:${server.port}/videos/watch/playlist/${playlistUUID}` | |
172 | const query = { | |
173 | format: 'json', | |
174 | maxheight: 400, | |
175 | maxwidth: 400 | |
176 | } | |
177 | ||
2d53be02 | 178 | await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query) |
6fad8e51 | 179 | }) |
d8755eed C |
180 | }) |
181 | ||
7c3b7976 C |
182 | after(async function () { |
183 | await cleanupTests([ server ]) | |
d8755eed C |
184 | }) |
185 | }) | |
331128ed | 186 | |
c0e8b12e | 187 | function checkParamEmbed (server: PeerTubeServer, embedUrl: string, expectedStatus = HttpStatusCode.BAD_REQUEST_400, query = {}) { |
331128ed C |
188 | const path = '/services/oembed' |
189 | ||
190 | return makeGetRequest({ | |
191 | url: server.url, | |
192 | path, | |
193 | query: Object.assign(query, { url: embedUrl }), | |
c0e8b12e | 194 | expectedStatus |
331128ed C |
195 | }) |
196 | } |