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