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