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