diff options
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/config.ts | 7 | ||||
-rw-r--r-- | server/tests/api/check-params/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/check-params/video-imports.ts | 275 |
3 files changed, 283 insertions, 0 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index 03855237f..2742e26de 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts | |||
@@ -60,6 +60,13 @@ describe('Test config API validators', function () { | |||
60 | '720p': false, | 60 | '720p': false, |
61 | '1080p': false | 61 | '1080p': false |
62 | } | 62 | } |
63 | }, | ||
64 | import: { | ||
65 | videos: { | ||
66 | http: { | ||
67 | enabled: false | ||
68 | } | ||
69 | } | ||
63 | } | 70 | } |
64 | } | 71 | } |
65 | 72 | ||
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index 820dde889..03fdd5c4e 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts | |||
@@ -10,4 +10,5 @@ import './video-captions' | |||
10 | import './video-channels' | 10 | import './video-channels' |
11 | import './video-comments' | 11 | import './video-comments' |
12 | import './videos' | 12 | import './videos' |
13 | import './video-imports' | ||
13 | import './search' | 14 | import './search' |
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts new file mode 100644 index 000000000..0ead34a47 --- /dev/null +++ b/server/tests/api/check-params/video-imports.ts | |||
@@ -0,0 +1,275 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
3 | import { omit } from 'lodash' | ||
4 | import 'mocha' | ||
5 | import { join } from 'path' | ||
6 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' | ||
7 | import { | ||
8 | createUser, | ||
9 | flushTests, | ||
10 | getMyUserInformation, | ||
11 | immutableAssign, | ||
12 | killallServers, | ||
13 | makeGetRequest, | ||
14 | makePostBodyRequest, | ||
15 | makeUploadRequest, | ||
16 | runServer, | ||
17 | ServerInfo, | ||
18 | setAccessTokensToServers, | ||
19 | updateCustomSubConfig, | ||
20 | userLogin | ||
21 | } from '../../utils' | ||
22 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' | ||
23 | import { getYoutubeVideoUrl } from '../../utils/videos/video-imports' | ||
24 | |||
25 | describe('Test video imports API validator', function () { | ||
26 | const path = '/api/v1/videos/imports' | ||
27 | let server: ServerInfo | ||
28 | let userAccessToken = '' | ||
29 | let accountName: string | ||
30 | let channelId: number | ||
31 | let channelUUID: string | ||
32 | |||
33 | // --------------------------------------------------------------- | ||
34 | |||
35 | before(async function () { | ||
36 | this.timeout(30000) | ||
37 | |||
38 | await flushTests() | ||
39 | |||
40 | server = await runServer(1) | ||
41 | |||
42 | await setAccessTokensToServers([ server ]) | ||
43 | |||
44 | const username = 'user1' | ||
45 | const password = 'my super password' | ||
46 | await createUser(server.url, server.accessToken, username, password) | ||
47 | userAccessToken = await userLogin(server, { username, password }) | ||
48 | |||
49 | { | ||
50 | const res = await getMyUserInformation(server.url, server.accessToken) | ||
51 | channelId = res.body.videoChannels[ 0 ].id | ||
52 | channelUUID = res.body.videoChannels[ 0 ].uuid | ||
53 | accountName = res.body.account.name + '@' + res.body.account.host | ||
54 | } | ||
55 | }) | ||
56 | |||
57 | describe('When listing my video imports', function () { | ||
58 | const myPath = '/api/v1/users/me/videos/imports' | ||
59 | |||
60 | it('Should fail with a bad start pagination', async function () { | ||
61 | await checkBadStartPagination(server.url, myPath, server.accessToken) | ||
62 | }) | ||
63 | |||
64 | it('Should fail with a bad count pagination', async function () { | ||
65 | await checkBadCountPagination(server.url, myPath, server.accessToken) | ||
66 | }) | ||
67 | |||
68 | it('Should fail with an incorrect sort', async function () { | ||
69 | await checkBadSortPagination(server.url, myPath, server.accessToken) | ||
70 | }) | ||
71 | |||
72 | it('Should success with the correct parameters', async function () { | ||
73 | await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken }) | ||
74 | }) | ||
75 | }) | ||
76 | |||
77 | describe('When adding a video import', function () { | ||
78 | let baseCorrectParams | ||
79 | |||
80 | before(function () { | ||
81 | baseCorrectParams = { | ||
82 | targetUrl: getYoutubeVideoUrl(), | ||
83 | name: 'my super name', | ||
84 | category: 5, | ||
85 | licence: 1, | ||
86 | language: 'pt', | ||
87 | nsfw: false, | ||
88 | commentsEnabled: true, | ||
89 | waitTranscoding: true, | ||
90 | description: 'my super description', | ||
91 | support: 'my super support text', | ||
92 | tags: [ 'tag1', 'tag2' ], | ||
93 | privacy: VideoPrivacy.PUBLIC, | ||
94 | channelId: channelId | ||
95 | } | ||
96 | }) | ||
97 | |||
98 | it('Should fail with nothing', async function () { | ||
99 | const fields = {} | ||
100 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
101 | }) | ||
102 | |||
103 | it('Should fail without a target url', async function () { | ||
104 | const fields = omit(baseCorrectParams, 'targetUrl') | ||
105 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 400 }) | ||
106 | }) | ||
107 | |||
108 | it('Should fail with a bad target url', async function () { | ||
109 | const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' }) | ||
110 | |||
111 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
112 | }) | ||
113 | |||
114 | it('Should fail with a long name', async function () { | ||
115 | const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) | ||
116 | |||
117 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
118 | }) | ||
119 | |||
120 | it('Should fail with a bad category', async function () { | ||
121 | const fields = immutableAssign(baseCorrectParams, { category: 125 }) | ||
122 | |||
123 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
124 | }) | ||
125 | |||
126 | it('Should fail with a bad licence', async function () { | ||
127 | const fields = immutableAssign(baseCorrectParams, { licence: 125 }) | ||
128 | |||
129 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
130 | }) | ||
131 | |||
132 | it('Should fail with a bad language', async function () { | ||
133 | const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) | ||
134 | |||
135 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
136 | }) | ||
137 | |||
138 | it('Should fail with a long description', async function () { | ||
139 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) | ||
140 | |||
141 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
142 | }) | ||
143 | |||
144 | it('Should fail with a long support text', async function () { | ||
145 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) }) | ||
146 | |||
147 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
148 | }) | ||
149 | |||
150 | it('Should fail without a channel', async function () { | ||
151 | const fields = omit(baseCorrectParams, 'channelId') | ||
152 | |||
153 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
154 | }) | ||
155 | |||
156 | it('Should fail with a bad channel', async function () { | ||
157 | const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) | ||
158 | |||
159 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
160 | }) | ||
161 | |||
162 | it('Should fail with another user channel', async function () { | ||
163 | const user = { | ||
164 | username: 'fake', | ||
165 | password: 'fake_password' | ||
166 | } | ||
167 | await createUser(server.url, server.accessToken, user.username, user.password) | ||
168 | |||
169 | const accessTokenUser = await userLogin(server, user) | ||
170 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
171 | const customChannelId = res.body.videoChannels[0].id | ||
172 | |||
173 | const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) | ||
174 | |||
175 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) | ||
176 | }) | ||
177 | |||
178 | it('Should fail with too many tags', async function () { | ||
179 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) | ||
180 | |||
181 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
182 | }) | ||
183 | |||
184 | it('Should fail with a tag length too low', async function () { | ||
185 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) | ||
186 | |||
187 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
188 | }) | ||
189 | |||
190 | it('Should fail with a tag length too big', async function () { | ||
191 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) | ||
192 | |||
193 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
194 | }) | ||
195 | |||
196 | it('Should fail with an incorrect thumbnail file', async function () { | ||
197 | const fields = baseCorrectParams | ||
198 | const attaches = { | ||
199 | 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') | ||
200 | } | ||
201 | |||
202 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
203 | }) | ||
204 | |||
205 | it('Should fail with a big thumbnail file', async function () { | ||
206 | const fields = baseCorrectParams | ||
207 | const attaches = { | ||
208 | 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') | ||
209 | } | ||
210 | |||
211 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
212 | }) | ||
213 | |||
214 | it('Should fail with an incorrect preview file', async function () { | ||
215 | const fields = baseCorrectParams | ||
216 | const attaches = { | ||
217 | 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') | ||
218 | } | ||
219 | |||
220 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
221 | }) | ||
222 | |||
223 | it('Should fail with a big preview file', async function () { | ||
224 | const fields = baseCorrectParams | ||
225 | const attaches = { | ||
226 | 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') | ||
227 | } | ||
228 | |||
229 | await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches }) | ||
230 | }) | ||
231 | |||
232 | it('Should succeed with the correct parameters', async function () { | ||
233 | this.timeout(10000) | ||
234 | |||
235 | { | ||
236 | await makePostBodyRequest({ | ||
237 | url: server.url, | ||
238 | path, | ||
239 | token: server.accessToken, | ||
240 | fields: baseCorrectParams, | ||
241 | statusCodeExpected: 200 | ||
242 | }) | ||
243 | } | ||
244 | }) | ||
245 | |||
246 | it('Should forbid to import videos', async function () { | ||
247 | await updateCustomSubConfig(server.url, server.accessToken, { | ||
248 | import: { | ||
249 | videos: { | ||
250 | http: { | ||
251 | enabled: false | ||
252 | } | ||
253 | } | ||
254 | } | ||
255 | }) | ||
256 | |||
257 | await makePostBodyRequest({ | ||
258 | url: server.url, | ||
259 | path, | ||
260 | token: server.accessToken, | ||
261 | fields: baseCorrectParams, | ||
262 | statusCodeExpected: 409 | ||
263 | }) | ||
264 | }) | ||
265 | }) | ||
266 | |||
267 | after(async function () { | ||
268 | killallServers([ server ]) | ||
269 | |||
270 | // Keep the logs if the test failed | ||
271 | if (this['ok']) { | ||
272 | await flushTests() | ||
273 | } | ||
274 | }) | ||
275 | }) | ||