]>
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, | |
db714ab4 C |
69 | '1080p': false, |
70 | '2160p': false | |
09209296 C |
71 | }, |
72 | hls: { | |
73 | enabled: false | |
fd206f0b | 74 | } |
5d08a6a7 C |
75 | }, |
76 | import: { | |
77 | videos: { | |
78 | http: { | |
79 | enabled: false | |
a84b8fa5 C |
80 | }, |
81 | torrent: { | |
82 | enabled: false | |
5d08a6a7 C |
83 | } |
84 | } | |
7ccddd7b JM |
85 | }, |
86 | autoBlacklist: { | |
87 | videos: { | |
88 | ofUsers: { | |
89 | enabled: false | |
90 | } | |
91 | } | |
5b9c965d C |
92 | }, |
93 | followers: { | |
94 | instance: { | |
14893eb7 C |
95 | enabled: false, |
96 | manualApproval: true | |
5b9c965d | 97 | } |
fd206f0b C |
98 | } |
99 | } | |
100 | ||
101 | // --------------------------------------------------------------- | |
102 | ||
103 | before(async function () { | |
e212f887 | 104 | this.timeout(30000) |
fd206f0b | 105 | |
210feb6c | 106 | server = await flushAndRunServer(1) |
fd206f0b C |
107 | |
108 | await setAccessTokensToServers([ server ]) | |
109 | ||
110 | const user = { | |
111 | username: 'user1', | |
112 | password: 'password' | |
113 | } | |
1eddc9a7 | 114 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
fd206f0b C |
115 | userAccessToken = await userLogin(server, user) |
116 | }) | |
117 | ||
118 | describe('When getting the configuration', function () { | |
119 | it('Should fail without token', async function () { | |
120 | await makeGetRequest({ | |
121 | url: server.url, | |
122 | path, | |
123 | statusCodeExpected: 401 | |
124 | }) | |
125 | }) | |
126 | ||
127 | it('Should fail if the user is not an administrator', async function () { | |
128 | await makeGetRequest({ | |
129 | url: server.url, | |
130 | path, | |
131 | token: userAccessToken, | |
132 | statusCodeExpected: 403 | |
133 | }) | |
134 | }) | |
135 | }) | |
136 | ||
137 | describe('When updating the configuration', function () { | |
138 | it('Should fail without token', async function () { | |
139 | await makePutBodyRequest({ | |
140 | url: server.url, | |
141 | path, | |
142 | fields: updateParams, | |
143 | statusCodeExpected: 401 | |
144 | }) | |
145 | }) | |
146 | ||
147 | it('Should fail if the user is not an administrator', async function () { | |
148 | await makePutBodyRequest({ | |
149 | url: server.url, | |
150 | path, | |
151 | fields: updateParams, | |
152 | token: userAccessToken, | |
153 | statusCodeExpected: 403 | |
154 | }) | |
155 | }) | |
156 | ||
157 | it('Should fail if it misses a key', async function () { | |
158 | const newUpdateParams = omit(updateParams, 'admin.email') | |
159 | ||
160 | await makePutBodyRequest({ | |
161 | url: server.url, | |
162 | path, | |
0883b324 C |
163 | fields: newUpdateParams, |
164 | token: server.accessToken, | |
165 | statusCodeExpected: 400 | |
166 | }) | |
167 | }) | |
168 | ||
169 | it('Should fail with a bad default NSFW policy', async function () { | |
170 | const newUpdateParams = immutableAssign(updateParams, { | |
171 | instance: { | |
172 | defaultNSFWPolicy: 'hello' | |
173 | } | |
174 | }) | |
175 | ||
176 | await makePutBodyRequest({ | |
177 | url: server.url, | |
178 | path, | |
576ad67a JM |
179 | fields: newUpdateParams, |
180 | token: server.accessToken, | |
181 | statusCodeExpected: 400 | |
182 | }) | |
183 | }) | |
184 | ||
185 | it('Should fail if email disabled and signup requires email verification', async function () { | |
7c3b7976 | 186 | // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts |
576ad67a JM |
187 | const newUpdateParams = immutableAssign(updateParams, { |
188 | signup: { | |
189 | enabled: true, | |
190 | limit: 5, | |
191 | requiresEmailVerification: true | |
192 | } | |
193 | }) | |
194 | ||
195 | await makePutBodyRequest({ | |
196 | url: server.url, | |
197 | path, | |
fd206f0b C |
198 | fields: newUpdateParams, |
199 | token: server.accessToken, | |
200 | statusCodeExpected: 400 | |
201 | }) | |
202 | }) | |
203 | ||
204 | it('Should success with the correct parameters', async function () { | |
205 | await makePutBodyRequest({ | |
206 | url: server.url, | |
207 | path, | |
208 | fields: updateParams, | |
209 | token: server.accessToken, | |
210 | statusCodeExpected: 200 | |
211 | }) | |
212 | }) | |
213 | }) | |
214 | ||
215 | describe('When deleting the configuration', function () { | |
216 | it('Should fail without token', async function () { | |
217 | await makeDeleteRequest({ | |
218 | url: server.url, | |
219 | path, | |
220 | statusCodeExpected: 401 | |
221 | }) | |
222 | }) | |
223 | ||
224 | it('Should fail if the user is not an administrator', async function () { | |
225 | await makeDeleteRequest({ | |
226 | url: server.url, | |
227 | path, | |
228 | token: userAccessToken, | |
229 | statusCodeExpected: 403 | |
230 | }) | |
231 | }) | |
232 | }) | |
233 | ||
7c3b7976 C |
234 | after(async function () { |
235 | await cleanupTests([ server ]) | |
fd206f0b C |
236 | }) |
237 | }) |