]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/config.ts
Better welcome modal
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / config.ts
CommitLineData
fd206f0b
C
1/* tslint:disable:no-unused-expression */
2
3import { omit } from 'lodash'
4import 'mocha'
09cababd 5import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
fd206f0b
C
6
7import {
8424c402
C
8 cleanupTests,
9 createUser,
10 flushAndRunServer,
11 immutableAssign,
12 makeDeleteRequest,
13 makeGetRequest,
14 makePutBodyRequest,
15 ServerInfo,
16 setAccessTokensToServers,
17 userLogin
94565d52 18} from '../../../../shared/extra-utils'
fd206f0b
C
19
20describe('Test config API validators', function () {
21 const path = '/api/v1/config/custom'
22 let server: ServerInfo
23 let userAccessToken: string
24 const updateParams: CustomConfig = {
66b16caf
C
25 instance: {
26 name: 'PeerTube updated',
2e3a0215 27 shortDescription: 'my short description',
66b16caf 28 description: 'my super description',
00b5556c 29 terms: 'my super terms',
ccc00cb2
C
30 codeOfConduct: 'my super coc',
31
8ae03c37 32 creationReason: 'my super reason',
ccc00cb2
C
33 moderationInformation: 'my super moderation information',
34 administrator: 'Kuja',
35 maintenanceLifetime: 'forever',
36 businessModel: 'my super business model',
37
38 languages: [ 'en', 'es' ],
39 categories: [ 1, 2 ],
40
f8802489 41 isNSFW: true,
901637bb 42 defaultClientRoute: '/videos/recently-added',
0883b324 43 defaultNSFWPolicy: 'blur',
00b5556c
C
44 customizations: {
45 javascript: 'alert("coucou")',
46 css: 'body { background-color: red; }'
47 }
66b16caf 48 },
7cd4d2ba
C
49 theme: {
50 default: 'default'
51 },
8be1afa1
C
52 services: {
53 twitter: {
54 username: '@MySuperUsername',
55 whitelisted: true
56 }
57 },
fd206f0b
C
58 cache: {
59 previews: {
60 size: 2
40e87e9e
C
61 },
62 captions: {
63 size: 3
fd206f0b
C
64 }
65 },
66 signup: {
67 enabled: false,
d9eaee39
JM
68 limit: 5,
69 requiresEmailVerification: false
fd206f0b
C
70 },
71 admin: {
72 email: 'superadmin1@example.com'
73 },
a4101923
C
74 contactForm: {
75 enabled: false
76 },
fd206f0b 77 user: {
bee0abff
FA
78 videoQuota: 5242881,
79 videoQuotaDaily: 318742
fd206f0b
C
80 },
81 transcoding: {
82 enabled: true,
14e2014a 83 allowAdditionalExtensions: true,
536598cf 84 allowAudioFiles: true,
fd206f0b
C
85 threads: 1,
86 resolutions: {
87 '240p': false,
88 '360p': true,
89 '480p': true,
90 '720p': false,
db714ab4
C
91 '1080p': false,
92 '2160p': false
09209296
C
93 },
94 hls: {
95 enabled: false
fd206f0b 96 }
5d08a6a7
C
97 },
98 import: {
99 videos: {
100 http: {
101 enabled: false
a84b8fa5
C
102 },
103 torrent: {
104 enabled: false
5d08a6a7
C
105 }
106 }
7ccddd7b
JM
107 },
108 autoBlacklist: {
109 videos: {
110 ofUsers: {
111 enabled: false
112 }
113 }
5b9c965d
C
114 },
115 followers: {
116 instance: {
14893eb7
C
117 enabled: false,
118 manualApproval: true
5b9c965d 119 }
8424c402
C
120 },
121 followings: {
122 instance: {
123 autoFollowBack: {
124 enabled: true
125 },
126 autoFollowIndex: {
127 enabled: true,
128 indexUrl: 'https://index.example.com'
129 }
130 }
fd206f0b
C
131 }
132 }
133
134 // ---------------------------------------------------------------
135
136 before(async function () {
e212f887 137 this.timeout(30000)
fd206f0b 138
210feb6c 139 server = await flushAndRunServer(1)
fd206f0b
C
140
141 await setAccessTokensToServers([ server ])
142
143 const user = {
144 username: 'user1',
145 password: 'password'
146 }
1eddc9a7 147 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
fd206f0b
C
148 userAccessToken = await userLogin(server, user)
149 })
150
151 describe('When getting the configuration', function () {
152 it('Should fail without token', async function () {
153 await makeGetRequest({
154 url: server.url,
155 path,
156 statusCodeExpected: 401
157 })
158 })
159
160 it('Should fail if the user is not an administrator', async function () {
161 await makeGetRequest({
162 url: server.url,
163 path,
164 token: userAccessToken,
165 statusCodeExpected: 403
166 })
167 })
168 })
169
170 describe('When updating the configuration', function () {
171 it('Should fail without token', async function () {
172 await makePutBodyRequest({
173 url: server.url,
174 path,
175 fields: updateParams,
176 statusCodeExpected: 401
177 })
178 })
179
180 it('Should fail if the user is not an administrator', async function () {
181 await makePutBodyRequest({
182 url: server.url,
183 path,
184 fields: updateParams,
185 token: userAccessToken,
186 statusCodeExpected: 403
187 })
188 })
189
190 it('Should fail if it misses a key', async function () {
191 const newUpdateParams = omit(updateParams, 'admin.email')
192
193 await makePutBodyRequest({
194 url: server.url,
195 path,
0883b324
C
196 fields: newUpdateParams,
197 token: server.accessToken,
198 statusCodeExpected: 400
199 })
200 })
201
202 it('Should fail with a bad default NSFW policy', async function () {
203 const newUpdateParams = immutableAssign(updateParams, {
204 instance: {
205 defaultNSFWPolicy: 'hello'
206 }
207 })
208
209 await makePutBodyRequest({
210 url: server.url,
211 path,
576ad67a
JM
212 fields: newUpdateParams,
213 token: server.accessToken,
214 statusCodeExpected: 400
215 })
216 })
217
218 it('Should fail if email disabled and signup requires email verification', async function () {
7c3b7976 219 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
576ad67a
JM
220 const newUpdateParams = immutableAssign(updateParams, {
221 signup: {
222 enabled: true,
223 limit: 5,
224 requiresEmailVerification: true
225 }
226 })
227
228 await makePutBodyRequest({
229 url: server.url,
230 path,
fd206f0b
C
231 fields: newUpdateParams,
232 token: server.accessToken,
233 statusCodeExpected: 400
234 })
235 })
236
237 it('Should success with the correct parameters', async function () {
238 await makePutBodyRequest({
239 url: server.url,
240 path,
241 fields: updateParams,
242 token: server.accessToken,
243 statusCodeExpected: 200
244 })
245 })
246 })
247
248 describe('When deleting the configuration', function () {
249 it('Should fail without token', async function () {
250 await makeDeleteRequest({
251 url: server.url,
252 path,
253 statusCodeExpected: 401
254 })
255 })
256
257 it('Should fail if the user is not an administrator', async function () {
258 await makeDeleteRequest({
259 url: server.url,
260 path,
261 token: userAccessToken,
262 statusCodeExpected: 403
263 })
264 })
265 })
266
7c3b7976
C
267 after(async function () {
268 await cleanupTests([ server ])
fd206f0b
C
269 })
270})