]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/config.ts
Add ability to manually approves instance followers in REST API
[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, runServer, ServerInfo,
9 setAccessTokensToServers, userLogin, immutableAssign
10 } from '../../../../shared/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 services: {
31 twitter: {
32 username: '@MySuperUsername',
33 whitelisted: true
34 }
35 },
36 cache: {
37 previews: {
38 size: 2
39 },
40 captions: {
41 size: 3
42 }
43 },
44 signup: {
45 enabled: false,
46 limit: 5,
47 requiresEmailVerification: false
48 },
49 admin: {
50 email: 'superadmin1@example.com'
51 },
52 contactForm: {
53 enabled: false
54 },
55 user: {
56 videoQuota: 5242881,
57 videoQuotaDaily: 318742
58 },
59 transcoding: {
60 enabled: true,
61 allowAdditionalExtensions: true,
62 threads: 1,
63 resolutions: {
64 '240p': false,
65 '360p': true,
66 '480p': true,
67 '720p': false,
68 '1080p': false
69 },
70 hls: {
71 enabled: false
72 }
73 },
74 import: {
75 videos: {
76 http: {
77 enabled: false
78 },
79 torrent: {
80 enabled: false
81 }
82 }
83 },
84 autoBlacklist: {
85 videos: {
86 ofUsers: {
87 enabled: false
88 }
89 }
90 },
91 followers: {
92 instance: {
93 enabled: false,
94 manualApproval: true
95 }
96 }
97 }
98
99 // ---------------------------------------------------------------
100
101 before(async function () {
102 this.timeout(30000)
103
104 await flushTests()
105 server = await runServer(1)
106
107 await setAccessTokensToServers([ server ])
108
109 const user = {
110 username: 'user1',
111 password: 'password'
112 }
113 await createUser(server.url, server.accessToken, user.username, user.password)
114 userAccessToken = await userLogin(server, user)
115 })
116
117 describe('When getting the configuration', function () {
118 it('Should fail without token', async function () {
119 await makeGetRequest({
120 url: server.url,
121 path,
122 statusCodeExpected: 401
123 })
124 })
125
126 it('Should fail if the user is not an administrator', async function () {
127 await makeGetRequest({
128 url: server.url,
129 path,
130 token: userAccessToken,
131 statusCodeExpected: 403
132 })
133 })
134 })
135
136 describe('When updating the configuration', function () {
137 it('Should fail without token', async function () {
138 await makePutBodyRequest({
139 url: server.url,
140 path,
141 fields: updateParams,
142 statusCodeExpected: 401
143 })
144 })
145
146 it('Should fail if the user is not an administrator', async function () {
147 await makePutBodyRequest({
148 url: server.url,
149 path,
150 fields: updateParams,
151 token: userAccessToken,
152 statusCodeExpected: 403
153 })
154 })
155
156 it('Should fail if it misses a key', async function () {
157 const newUpdateParams = omit(updateParams, 'admin.email')
158
159 await makePutBodyRequest({
160 url: server.url,
161 path,
162 fields: newUpdateParams,
163 token: server.accessToken,
164 statusCodeExpected: 400
165 })
166 })
167
168 it('Should fail with a bad default NSFW policy', async function () {
169 const newUpdateParams = immutableAssign(updateParams, {
170 instance: {
171 defaultNSFWPolicy: 'hello'
172 }
173 })
174
175 await makePutBodyRequest({
176 url: server.url,
177 path,
178 fields: newUpdateParams,
179 token: server.accessToken,
180 statusCodeExpected: 400
181 })
182 })
183
184 it('Should fail if email disabled and signup requires email verification', async function () {
185 // opposite scenario - succcess when enable enabled - covered via tests/api/users/user-verification.ts
186 const newUpdateParams = immutableAssign(updateParams, {
187 signup: {
188 enabled: true,
189 limit: 5,
190 requiresEmailVerification: true
191 }
192 })
193
194 await makePutBodyRequest({
195 url: server.url,
196 path,
197 fields: newUpdateParams,
198 token: server.accessToken,
199 statusCodeExpected: 400
200 })
201 })
202
203 it('Should success with the correct parameters', async function () {
204 await makePutBodyRequest({
205 url: server.url,
206 path,
207 fields: updateParams,
208 token: server.accessToken,
209 statusCodeExpected: 200
210 })
211 })
212 })
213
214 describe('When deleting the configuration', function () {
215 it('Should fail without token', async function () {
216 await makeDeleteRequest({
217 url: server.url,
218 path,
219 statusCodeExpected: 401
220 })
221 })
222
223 it('Should fail if the user is not an administrator', async function () {
224 await makeDeleteRequest({
225 url: server.url,
226 path,
227 token: userAccessToken,
228 statusCodeExpected: 403
229 })
230 })
231 })
232
233 after(async function () {
234 killallServers([ server ])
235
236 // Keep the logs if the test failed
237 if (this['ok']) {
238 await flushTests()
239 }
240 })
241 })