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