]>
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 { | |
8 | createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo, | |
0883b324 | 9 | setAccessTokensToServers, userLogin, immutableAssign |
9639bd17 | 10 | } from '../../../../shared/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, |
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 | } | |
7ccddd7b JM |
83 | }, |
84 | autoBlacklist: { | |
85 | videos: { | |
86 | ofUsers: { | |
87 | enabled: false | |
88 | } | |
89 | } | |
fd206f0b C |
90 | } |
91 | } | |
92 | ||
93 | // --------------------------------------------------------------- | |
94 | ||
95 | before(async function () { | |
e212f887 | 96 | this.timeout(30000) |
fd206f0b C |
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, | |
0883b324 C |
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, | |
576ad67a JM |
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, | |
fd206f0b C |
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 | }) |