]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
40e87e9e | 2 | |
c55e3d72 | 3 | import { buildAbsoluteFixturePath } from '@shared/core-utils' |
c3edc5b0 | 4 | import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models' |
40e87e9e | 5 | import { |
7c3b7976 | 6 | cleanupTests, |
254d3579 | 7 | createSingleServer, |
40e87e9e C |
8 | makeDeleteRequest, |
9 | makeGetRequest, | |
10 | makeUploadRequest, | |
254d3579 | 11 | PeerTubeServer, |
d23dd9fb | 12 | setAccessTokensToServers |
bf54587a | 13 | } from '@shared/server-commands' |
40e87e9e C |
14 | |
15 | describe('Test video captions API validator', function () { | |
16 | const path = '/api/v1/videos/' | |
17 | ||
254d3579 | 18 | let server: PeerTubeServer |
40e87e9e | 19 | let userAccessToken: string |
d4a8e7a6 | 20 | let video: VideoCreateResult |
795212f7 | 21 | let privateVideo: VideoCreateResult |
40e87e9e C |
22 | |
23 | // --------------------------------------------------------------- | |
24 | ||
25 | before(async function () { | |
e901579b | 26 | this.timeout(120000) |
40e87e9e | 27 | |
254d3579 | 28 | server = await createSingleServer(1) |
40e87e9e C |
29 | |
30 | await setAccessTokensToServers([ server ]) | |
31 | ||
89d241a7 | 32 | video = await server.videos.upload() |
795212f7 | 33 | privateVideo = await server.videos.upload({ attributes: { privacy: VideoPrivacy.PRIVATE } }) |
40e87e9e C |
34 | |
35 | { | |
36 | const user = { | |
37 | username: 'user1', | |
38 | password: 'my super password' | |
39 | } | |
89d241a7 C |
40 | await server.users.create({ username: user.username, password: user.password }) |
41 | userAccessToken = await server.login.getAccessToken(user) | |
40e87e9e C |
42 | } |
43 | }) | |
44 | ||
45 | describe('When adding video caption', function () { | |
46 | const fields = { } | |
47 | const attaches = { | |
3d470a53 | 48 | captionfile: buildAbsoluteFixturePath('subtitle-good1.vtt') |
40e87e9e C |
49 | } |
50 | ||
51 | it('Should fail without a valid uuid', async function () { | |
52 | await makeUploadRequest({ | |
53 | method: 'PUT', | |
54 | url: server.url, | |
59fd824c | 55 | path: path + '4da6fde3-88f7-4d16-b119-108df563d0b06/captions/fr', |
40e87e9e C |
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, | |
59fd824c | 66 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr', |
40e87e9e C |
67 | token: server.accessToken, |
68 | fields, | |
59fd824c | 69 | attaches, |
c0e8b12e | 70 | expectedStatus: 404 |
40e87e9e C |
71 | }) |
72 | }) | |
73 | ||
74 | it('Should fail with a missing language in path', async function () { | |
d4a8e7a6 | 75 | const captionPath = path + video.uuid + '/captions' |
40e87e9e C |
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 () { | |
d4a8e7a6 | 87 | const captionPath = path + video.uuid + '/captions/15' |
40e87e9e C |
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 () { | |
d4a8e7a6 | 99 | const captionPath = path + video.uuid + '/captions/fr' |
40e87e9e C |
100 | await makeUploadRequest({ |
101 | method: 'PUT', | |
102 | url: server.url, | |
103 | path: captionPath, | |
104 | fields, | |
105 | attaches, | |
c0e8b12e | 106 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
40e87e9e C |
107 | }) |
108 | }) | |
109 | ||
110 | it('Should fail with a bad access token', async function () { | |
d4a8e7a6 | 111 | const captionPath = path + video.uuid + '/captions/fr' |
40e87e9e C |
112 | await makeUploadRequest({ |
113 | method: 'PUT', | |
114 | url: server.url, | |
115 | path: captionPath, | |
116 | token: 'blabla', | |
117 | fields, | |
118 | attaches, | |
c0e8b12e | 119 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
40e87e9e C |
120 | }) |
121 | }) | |
122 | ||
39a26b2e C |
123 | // We accept any file now |
124 | // it('Should fail with an invalid captionfile extension', async function () { | |
125 | // const attaches = { | |
3d470a53 | 126 | // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.txt') |
39a26b2e C |
127 | // } |
128 | // | |
d4a8e7a6 | 129 | // const captionPath = path + video.uuid + '/captions/fr' |
39a26b2e C |
130 | // await makeUploadRequest({ |
131 | // method: 'PUT', | |
132 | // url: server.url, | |
133 | // path: captionPath, | |
134 | // token: server.accessToken, | |
135 | // fields, | |
136 | // attaches, | |
c0e8b12e | 137 | // expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
39a26b2e C |
138 | // }) |
139 | // }) | |
f4001cf4 | 140 | |
2769e297 C |
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', | |
d4a8e7a6 | 147 | // videoId: video.uuid, |
2769e297 C |
148 | // fixture: 'subtitle-bad.txt', |
149 | // mimeType: 'application/octet-stream', | |
c0e8b12e | 150 | // expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
2769e297 C |
151 | // }) |
152 | // }) | |
153 | ||
154 | it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () { | |
c63830f1 | 155 | await server.captions.add({ |
2769e297 | 156 | language: 'zh', |
d4a8e7a6 | 157 | videoId: video.uuid, |
2769e297 C |
158 | fixture: 'subtitle-good.srt', |
159 | mimeType: 'application/octet-stream' | |
160 | }) | |
161 | }) | |
162 | ||
163 | // We don't check the file validity yet | |
f4001cf4 C |
164 | // it('Should fail with an invalid captionfile srt', async function () { |
165 | // const attaches = { | |
3d470a53 | 166 | // 'captionfile': buildAbsoluteFixturePath('subtitle-bad.srt') |
f4001cf4 C |
167 | // } |
168 | // | |
d4a8e7a6 | 169 | // const captionPath = path + video.uuid + '/captions/fr' |
f4001cf4 C |
170 | // await makeUploadRequest({ |
171 | // method: 'PUT', | |
172 | // url: server.url, | |
173 | // path: captionPath, | |
174 | // token: server.accessToken, | |
175 | // fields, | |
176 | // attaches, | |
c0e8b12e | 177 | // expectedStatus: HttpStatusCode.INTERNAL_SERVER_ERROR_500 |
f4001cf4 C |
178 | // }) |
179 | // }) | |
180 | ||
40e87e9e | 181 | it('Should success with the correct parameters', async function () { |
d4a8e7a6 | 182 | const captionPath = path + video.uuid + '/captions/fr' |
40e87e9e C |
183 | await makeUploadRequest({ |
184 | method: 'PUT', | |
185 | url: server.url, | |
186 | path: captionPath, | |
187 | token: server.accessToken, | |
188 | fields, | |
189 | attaches, | |
c0e8b12e | 190 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
40e87e9e C |
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 () { | |
2d53be02 RK |
201 | await makeGetRequest({ |
202 | url: server.url, | |
203 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', | |
c0e8b12e | 204 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
2d53be02 | 205 | }) |
40e87e9e C |
206 | }) |
207 | ||
795212f7 C |
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 | ||
40e87e9e | 225 | it('Should success with the correct parameters', async function () { |
c0e8b12e | 226 | await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', expectedStatus: HttpStatusCode.OK_200 }) |
795212f7 C |
227 | |
228 | await makeGetRequest({ | |
229 | url: server.url, | |
230 | path: path + privateVideo.shortUUID + '/captions', | |
231 | token: server.accessToken, | |
232 | expectedStatus: HttpStatusCode.OK_200 | |
233 | }) | |
40e87e9e C |
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, | |
c0e8b12e | 251 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
40e87e9e C |
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 () { | |
d4a8e7a6 | 264 | const captionPath = path + video.shortUUID + '/captions' |
40e87e9e C |
265 | await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken }) |
266 | }) | |
267 | ||
268 | it('Should fail with an unknown language', async function () { | |
d4a8e7a6 | 269 | const captionPath = path + video.shortUUID + '/captions/15' |
40e87e9e C |
270 | await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken }) |
271 | }) | |
272 | ||
273 | it('Should fail without access token', async function () { | |
d4a8e7a6 | 274 | const captionPath = path + video.shortUUID + '/captions/fr' |
c0e8b12e | 275 | await makeDeleteRequest({ url: server.url, path: captionPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
40e87e9e C |
276 | }) |
277 | ||
278 | it('Should fail with a bad access token', async function () { | |
d4a8e7a6 | 279 | const captionPath = path + video.shortUUID + '/captions/fr' |
c0e8b12e | 280 | await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
40e87e9e C |
281 | }) |
282 | ||
283 | it('Should fail with another user', async function () { | |
d4a8e7a6 | 284 | const captionPath = path + video.shortUUID + '/captions/fr' |
2d53be02 RK |
285 | await makeDeleteRequest({ |
286 | url: server.url, | |
287 | path: captionPath, | |
288 | token: userAccessToken, | |
c0e8b12e | 289 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
2d53be02 | 290 | }) |
40e87e9e C |
291 | }) |
292 | ||
293 | it('Should success with the correct parameters', async function () { | |
d4a8e7a6 | 294 | const captionPath = path + video.shortUUID + '/captions/fr' |
2d53be02 RK |
295 | await makeDeleteRequest({ |
296 | url: server.url, | |
297 | path: captionPath, | |
298 | token: server.accessToken, | |
c0e8b12e | 299 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
2d53be02 | 300 | }) |
40e87e9e C |
301 | }) |
302 | }) | |
303 | ||
7c3b7976 C |
304 | after(async function () { |
305 | await cleanupTests([ server ]) | |
40e87e9e C |
306 | }) |
307 | }) |