]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import { buildAbsoluteFixturePath } from '@shared/core-utils' | |
4 | import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models' | |
5 | import { | |
6 | cleanupTests, | |
7 | createSingleServer, | |
8 | makeDeleteRequest, | |
9 | makeGetRequest, | |
10 | makeUploadRequest, | |
11 | PeerTubeServer, | |
12 | setAccessTokensToServers | |
13 | } from '@shared/server-commands' | |
14 | ||
15 | describe('Test video captions API validator', function () { | |
16 | const path = '/api/v1/videos/' | |
17 | ||
18 | let server: PeerTubeServer | |
19 | let userAccessToken: string | |
20 | let video: VideoCreateResult | |
21 | let privateVideo: VideoCreateResult | |
22 | ||
23 | // --------------------------------------------------------------- | |
24 | ||
25 | before(async function () { | |
26 | this.timeout(30000) | |
27 | ||
28 | server = await createSingleServer(1) | |
29 | ||
30 | await setAccessTokensToServers([ server ]) | |
31 | ||
32 | video = await server.videos.upload() | |
33 | privateVideo = await server.videos.upload({ attributes: { privacy: VideoPrivacy.PRIVATE } }) | |
34 | ||
35 | { | |
36 | const user = { | |
37 | username: 'user1', | |
38 | password: 'my super password' | |
39 | } | |
40 | await server.users.create({ username: user.username, password: user.password }) | |
41 | userAccessToken = await server.login.getAccessToken(user) | |
42 | } | |
43 | }) | |
44 | ||
45 | describe('When adding video caption', function () { | |
46 | const fields = { } | |
47 | const attaches = { | |
48 | captionfile: buildAbsoluteFixturePath('subtitle-good1.vtt') | |
49 | } | |
50 | ||
51 | it('Should fail without a valid uuid', async function () { | |
52 | await makeUploadRequest({ | |
53 | method: 'PUT', | |
54 | url: server.url, | |
55 | path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr', | |
56 | token: server.accessToken, | |
57 | fields, | |
58 | attaches | |
59 | }) | |
60 | }) | |
61 | ||
62 | it('Should fail with an unknown id', async function () { | |
63 | await makeUploadRequest({ | |
64 | method: 'PUT', | |
65 | url: server.url, | |
66 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr', | |
67 | token: server.accessToken, | |
68 | fields, | |
69 | attaches, | |
70 | expectedStatus: 404 | |
71 | }) | |
72 | }) | |
73 | ||
74 | it('Should fail with a missing language in path', async function () { | |
75 | const captionPath = path + video.uuid + '/captions' | |
76 | await makeUploadRequest({ | |
77 | method: 'PUT', | |
78 | url: server.url, | |
79 | path: captionPath, | |
80 | token: server.accessToken, | |
81 | fields, | |
82 | attaches | |
83 | }) | |
84 | }) | |
85 | ||
86 | it('Should fail with an unknown language', async function () { | |
87 | const captionPath = path + video.uuid + '/captions/15' | |
88 | await makeUploadRequest({ | |
89 | method: 'PUT', | |
90 | url: server.url, | |
91 | path: captionPath, | |
92 | token: server.accessToken, | |
93 | fields, | |
94 | attaches | |
95 | }) | |
96 | }) | |
97 | ||
98 | it('Should fail without access token', async function () { | |
99 | const captionPath = path + video.uuid + '/captions/fr' | |
100 | await makeUploadRequest({ | |
101 | method: 'PUT', | |
102 | url: server.url, | |
103 | path: captionPath, | |
104 | fields, | |
105 | attaches, | |
106 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
107 | }) | |
108 | }) | |
109 | ||
110 | it('Should fail with a bad access token', async function () { | |
111 | const captionPath = path + video.uuid + '/captions/fr' | |
112 | await makeUploadRequest({ | |
113 | method: 'PUT', | |
114 | url: server.url, | |
115 | path: captionPath, | |
116 | token: 'blabla', | |
117 | fields, | |
118 | attaches, | |
119 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
120 | }) | |
121 | }) | |
122 | ||
123 | // We accept any file now | |
124 | // it('Should fail with an invalid captionfile extension', async function () { | |
125 | // const attaches = { | |
126 | // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.txt') | |
127 | // } | |
128 | // | |
129 | // const captionPath = path + video.uuid + '/captions/fr' | |
130 | // await makeUploadRequest({ | |
131 | // method: 'PUT', | |
132 | // url: server.url, | |
133 | // path: captionPath, | |
134 | // token: server.accessToken, | |
135 | // fields, | |
136 | // attaches, | |
137 | // expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
138 | // }) | |
139 | // }) | |
140 | ||
141 | // We don't check the extension yet | |
142 | // it('Should fail with an invalid captionfile extension and octet-stream mime type', async function () { | |
143 | // await createVideoCaption({ | |
144 | // url: server.url, | |
145 | // accessToken: server.accessToken, | |
146 | // language: 'zh', | |
147 | // videoId: video.uuid, | |
148 | // fixture: 'subtitle-bad.txt', | |
149 | // mimeType: 'application/octet-stream', | |
150 | // expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
151 | // }) | |
152 | // }) | |
153 | ||
154 | it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () { | |
155 | await server.captions.add({ | |
156 | language: 'zh', | |
157 | videoId: video.uuid, | |
158 | fixture: 'subtitle-good.srt', | |
159 | mimeType: 'application/octet-stream' | |
160 | }) | |
161 | }) | |
162 | ||
163 | // We don't check the file validity yet | |
164 | // it('Should fail with an invalid captionfile srt', async function () { | |
165 | // const attaches = { | |
166 | // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt') | |
167 | // } | |
168 | // | |
169 | // const captionPath = path + video.uuid + '/captions/fr' | |
170 | // await makeUploadRequest({ | |
171 | // method: 'PUT', | |
172 | // url: server.url, | |
173 | // path: captionPath, | |
174 | // token: server.accessToken, | |
175 | // fields, | |
176 | // attaches, | |
177 | // expectedStatus: HttpStatusCode.INTERNAL_SERVER_ERROR_500 | |
178 | // }) | |
179 | // }) | |
180 | ||
181 | it('Should success with the correct parameters', async function () { | |
182 | const captionPath = path + video.uuid + '/captions/fr' | |
183 | await makeUploadRequest({ | |
184 | method: 'PUT', | |
185 | url: server.url, | |
186 | path: captionPath, | |
187 | token: server.accessToken, | |
188 | fields, | |
189 | attaches, | |
190 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | |
191 | }) | |
192 | }) | |
193 | }) | |
194 | ||
195 | describe('When listing video captions', function () { | |
196 | it('Should fail without a valid uuid', async function () { | |
197 | await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions' }) | |
198 | }) | |
199 | ||
200 | it('Should fail with an unknown id', async function () { | |
201 | await makeGetRequest({ | |
202 | url: server.url, | |
203 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', | |
204 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | |
205 | }) | |
206 | }) | |
207 | ||
208 | it('Should fail with a private video without token', async function () { | |
209 | await makeGetRequest({ | |
210 | url: server.url, | |
211 | path: path + privateVideo.shortUUID + '/captions', | |
212 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
213 | }) | |
214 | }) | |
215 | ||
216 | it('Should fail with another user token', async function () { | |
217 | await makeGetRequest({ | |
218 | url: server.url, | |
219 | token: userAccessToken, | |
220 | path: path + privateVideo.shortUUID + '/captions', | |
221 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
222 | }) | |
223 | }) | |
224 | ||
225 | it('Should success with the correct parameters', async function () { | |
226 | await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', expectedStatus: HttpStatusCode.OK_200 }) | |
227 | ||
228 | await makeGetRequest({ | |
229 | url: server.url, | |
230 | path: path + privateVideo.shortUUID + '/captions', | |
231 | token: server.accessToken, | |
232 | expectedStatus: HttpStatusCode.OK_200 | |
233 | }) | |
234 | }) | |
235 | }) | |
236 | ||
237 | describe('When deleting video caption', function () { | |
238 | it('Should fail without a valid uuid', async function () { | |
239 | await makeDeleteRequest({ | |
240 | url: server.url, | |
241 | path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr', | |
242 | token: server.accessToken | |
243 | }) | |
244 | }) | |
245 | ||
246 | it('Should fail with an unknown id', async function () { | |
247 | await makeDeleteRequest({ | |
248 | url: server.url, | |
249 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr', | |
250 | token: server.accessToken, | |
251 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | |
252 | }) | |
253 | }) | |
254 | ||
255 | it('Should fail with an invalid language', async function () { | |
256 | await makeDeleteRequest({ | |
257 | url: server.url, | |
258 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/16', | |
259 | token: server.accessToken | |
260 | }) | |
261 | }) | |
262 | ||
263 | it('Should fail with a missing language', async function () { | |
264 | const captionPath = path + video.shortUUID + '/captions' | |
265 | await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken }) | |
266 | }) | |
267 | ||
268 | it('Should fail with an unknown language', async function () { | |
269 | const captionPath = path + video.shortUUID + '/captions/15' | |
270 | await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken }) | |
271 | }) | |
272 | ||
273 | it('Should fail without access token', async function () { | |
274 | const captionPath = path + video.shortUUID + '/captions/fr' | |
275 | await makeDeleteRequest({ url: server.url, path: captionPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
276 | }) | |
277 | ||
278 | it('Should fail with a bad access token', async function () { | |
279 | const captionPath = path + video.shortUUID + '/captions/fr' | |
280 | await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
281 | }) | |
282 | ||
283 | it('Should fail with another user', async function () { | |
284 | const captionPath = path + video.shortUUID + '/captions/fr' | |
285 | await makeDeleteRequest({ | |
286 | url: server.url, | |
287 | path: captionPath, | |
288 | token: userAccessToken, | |
289 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
290 | }) | |
291 | }) | |
292 | ||
293 | it('Should success with the correct parameters', async function () { | |
294 | const captionPath = path + video.shortUUID + '/captions/fr' | |
295 | await makeDeleteRequest({ | |
296 | url: server.url, | |
297 | path: captionPath, | |
298 | token: server.accessToken, | |
299 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | |
300 | }) | |
301 | }) | |
302 | }) | |
303 | ||
304 | after(async function () { | |
305 | await cleanupTests([ server ]) | |
306 | }) | |
307 | }) |