]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/config.ts
add quarantine videos feature (#1637)
[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 }
92
93 // ---------------------------------------------------------------
94
95 before(async function () {
96 this.timeout(30000)
97
98 await flushTests()
99 server = await runServer(1)
100
101 await setAccessTokensToServers([ server ])
102
103 const user = {
104 username: 'user1',
105 password: 'password'
106 }
107 await createUser(server.url, server.accessToken, user.username, user.password)
108 userAccessToken = await userLogin(server, user)
109 })
110
111 describe('When getting the configuration', function () {
112 it('Should fail without token', async function () {
113 await makeGetRequest({
114 url: server.url,
115 path,
116 statusCodeExpected: 401
117 })
118 })
119
120 it('Should fail if the user is not an administrator', async function () {
121 await makeGetRequest({
122 url: server.url,
123 path,
124 token: userAccessToken,
125 statusCodeExpected: 403
126 })
127 })
128 })
129
130 describe('When updating the configuration', function () {
131 it('Should fail without token', async function () {
132 await makePutBodyRequest({
133 url: server.url,
134 path,
135 fields: updateParams,
136 statusCodeExpected: 401
137 })
138 })
139
140 it('Should fail if the user is not an administrator', async function () {
141 await makePutBodyRequest({
142 url: server.url,
143 path,
144 fields: updateParams,
145 token: userAccessToken,
146 statusCodeExpected: 403
147 })
148 })
149
150 it('Should fail if it misses a key', async function () {
151 const newUpdateParams = omit(updateParams, 'admin.email')
152
153 await makePutBodyRequest({
154 url: server.url,
155 path,
156 fields: newUpdateParams,
157 token: server.accessToken,
158 statusCodeExpected: 400
159 })
160 })
161
162 it('Should fail with a bad default NSFW policy', async function () {
163 const newUpdateParams = immutableAssign(updateParams, {
164 instance: {
165 defaultNSFWPolicy: 'hello'
166 }
167 })
168
169 await makePutBodyRequest({
170 url: server.url,
171 path,
172 fields: newUpdateParams,
173 token: server.accessToken,
174 statusCodeExpected: 400
175 })
176 })
177
178 it('Should fail if email disabled and signup requires email verification', async function () {
179 // opposite scenario - succcess when enable enabled - covered via tests/api/users/user-verification.ts
180 const newUpdateParams = immutableAssign(updateParams, {
181 signup: {
182 enabled: true,
183 limit: 5,
184 requiresEmailVerification: true
185 }
186 })
187
188 await makePutBodyRequest({
189 url: server.url,
190 path,
191 fields: newUpdateParams,
192 token: server.accessToken,
193 statusCodeExpected: 400
194 })
195 })
196
197 it('Should success with the correct parameters', async function () {
198 await makePutBodyRequest({
199 url: server.url,
200 path,
201 fields: updateParams,
202 token: server.accessToken,
203 statusCodeExpected: 200
204 })
205 })
206 })
207
208 describe('When deleting the configuration', function () {
209 it('Should fail without token', async function () {
210 await makeDeleteRequest({
211 url: server.url,
212 path,
213 statusCodeExpected: 401
214 })
215 })
216
217 it('Should fail if the user is not an administrator', async function () {
218 await makeDeleteRequest({
219 url: server.url,
220 path,
221 token: userAccessToken,
222 statusCodeExpected: 403
223 })
224 })
225 })
226
227 after(async function () {
228 killallServers([ server ])
229
230 // Keep the logs if the test failed
231 if (this['ok']) {
232 await flushTests()
233 }
234 })
235 })