]>
Commit | Line | Data |
---|---|---|
fd206f0b C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import { omit } from 'lodash' | |
4 | import 'mocha' | |
09cababd | 5 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' |
fd206f0b C |
6 | |
7 | import { | |
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 | |
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 = { | |
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, |
536598cf | 62 | allowAudioFiles: true, |
fd206f0b C |
63 | threads: 1, |
64 | resolutions: { | |
65 | '240p': false, | |
66 | '360p': true, | |
67 | '480p': true, | |
68 | '720p': false, | |
69 | '1080p': false | |
09209296 C |
70 | }, |
71 | hls: { | |
72 | enabled: false | |
fd206f0b | 73 | } |
5d08a6a7 C |
74 | }, |
75 | import: { | |
76 | videos: { | |
77 | http: { | |
78 | enabled: false | |
a84b8fa5 C |
79 | }, |
80 | torrent: { | |
81 | enabled: false | |
5d08a6a7 C |
82 | } |
83 | } | |
7ccddd7b JM |
84 | }, |
85 | autoBlacklist: { | |
86 | videos: { | |
87 | ofUsers: { | |
88 | enabled: false | |
89 | } | |
90 | } | |
5b9c965d C |
91 | }, |
92 | followers: { | |
93 | instance: { | |
14893eb7 C |
94 | enabled: false, |
95 | manualApproval: true | |
5b9c965d | 96 | } |
fd206f0b C |
97 | } |
98 | } | |
99 | ||
100 | // --------------------------------------------------------------- | |
101 | ||
102 | before(async function () { | |
e212f887 | 103 | this.timeout(30000) |
fd206f0b | 104 | |
210feb6c | 105 | server = await flushAndRunServer(1) |
fd206f0b C |
106 | |
107 | await setAccessTokensToServers([ server ]) | |
108 | ||
109 | const user = { | |
110 | username: 'user1', | |
111 | password: 'password' | |
112 | } | |
1eddc9a7 | 113 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
fd206f0b C |
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, | |
0883b324 C |
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, | |
576ad67a JM |
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 () { | |
7c3b7976 | 185 | // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts |
576ad67a JM |
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, | |
fd206f0b C |
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 | ||
7c3b7976 C |
233 | after(async function () { |
234 | await cleanupTests([ server ]) | |
fd206f0b C |
235 | }) |
236 | }) |