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