diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
commit | a24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch) | |
tree | a54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tests/api/check-params/video-imports.ts | |
parent | 5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff) | |
parent | c63830f15403ac4e750829f27d8bbbdc9a59282c (diff) | |
download | PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip |
Merge branch 'next' into develop
Diffstat (limited to 'server/tests/api/check-params/video-imports.ts')
-rw-r--r-- | server/tests/api/check-params/video-imports.ts | 124 |
1 files changed, 60 insertions, 64 deletions
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index a27b624d0..d6d745488 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts | |||
@@ -2,33 +2,25 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { omit } from 'lodash' | 4 | import { omit } from 'lodash' |
5 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
6 | import { | 5 | import { |
7 | buildAbsoluteFixturePath, | 6 | buildAbsoluteFixturePath, |
7 | checkBadCountPagination, | ||
8 | checkBadSortPagination, | ||
9 | checkBadStartPagination, | ||
8 | cleanupTests, | 10 | cleanupTests, |
9 | createUser, | 11 | createSingleServer, |
10 | flushAndRunServer, | 12 | FIXTURE_URLS, |
11 | getMyUserInformation, | ||
12 | immutableAssign, | ||
13 | makeGetRequest, | 13 | makeGetRequest, |
14 | makePostBodyRequest, | 14 | makePostBodyRequest, |
15 | makeUploadRequest, | 15 | makeUploadRequest, |
16 | ServerInfo, | 16 | PeerTubeServer, |
17 | setAccessTokensToServers, | 17 | setAccessTokensToServers |
18 | updateCustomSubConfig, | 18 | } from '@shared/extra-utils' |
19 | userLogin | 19 | import { HttpStatusCode, VideoPrivacy } from '@shared/models' |
20 | } from '../../../../shared/extra-utils' | ||
21 | import { | ||
22 | checkBadCountPagination, | ||
23 | checkBadSortPagination, | ||
24 | checkBadStartPagination | ||
25 | } from '../../../../shared/extra-utils/requests/check-api-params' | ||
26 | import { getGoodVideoUrl, getMagnetURI } from '../../../../shared/extra-utils/videos/video-imports' | ||
27 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' | ||
28 | 20 | ||
29 | describe('Test video imports API validator', function () { | 21 | describe('Test video imports API validator', function () { |
30 | const path = '/api/v1/videos/imports' | 22 | const path = '/api/v1/videos/imports' |
31 | let server: ServerInfo | 23 | let server: PeerTubeServer |
32 | let userAccessToken = '' | 24 | let userAccessToken = '' |
33 | let channelId: number | 25 | let channelId: number |
34 | 26 | ||
@@ -37,18 +29,18 @@ describe('Test video imports API validator', function () { | |||
37 | before(async function () { | 29 | before(async function () { |
38 | this.timeout(30000) | 30 | this.timeout(30000) |
39 | 31 | ||
40 | server = await flushAndRunServer(1) | 32 | server = await createSingleServer(1) |
41 | 33 | ||
42 | await setAccessTokensToServers([ server ]) | 34 | await setAccessTokensToServers([ server ]) |
43 | 35 | ||
44 | const username = 'user1' | 36 | const username = 'user1' |
45 | const password = 'my super password' | 37 | const password = 'my super password' |
46 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) | 38 | await server.users.create({ username: username, password: password }) |
47 | userAccessToken = await userLogin(server, { username, password }) | 39 | userAccessToken = await server.login.getAccessToken({ username, password }) |
48 | 40 | ||
49 | { | 41 | { |
50 | const res = await getMyUserInformation(server.url, server.accessToken) | 42 | const { videoChannels } = await server.users.getMyInfo() |
51 | channelId = res.body.videoChannels[0].id | 43 | channelId = videoChannels[0].id |
52 | } | 44 | } |
53 | }) | 45 | }) |
54 | 46 | ||
@@ -68,7 +60,7 @@ describe('Test video imports API validator', function () { | |||
68 | }) | 60 | }) |
69 | 61 | ||
70 | it('Should success with the correct parameters', async function () { | 62 | it('Should success with the correct parameters', async function () { |
71 | await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken }) | 63 | await makeGetRequest({ url: server.url, path: myPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken }) |
72 | }) | 64 | }) |
73 | }) | 65 | }) |
74 | 66 | ||
@@ -77,7 +69,7 @@ describe('Test video imports API validator', function () { | |||
77 | 69 | ||
78 | before(function () { | 70 | before(function () { |
79 | baseCorrectParams = { | 71 | baseCorrectParams = { |
80 | targetUrl: getGoodVideoUrl(), | 72 | targetUrl: FIXTURE_URLS.goodVideo, |
81 | name: 'my super name', | 73 | name: 'my super name', |
82 | category: 5, | 74 | category: 5, |
83 | licence: 1, | 75 | licence: 1, |
@@ -106,48 +98,48 @@ describe('Test video imports API validator', function () { | |||
106 | path, | 98 | path, |
107 | token: server.accessToken, | 99 | token: server.accessToken, |
108 | fields, | 100 | fields, |
109 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | 101 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
110 | }) | 102 | }) |
111 | }) | 103 | }) |
112 | 104 | ||
113 | it('Should fail with a bad target url', async function () { | 105 | it('Should fail with a bad target url', async function () { |
114 | const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' }) | 106 | const fields = { ...baseCorrectParams, targetUrl: 'htt://hello' } |
115 | 107 | ||
116 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 108 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
117 | }) | 109 | }) |
118 | 110 | ||
119 | it('Should fail with a long name', async function () { | 111 | it('Should fail with a long name', async function () { |
120 | const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) | 112 | const fields = { ...baseCorrectParams, name: 'super'.repeat(65) } |
121 | 113 | ||
122 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 114 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
123 | }) | 115 | }) |
124 | 116 | ||
125 | it('Should fail with a bad category', async function () { | 117 | it('Should fail with a bad category', async function () { |
126 | const fields = immutableAssign(baseCorrectParams, { category: 125 }) | 118 | const fields = { ...baseCorrectParams, category: 125 } |
127 | 119 | ||
128 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 120 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
129 | }) | 121 | }) |
130 | 122 | ||
131 | it('Should fail with a bad licence', async function () { | 123 | it('Should fail with a bad licence', async function () { |
132 | const fields = immutableAssign(baseCorrectParams, { licence: 125 }) | 124 | const fields = { ...baseCorrectParams, licence: 125 } |
133 | 125 | ||
134 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 126 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
135 | }) | 127 | }) |
136 | 128 | ||
137 | it('Should fail with a bad language', async function () { | 129 | it('Should fail with a bad language', async function () { |
138 | const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) | 130 | const fields = { ...baseCorrectParams, language: 'a'.repeat(15) } |
139 | 131 | ||
140 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 132 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
141 | }) | 133 | }) |
142 | 134 | ||
143 | it('Should fail with a long description', async function () { | 135 | it('Should fail with a long description', async function () { |
144 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) | 136 | const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) } |
145 | 137 | ||
146 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 138 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
147 | }) | 139 | }) |
148 | 140 | ||
149 | it('Should fail with a long support text', async function () { | 141 | it('Should fail with a long support text', async function () { |
150 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) | 142 | const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } |
151 | 143 | ||
152 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 144 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
153 | }) | 145 | }) |
@@ -159,7 +151,7 @@ describe('Test video imports API validator', function () { | |||
159 | }) | 151 | }) |
160 | 152 | ||
161 | it('Should fail with a bad channel', async function () { | 153 | it('Should fail with a bad channel', async function () { |
162 | const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) | 154 | const fields = { ...baseCorrectParams, channelId: 545454 } |
163 | 155 | ||
164 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 156 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
165 | }) | 157 | }) |
@@ -169,31 +161,31 @@ describe('Test video imports API validator', function () { | |||
169 | username: 'fake', | 161 | username: 'fake', |
170 | password: 'fake_password' | 162 | password: 'fake_password' |
171 | } | 163 | } |
172 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | 164 | await server.users.create({ username: user.username, password: user.password }) |
173 | 165 | ||
174 | const accessTokenUser = await userLogin(server, user) | 166 | const accessTokenUser = await server.login.getAccessToken(user) |
175 | const res = await getMyUserInformation(server.url, accessTokenUser) | 167 | const { videoChannels } = await server.users.getMyInfo({ token: accessTokenUser }) |
176 | const customChannelId = res.body.videoChannels[0].id | 168 | const customChannelId = videoChannels[0].id |
177 | 169 | ||
178 | const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) | 170 | const fields = { ...baseCorrectParams, channelId: customChannelId } |
179 | 171 | ||
180 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) | 172 | await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) |
181 | }) | 173 | }) |
182 | 174 | ||
183 | it('Should fail with too many tags', async function () { | 175 | it('Should fail with too many tags', async function () { |
184 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) | 176 | const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] } |
185 | 177 | ||
186 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 178 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
187 | }) | 179 | }) |
188 | 180 | ||
189 | it('Should fail with a tag length too low', async function () { | 181 | it('Should fail with a tag length too low', async function () { |
190 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) | 182 | const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] } |
191 | 183 | ||
192 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 184 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
193 | }) | 185 | }) |
194 | 186 | ||
195 | it('Should fail with a tag length too big', async function () { | 187 | it('Should fail with a tag length too big', async function () { |
196 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) | 188 | const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] } |
197 | 189 | ||
198 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 190 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
199 | }) | 191 | }) |
@@ -245,7 +237,7 @@ describe('Test video imports API validator', function () { | |||
245 | 237 | ||
246 | it('Should fail with an invalid magnet URI', async function () { | 238 | it('Should fail with an invalid magnet URI', async function () { |
247 | let fields = omit(baseCorrectParams, 'targetUrl') | 239 | let fields = omit(baseCorrectParams, 'targetUrl') |
248 | fields = immutableAssign(fields, { magnetUri: 'blabla' }) | 240 | fields = { ...fields, magnetUri: 'blabla' } |
249 | 241 | ||
250 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 242 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
251 | }) | 243 | }) |
@@ -258,19 +250,21 @@ describe('Test video imports API validator', function () { | |||
258 | path, | 250 | path, |
259 | token: server.accessToken, | 251 | token: server.accessToken, |
260 | fields: baseCorrectParams, | 252 | fields: baseCorrectParams, |
261 | statusCodeExpected: HttpStatusCode.OK_200 | 253 | expectedStatus: HttpStatusCode.OK_200 |
262 | }) | 254 | }) |
263 | }) | 255 | }) |
264 | 256 | ||
265 | it('Should forbid to import http videos', async function () { | 257 | it('Should forbid to import http videos', async function () { |
266 | await updateCustomSubConfig(server.url, server.accessToken, { | 258 | await server.config.updateCustomSubConfig({ |
267 | import: { | 259 | newConfig: { |
268 | videos: { | 260 | import: { |
269 | http: { | 261 | videos: { |
270 | enabled: false | 262 | http: { |
271 | }, | 263 | enabled: false |
272 | torrent: { | 264 | }, |
273 | enabled: true | 265 | torrent: { |
266 | enabled: true | ||
267 | } | ||
274 | } | 268 | } |
275 | } | 269 | } |
276 | } | 270 | } |
@@ -281,33 +275,35 @@ describe('Test video imports API validator', function () { | |||
281 | path, | 275 | path, |
282 | token: server.accessToken, | 276 | token: server.accessToken, |
283 | fields: baseCorrectParams, | 277 | fields: baseCorrectParams, |
284 | statusCodeExpected: HttpStatusCode.CONFLICT_409 | 278 | expectedStatus: HttpStatusCode.CONFLICT_409 |
285 | }) | 279 | }) |
286 | }) | 280 | }) |
287 | 281 | ||
288 | it('Should forbid to import torrent videos', async function () { | 282 | it('Should forbid to import torrent videos', async function () { |
289 | await updateCustomSubConfig(server.url, server.accessToken, { | 283 | await server.config.updateCustomSubConfig({ |
290 | import: { | 284 | newConfig: { |
291 | videos: { | 285 | import: { |
292 | http: { | 286 | videos: { |
293 | enabled: true | 287 | http: { |
294 | }, | 288 | enabled: true |
295 | torrent: { | 289 | }, |
296 | enabled: false | 290 | torrent: { |
291 | enabled: false | ||
292 | } | ||
297 | } | 293 | } |
298 | } | 294 | } |
299 | } | 295 | } |
300 | }) | 296 | }) |
301 | 297 | ||
302 | let fields = omit(baseCorrectParams, 'targetUrl') | 298 | let fields = omit(baseCorrectParams, 'targetUrl') |
303 | fields = immutableAssign(fields, { magnetUri: getMagnetURI() }) | 299 | fields = { ...fields, magnetUri: FIXTURE_URLS.magnet } |
304 | 300 | ||
305 | await makePostBodyRequest({ | 301 | await makePostBodyRequest({ |
306 | url: server.url, | 302 | url: server.url, |
307 | path, | 303 | path, |
308 | token: server.accessToken, | 304 | token: server.accessToken, |
309 | fields, | 305 | fields, |
310 | statusCodeExpected: HttpStatusCode.CONFLICT_409 | 306 | expectedStatus: HttpStatusCode.CONFLICT_409 |
311 | }) | 307 | }) |
312 | 308 | ||
313 | fields = omit(fields, 'magnetUri') | 309 | fields = omit(fields, 'magnetUri') |
@@ -321,7 +317,7 @@ describe('Test video imports API validator', function () { | |||
321 | token: server.accessToken, | 317 | token: server.accessToken, |
322 | fields, | 318 | fields, |
323 | attaches, | 319 | attaches, |
324 | statusCodeExpected: HttpStatusCode.CONFLICT_409 | 320 | expectedStatus: HttpStatusCode.CONFLICT_409 |
325 | }) | 321 | }) |
326 | }) | 322 | }) |
327 | }) | 323 | }) |