aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/accounts.ts2
-rw-r--r--server/tests/api/check-params/config.ts3
-rw-r--r--server/tests/api/check-params/contact-form.ts4
-rw-r--r--server/tests/api/check-params/users.ts18
-rw-r--r--server/tests/api/check-params/video-abuses.ts6
-rw-r--r--server/tests/api/check-params/video-blacklist.ts118
-rw-r--r--server/tests/api/check-params/video-imports.ts1
-rw-r--r--server/tests/api/check-params/videos.ts2
8 files changed, 100 insertions, 54 deletions
diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.ts
index 567fd072c..68f9519c6 100644
--- a/server/tests/api/check-params/accounts.ts
+++ b/server/tests/api/check-params/accounts.ts
@@ -10,7 +10,7 @@ import {
10} from '../../../../shared/utils/requests/check-api-params' 10} from '../../../../shared/utils/requests/check-api-params'
11import { getAccount } from '../../../../shared/utils/users/accounts' 11import { getAccount } from '../../../../shared/utils/users/accounts'
12 12
13describe('Test users API validators', function () { 13describe('Test accounts API validators', function () {
14 const path = '/api/v1/accounts/' 14 const path = '/api/v1/accounts/'
15 let server: ServerInfo 15 let server: ServerInfo
16 16
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 4038ecbf0..07de2b5a5 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -65,6 +65,9 @@ describe('Test config API validators', function () {
65 '480p': true, 65 '480p': true,
66 '720p': false, 66 '720p': false,
67 '1080p': false 67 '1080p': false
68 },
69 hls: {
70 enabled: false
68 } 71 }
69 }, 72 },
70 import: { 73 import: {
diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts
index 2407ac0b5..c7e014b1f 100644
--- a/server/tests/api/check-params/contact-form.ts
+++ b/server/tests/api/check-params/contact-form.ts
@@ -46,6 +46,8 @@ describe('Test contact form API validators', function () {
46 }) 46 })
47 47
48 it('Should not accept a contact form if it is disabled in the configuration', async function () { 48 it('Should not accept a contact form if it is disabled in the configuration', async function () {
49 this.timeout(10000)
50
49 killallServers([ server ]) 51 killallServers([ server ])
50 52
51 // Contact form is disabled 53 // Contact form is disabled
@@ -54,6 +56,8 @@ describe('Test contact form API validators', function () {
54 }) 56 })
55 57
56 it('Should not accept a contact form if from email is invalid', async function () { 58 it('Should not accept a contact form if from email is invalid', async function () {
59 this.timeout(10000)
60
57 killallServers([ server ]) 61 killallServers([ server ])
58 62
59 // Email & contact form enabled 63 // Email & contact form enabled
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index a3e8e2e9c..13be8b460 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -464,6 +464,24 @@ describe('Test users API validators', function () {
464 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields }) 464 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
465 }) 465 })
466 466
467 it('Should fail with a too small password', async function () {
468 const fields = {
469 currentPassword: 'my super password',
470 password: 'bla'
471 }
472
473 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
474 })
475
476 it('Should fail with a too long password', async function () {
477 const fields = {
478 currentPassword: 'my super password',
479 password: 'super'.repeat(61)
480 }
481
482 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
483 })
484
467 it('Should fail with an non authenticated user', async function () { 485 it('Should fail with an non authenticated user', async function () {
468 const fields = { 486 const fields = {
469 videoQuota: 42 487 videoQuota: 42
diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts
index a79ab4201..3b8f5f14d 100644
--- a/server/tests/api/check-params/video-abuses.ts
+++ b/server/tests/api/check-params/video-abuses.ts
@@ -113,8 +113,8 @@ describe('Test video abuses API validators', function () {
113 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 113 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
114 }) 114 })
115 115
116 it('Should fail with a reason too big', async function () { 116 it('Should fail with a too big reason', async function () {
117 const fields = { reason: 'super'.repeat(61) } 117 const fields = { reason: 'super'.repeat(605) }
118 118
119 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 119 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
120 }) 120 })
@@ -154,7 +154,7 @@ describe('Test video abuses API validators', function () {
154 }) 154 })
155 155
156 it('Should fail with a bad moderation comment', async function () { 156 it('Should fail with a bad moderation comment', async function () {
157 const body = { moderationComment: 'b'.repeat(305) } 157 const body = { moderationComment: 'b'.repeat(3001) }
158 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400) 158 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
159 }) 159 })
160 160
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index 8e1206db3..6b82643f4 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -4,17 +4,20 @@ import 'mocha'
4 4
5import { 5import {
6 createUser, 6 createUser,
7 doubleFollow,
8 flushAndRunMultipleServers,
7 flushTests, 9 flushTests,
8 getBlacklistedVideosList, getVideo, getVideoWithToken, 10 getBlacklistedVideosList,
11 getVideo,
12 getVideoWithToken,
9 killallServers, 13 killallServers,
10 makePostBodyRequest, 14 makePostBodyRequest,
11 makePutBodyRequest, 15 makePutBodyRequest,
12 removeVideoFromBlacklist, 16 removeVideoFromBlacklist,
13 runServer,
14 ServerInfo, 17 ServerInfo,
15 setAccessTokensToServers, 18 setAccessTokensToServers,
16 uploadVideo, 19 uploadVideo,
17 userLogin 20 userLogin, waitJobs
18} from '../../../../shared/utils' 21} from '../../../../shared/utils'
19import { 22import {
20 checkBadCountPagination, 23 checkBadCountPagination,
@@ -25,8 +28,9 @@ import { VideoDetails } from '../../../../shared/models/videos'
25import { expect } from 'chai' 28import { expect } from 'chai'
26 29
27describe('Test video blacklist API validators', function () { 30describe('Test video blacklist API validators', function () {
28 let server: ServerInfo 31 let servers: ServerInfo[]
29 let notBlacklistedVideoId: number 32 let notBlacklistedVideoId: number
33 let remoteVideoUUID: string
30 let userAccessToken1 = '' 34 let userAccessToken1 = ''
31 let userAccessToken2 = '' 35 let userAccessToken2 = ''
32 36
@@ -36,75 +40,89 @@ describe('Test video blacklist API validators', function () {
36 this.timeout(120000) 40 this.timeout(120000)
37 41
38 await flushTests() 42 await flushTests()
43 servers = await flushAndRunMultipleServers(2)
39 44
40 server = await runServer(1) 45 await setAccessTokensToServers(servers)
41 46 await doubleFollow(servers[0], servers[1])
42 await setAccessTokensToServers([ server ])
43 47
44 { 48 {
45 const username = 'user1' 49 const username = 'user1'
46 const password = 'my super password' 50 const password = 'my super password'
47 await createUser(server.url, server.accessToken, username, password) 51 await createUser(servers[0].url, servers[0].accessToken, username, password)
48 userAccessToken1 = await userLogin(server, { username, password }) 52 userAccessToken1 = await userLogin(servers[0], { username, password })
49 } 53 }
50 54
51 { 55 {
52 const username = 'user2' 56 const username = 'user2'
53 const password = 'my super password' 57 const password = 'my super password'
54 await createUser(server.url, server.accessToken, username, password) 58 await createUser(servers[0].url, servers[0].accessToken, username, password)
55 userAccessToken2 = await userLogin(server, { username, password }) 59 userAccessToken2 = await userLogin(servers[0], { username, password })
56 } 60 }
57 61
58 { 62 {
59 const res = await uploadVideo(server.url, userAccessToken1, {}) 63 const res = await uploadVideo(servers[0].url, userAccessToken1, {})
60 server.video = res.body.video 64 servers[0].video = res.body.video
61 } 65 }
62 66
63 { 67 {
64 const res = await uploadVideo(server.url, server.accessToken, {}) 68 const res = await uploadVideo(servers[0].url, servers[0].accessToken, {})
65 notBlacklistedVideoId = res.body.video.uuid 69 notBlacklistedVideoId = res.body.video.uuid
66 } 70 }
71
72 {
73 const res = await uploadVideo(servers[1].url, servers[1].accessToken, {})
74 remoteVideoUUID = res.body.video.uuid
75 }
76
77 await waitJobs(servers)
67 }) 78 })
68 79
69 describe('When adding a video in blacklist', function () { 80 describe('When adding a video in blacklist', function () {
70 const basePath = '/api/v1/videos/' 81 const basePath = '/api/v1/videos/'
71 82
72 it('Should fail with nothing', async function () { 83 it('Should fail with nothing', async function () {
73 const path = basePath + server.video + '/blacklist' 84 const path = basePath + servers[0].video + '/blacklist'
74 const fields = {} 85 const fields = {}
75 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 86 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
76 }) 87 })
77 88
78 it('Should fail with a wrong video', async function () { 89 it('Should fail with a wrong video', async function () {
79 const wrongPath = '/api/v1/videos/blabla/blacklist' 90 const wrongPath = '/api/v1/videos/blabla/blacklist'
80 const fields = {} 91 const fields = {}
81 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) 92 await makePostBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
82 }) 93 })
83 94
84 it('Should fail with a non authenticated user', async function () { 95 it('Should fail with a non authenticated user', async function () {
85 const path = basePath + server.video + '/blacklist' 96 const path = basePath + servers[0].video + '/blacklist'
86 const fields = {} 97 const fields = {}
87 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) 98 await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
88 }) 99 })
89 100
90 it('Should fail with a non admin user', async function () { 101 it('Should fail with a non admin user', async function () {
91 const path = basePath + server.video + '/blacklist' 102 const path = basePath + servers[0].video + '/blacklist'
92 const fields = {} 103 const fields = {}
93 await makePostBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) 104 await makePostBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
94 }) 105 })
95 106
96 it('Should fail with an invalid reason', async function () { 107 it('Should fail with an invalid reason', async function () {
97 const path = basePath + server.video.uuid + '/blacklist' 108 const path = basePath + servers[0].video.uuid + '/blacklist'
98 const fields = { reason: 'a'.repeat(305) } 109 const fields = { reason: 'a'.repeat(305) }
99 110
100 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 111 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
112 })
113
114 it('Should fail to unfederate a remote video', async function () {
115 const path = basePath + remoteVideoUUID + '/blacklist'
116 const fields = { unfederate: true }
117
118 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 409 })
101 }) 119 })
102 120
103 it('Should succeed with the correct params', async function () { 121 it('Should succeed with the correct params', async function () {
104 const path = basePath + server.video.uuid + '/blacklist' 122 const path = basePath + servers[0].video.uuid + '/blacklist'
105 const fields = { } 123 const fields = { }
106 124
107 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) 125 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
108 }) 126 })
109 }) 127 })
110 128
@@ -114,61 +132,61 @@ describe('Test video blacklist API validators', function () {
114 it('Should fail with a wrong video', async function () { 132 it('Should fail with a wrong video', async function () {
115 const wrongPath = '/api/v1/videos/blabla/blacklist' 133 const wrongPath = '/api/v1/videos/blabla/blacklist'
116 const fields = {} 134 const fields = {}
117 await makePutBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields }) 135 await makePutBodyRequest({ url: servers[0].url, path: wrongPath, token: servers[0].accessToken, fields })
118 }) 136 })
119 137
120 it('Should fail with a video not blacklisted', async function () { 138 it('Should fail with a video not blacklisted', async function () {
121 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist' 139 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
122 const fields = {} 140 const fields = {}
123 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) 141 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 404 })
124 }) 142 })
125 143
126 it('Should fail with a non authenticated user', async function () { 144 it('Should fail with a non authenticated user', async function () {
127 const path = basePath + server.video + '/blacklist' 145 const path = basePath + servers[0].video + '/blacklist'
128 const fields = {} 146 const fields = {}
129 await makePutBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) 147 await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 })
130 }) 148 })
131 149
132 it('Should fail with a non admin user', async function () { 150 it('Should fail with a non admin user', async function () {
133 const path = basePath + server.video + '/blacklist' 151 const path = basePath + servers[0].video + '/blacklist'
134 const fields = {} 152 const fields = {}
135 await makePutBodyRequest({ url: server.url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) 153 await makePutBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 })
136 }) 154 })
137 155
138 it('Should fail with an invalid reason', async function () { 156 it('Should fail with an invalid reason', async function () {
139 const path = basePath + server.video.uuid + '/blacklist' 157 const path = basePath + servers[0].video.uuid + '/blacklist'
140 const fields = { reason: 'a'.repeat(305) } 158 const fields = { reason: 'a'.repeat(305) }
141 159
142 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 160 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
143 }) 161 })
144 162
145 it('Should succeed with the correct params', async function () { 163 it('Should succeed with the correct params', async function () {
146 const path = basePath + server.video.uuid + '/blacklist' 164 const path = basePath + servers[0].video.uuid + '/blacklist'
147 const fields = { reason: 'hello' } 165 const fields = { reason: 'hello' }
148 166
149 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) 167 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 })
150 }) 168 })
151 }) 169 })
152 170
153 describe('When getting blacklisted video', function () { 171 describe('When getting blacklisted video', function () {
154 172
155 it('Should fail with a non authenticated user', async function () { 173 it('Should fail with a non authenticated user', async function () {
156 await getVideo(server.url, server.video.uuid, 401) 174 await getVideo(servers[0].url, servers[0].video.uuid, 401)
157 }) 175 })
158 176
159 it('Should fail with another user', async function () { 177 it('Should fail with another user', async function () {
160 await getVideoWithToken(server.url, userAccessToken2, server.video.uuid, 403) 178 await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
161 }) 179 })
162 180
163 it('Should succeed with the owner authenticated user', async function () { 181 it('Should succeed with the owner authenticated user', async function () {
164 const res = await getVideoWithToken(server.url, userAccessToken1, server.video.uuid, 200) 182 const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, 200)
165 const video: VideoDetails = res.body 183 const video: VideoDetails = res.body
166 184
167 expect(video.blacklisted).to.be.true 185 expect(video.blacklisted).to.be.true
168 }) 186 })
169 187
170 it('Should succeed with an admin', async function () { 188 it('Should succeed with an admin', async function () {
171 const res = await getVideoWithToken(server.url, server.accessToken, server.video.uuid, 200) 189 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 200)
172 const video: VideoDetails = res.body 190 const video: VideoDetails = res.body
173 191
174 expect(video.blacklisted).to.be.true 192 expect(video.blacklisted).to.be.true
@@ -177,24 +195,24 @@ describe('Test video blacklist API validators', function () {
177 195
178 describe('When removing a video in blacklist', function () { 196 describe('When removing a video in blacklist', function () {
179 it('Should fail with a non authenticated user', async function () { 197 it('Should fail with a non authenticated user', async function () {
180 await removeVideoFromBlacklist(server.url, 'fake token', server.video.uuid, 401) 198 await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, 401)
181 }) 199 })
182 200
183 it('Should fail with a non admin user', async function () { 201 it('Should fail with a non admin user', async function () {
184 await removeVideoFromBlacklist(server.url, userAccessToken2, server.video.uuid, 403) 202 await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, 403)
185 }) 203 })
186 204
187 it('Should fail with an incorrect id', async function () { 205 it('Should fail with an incorrect id', async function () {
188 await removeVideoFromBlacklist(server.url, server.accessToken, 'hello', 400) 206 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', 400)
189 }) 207 })
190 208
191 it('Should fail with a not blacklisted video', async function () { 209 it('Should fail with a not blacklisted video', async function () {
192 // The video was not added to the blacklist so it should fail 210 // The video was not added to the blacklist so it should fail
193 await removeVideoFromBlacklist(server.url, server.accessToken, notBlacklistedVideoId, 404) 211 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, 404)
194 }) 212 })
195 213
196 it('Should succeed with the correct params', async function () { 214 it('Should succeed with the correct params', async function () {
197 await removeVideoFromBlacklist(server.url, server.accessToken, server.video.uuid, 204) 215 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 204)
198 }) 216 })
199 }) 217 })
200 218
@@ -202,28 +220,28 @@ describe('Test video blacklist API validators', function () {
202 const basePath = '/api/v1/videos/blacklist/' 220 const basePath = '/api/v1/videos/blacklist/'
203 221
204 it('Should fail with a non authenticated user', async function () { 222 it('Should fail with a non authenticated user', async function () {
205 await getBlacklistedVideosList(server.url, 'fake token', 401) 223 await getBlacklistedVideosList(servers[0].url, 'fake token', 401)
206 }) 224 })
207 225
208 it('Should fail with a non admin user', async function () { 226 it('Should fail with a non admin user', async function () {
209 await getBlacklistedVideosList(server.url, userAccessToken2, 403) 227 await getBlacklistedVideosList(servers[0].url, userAccessToken2, 403)
210 }) 228 })
211 229
212 it('Should fail with a bad start pagination', async function () { 230 it('Should fail with a bad start pagination', async function () {
213 await checkBadStartPagination(server.url, basePath, server.accessToken) 231 await checkBadStartPagination(servers[0].url, basePath, servers[0].accessToken)
214 }) 232 })
215 233
216 it('Should fail with a bad count pagination', async function () { 234 it('Should fail with a bad count pagination', async function () {
217 await checkBadCountPagination(server.url, basePath, server.accessToken) 235 await checkBadCountPagination(servers[0].url, basePath, servers[0].accessToken)
218 }) 236 })
219 237
220 it('Should fail with an incorrect sort', async function () { 238 it('Should fail with an incorrect sort', async function () {
221 await checkBadSortPagination(server.url, basePath, server.accessToken) 239 await checkBadSortPagination(servers[0].url, basePath, servers[0].accessToken)
222 }) 240 })
223 }) 241 })
224 242
225 after(async function () { 243 after(async function () {
226 killallServers([ server ]) 244 killallServers(servers)
227 245
228 // Keep the logs if the test failed 246 // Keep the logs if the test failed
229 if (this['ok']) { 247 if (this['ok']) {
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
index 7bf187007..6dd9f15f7 100644
--- a/server/tests/api/check-params/video-imports.ts
+++ b/server/tests/api/check-params/video-imports.ts
@@ -88,6 +88,7 @@ describe('Test video imports API validator', function () {
88 language: 'pt', 88 language: 'pt',
89 nsfw: false, 89 nsfw: false,
90 commentsEnabled: true, 90 commentsEnabled: true,
91 downloadEnabled: true,
91 waitTranscoding: true, 92 waitTranscoding: true,
92 description: 'my super description', 93 description: 'my super description',
93 support: 'my super support text', 94 support: 'my super support text',
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index f26b91435..878ffe025 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -179,6 +179,7 @@ describe('Test videos API validator', function () {
179 language: 'pt', 179 language: 'pt',
180 nsfw: false, 180 nsfw: false,
181 commentsEnabled: true, 181 commentsEnabled: true,
182 downloadEnabled: true,
182 waitTranscoding: true, 183 waitTranscoding: true,
183 description: 'my super description', 184 description: 'my super description',
184 support: 'my super support text', 185 support: 'my super support text',
@@ -428,6 +429,7 @@ describe('Test videos API validator', function () {
428 language: 'pt', 429 language: 'pt',
429 nsfw: false, 430 nsfw: false,
430 commentsEnabled: false, 431 commentsEnabled: false,
432 downloadEnabled: false,
431 description: 'my super description', 433 description: 'my super description',
432 privacy: VideoPrivacy.PUBLIC, 434 privacy: VideoPrivacy.PUBLIC,
433 tags: [ 'tag1', 'tag2' ] 435 tags: [ 'tag1', 'tag2' ]