]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import { omit } from 'lodash' | |
4 | import 'mocha' | |
5 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' | |
6 | ||
7 | import { | |
8 | createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, flushAndRunServer, ServerInfo, | |
9 | setAccessTokensToServers, userLogin, immutableAssign, cleanupTests | |
10 | } from '../../../../shared/extra-utils' | |
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 = { | |
17 | instance: { | |
18 | name: 'PeerTube updated', | |
19 | shortDescription: 'my short description', | |
20 | description: 'my super description', | |
21 | terms: 'my super terms', | |
22 | isNSFW: true, | |
23 | defaultClientRoute: '/videos/recently-added', | |
24 | defaultNSFWPolicy: 'blur', | |
25 | customizations: { | |
26 | javascript: 'alert("coucou")', | |
27 | css: 'body { background-color: red; }' | |
28 | } | |
29 | }, | |
30 | services: { | |
31 | twitter: { | |
32 | username: '@MySuperUsername', | |
33 | whitelisted: true | |
34 | } | |
35 | }, | |
36 | cache: { | |
37 | previews: { | |
38 | size: 2 | |
39 | }, | |
40 | captions: { | |
41 | size: 3 | |
42 | } | |
43 | }, | |
44 | signup: { | |
45 | enabled: false, | |
46 | limit: 5, | |
47 | requiresEmailVerification: false | |
48 | }, | |
49 | admin: { | |
50 | email: 'superadmin1@example.com' | |
51 | }, | |
52 | contactForm: { | |
53 | enabled: false | |
54 | }, | |
55 | user: { | |
56 | videoQuota: 5242881, | |
57 | videoQuotaDaily: 318742 | |
58 | }, | |
59 | transcoding: { | |
60 | enabled: true, | |
61 | allowAdditionalExtensions: true, | |
62 | threads: 1, | |
63 | resolutions: { | |
64 | '240p': false, | |
65 | '360p': true, | |
66 | '480p': true, | |
67 | '720p': false, | |
68 | '1080p': false | |
69 | }, | |
70 | hls: { | |
71 | enabled: false | |
72 | } | |
73 | }, | |
74 | import: { | |
75 | videos: { | |
76 | http: { | |
77 | enabled: false | |
78 | }, | |
79 | torrent: { | |
80 | enabled: false | |
81 | } | |
82 | } | |
83 | }, | |
84 | autoBlacklist: { | |
85 | videos: { | |
86 | ofUsers: { | |
87 | enabled: false | |
88 | } | |
89 | } | |
90 | }, | |
91 | followers: { | |
92 | instance: { | |
93 | enabled: false, | |
94 | manualApproval: true | |
95 | } | |
96 | } | |
97 | } | |
98 | ||
99 | // --------------------------------------------------------------- | |
100 | ||
101 | before(async function () { | |
102 | this.timeout(30000) | |
103 | ||
104 | server = await flushAndRunServer(1) | |
105 | ||
106 | await setAccessTokensToServers([ server ]) | |
107 | ||
108 | const user = { | |
109 | username: 'user1', | |
110 | password: 'password' | |
111 | } | |
112 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | |
113 | userAccessToken = await userLogin(server, user) | |
114 | }) | |
115 | ||
116 | describe('When getting the configuration', function () { | |
117 | it('Should fail without token', async function () { | |
118 | await makeGetRequest({ | |
119 | url: server.url, | |
120 | path, | |
121 | statusCodeExpected: 401 | |
122 | }) | |
123 | }) | |
124 | ||
125 | it('Should fail if the user is not an administrator', async function () { | |
126 | await makeGetRequest({ | |
127 | url: server.url, | |
128 | path, | |
129 | token: userAccessToken, | |
130 | statusCodeExpected: 403 | |
131 | }) | |
132 | }) | |
133 | }) | |
134 | ||
135 | describe('When updating the configuration', function () { | |
136 | it('Should fail without token', async function () { | |
137 | await makePutBodyRequest({ | |
138 | url: server.url, | |
139 | path, | |
140 | fields: updateParams, | |
141 | statusCodeExpected: 401 | |
142 | }) | |
143 | }) | |
144 | ||
145 | it('Should fail if the user is not an administrator', async function () { | |
146 | await makePutBodyRequest({ | |
147 | url: server.url, | |
148 | path, | |
149 | fields: updateParams, | |
150 | token: userAccessToken, | |
151 | statusCodeExpected: 403 | |
152 | }) | |
153 | }) | |
154 | ||
155 | it('Should fail if it misses a key', async function () { | |
156 | const newUpdateParams = omit(updateParams, 'admin.email') | |
157 | ||
158 | await makePutBodyRequest({ | |
159 | url: server.url, | |
160 | path, | |
161 | fields: newUpdateParams, | |
162 | token: server.accessToken, | |
163 | statusCodeExpected: 400 | |
164 | }) | |
165 | }) | |
166 | ||
167 | it('Should fail with a bad default NSFW policy', async function () { | |
168 | const newUpdateParams = immutableAssign(updateParams, { | |
169 | instance: { | |
170 | defaultNSFWPolicy: 'hello' | |
171 | } | |
172 | }) | |
173 | ||
174 | await makePutBodyRequest({ | |
175 | url: server.url, | |
176 | path, | |
177 | fields: newUpdateParams, | |
178 | token: server.accessToken, | |
179 | statusCodeExpected: 400 | |
180 | }) | |
181 | }) | |
182 | ||
183 | it('Should fail if email disabled and signup requires email verification', async function () { | |
184 | // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts | |
185 | const newUpdateParams = immutableAssign(updateParams, { | |
186 | signup: { | |
187 | enabled: true, | |
188 | limit: 5, | |
189 | requiresEmailVerification: true | |
190 | } | |
191 | }) | |
192 | ||
193 | await makePutBodyRequest({ | |
194 | url: server.url, | |
195 | path, | |
196 | fields: newUpdateParams, | |
197 | token: server.accessToken, | |
198 | statusCodeExpected: 400 | |
199 | }) | |
200 | }) | |
201 | ||
202 | it('Should success with the correct parameters', async function () { | |
203 | await makePutBodyRequest({ | |
204 | url: server.url, | |
205 | path, | |
206 | fields: updateParams, | |
207 | token: server.accessToken, | |
208 | statusCodeExpected: 200 | |
209 | }) | |
210 | }) | |
211 | }) | |
212 | ||
213 | describe('When deleting the configuration', function () { | |
214 | it('Should fail without token', async function () { | |
215 | await makeDeleteRequest({ | |
216 | url: server.url, | |
217 | path, | |
218 | statusCodeExpected: 401 | |
219 | }) | |
220 | }) | |
221 | ||
222 | it('Should fail if the user is not an administrator', async function () { | |
223 | await makeDeleteRequest({ | |
224 | url: server.url, | |
225 | path, | |
226 | token: userAccessToken, | |
227 | statusCodeExpected: 403 | |
228 | }) | |
229 | }) | |
230 | }) | |
231 | ||
232 | after(async function () { | |
233 | await cleanupTests([ server ]) | |
234 | }) | |
235 | }) |