]>
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 |
fd206f0b C |
10 | } from '../../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 = { | |
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', |
901637bb | 22 | defaultClientRoute: '/videos/recently-added', |
0883b324 | 23 | defaultNSFWPolicy: 'blur', |
00b5556c C |
24 | customizations: { |
25 | javascript: 'alert("coucou")', | |
26 | css: 'body { background-color: red; }' | |
27 | } | |
66b16caf | 28 | }, |
8be1afa1 C |
29 | services: { |
30 | twitter: { | |
31 | username: '@MySuperUsername', | |
32 | whitelisted: true | |
33 | } | |
34 | }, | |
fd206f0b C |
35 | cache: { |
36 | previews: { | |
37 | size: 2 | |
40e87e9e C |
38 | }, |
39 | captions: { | |
40 | size: 3 | |
fd206f0b C |
41 | } |
42 | }, | |
43 | signup: { | |
44 | enabled: false, | |
d9eaee39 JM |
45 | limit: 5, |
46 | requiresEmailVerification: false | |
fd206f0b C |
47 | }, |
48 | admin: { | |
49 | email: 'superadmin1@example.com' | |
50 | }, | |
51 | user: { | |
bee0abff FA |
52 | videoQuota: 5242881, |
53 | videoQuotaDaily: 318742 | |
fd206f0b C |
54 | }, |
55 | transcoding: { | |
56 | enabled: true, | |
57 | threads: 1, | |
58 | resolutions: { | |
59 | '240p': false, | |
60 | '360p': true, | |
61 | '480p': true, | |
62 | '720p': false, | |
63 | '1080p': false | |
64 | } | |
5d08a6a7 C |
65 | }, |
66 | import: { | |
67 | videos: { | |
68 | http: { | |
69 | enabled: false | |
a84b8fa5 C |
70 | }, |
71 | torrent: { | |
72 | enabled: false | |
5d08a6a7 C |
73 | } |
74 | } | |
fd206f0b C |
75 | } |
76 | } | |
77 | ||
78 | // --------------------------------------------------------------- | |
79 | ||
80 | before(async function () { | |
e212f887 | 81 | this.timeout(30000) |
fd206f0b C |
82 | |
83 | await flushTests() | |
84 | server = await runServer(1) | |
85 | ||
86 | await setAccessTokensToServers([ server ]) | |
87 | ||
88 | const user = { | |
89 | username: 'user1', | |
90 | password: 'password' | |
91 | } | |
92 | await createUser(server.url, server.accessToken, user.username, user.password) | |
93 | userAccessToken = await userLogin(server, user) | |
94 | }) | |
95 | ||
96 | describe('When getting the configuration', function () { | |
97 | it('Should fail without token', async function () { | |
98 | await makeGetRequest({ | |
99 | url: server.url, | |
100 | path, | |
101 | statusCodeExpected: 401 | |
102 | }) | |
103 | }) | |
104 | ||
105 | it('Should fail if the user is not an administrator', async function () { | |
106 | await makeGetRequest({ | |
107 | url: server.url, | |
108 | path, | |
109 | token: userAccessToken, | |
110 | statusCodeExpected: 403 | |
111 | }) | |
112 | }) | |
113 | }) | |
114 | ||
115 | describe('When updating the configuration', function () { | |
116 | it('Should fail without token', async function () { | |
117 | await makePutBodyRequest({ | |
118 | url: server.url, | |
119 | path, | |
120 | fields: updateParams, | |
121 | statusCodeExpected: 401 | |
122 | }) | |
123 | }) | |
124 | ||
125 | it('Should fail if the user is not an administrator', async function () { | |
126 | await makePutBodyRequest({ | |
127 | url: server.url, | |
128 | path, | |
129 | fields: updateParams, | |
130 | token: userAccessToken, | |
131 | statusCodeExpected: 403 | |
132 | }) | |
133 | }) | |
134 | ||
135 | it('Should fail if it misses a key', async function () { | |
136 | const newUpdateParams = omit(updateParams, 'admin.email') | |
137 | ||
138 | await makePutBodyRequest({ | |
139 | url: server.url, | |
140 | path, | |
0883b324 C |
141 | fields: newUpdateParams, |
142 | token: server.accessToken, | |
143 | statusCodeExpected: 400 | |
144 | }) | |
145 | }) | |
146 | ||
147 | it('Should fail with a bad default NSFW policy', async function () { | |
148 | const newUpdateParams = immutableAssign(updateParams, { | |
149 | instance: { | |
150 | defaultNSFWPolicy: 'hello' | |
151 | } | |
152 | }) | |
153 | ||
154 | await makePutBodyRequest({ | |
155 | url: server.url, | |
156 | path, | |
fd206f0b C |
157 | fields: newUpdateParams, |
158 | token: server.accessToken, | |
159 | statusCodeExpected: 400 | |
160 | }) | |
161 | }) | |
162 | ||
163 | it('Should success with the correct parameters', async function () { | |
164 | await makePutBodyRequest({ | |
165 | url: server.url, | |
166 | path, | |
167 | fields: updateParams, | |
168 | token: server.accessToken, | |
169 | statusCodeExpected: 200 | |
170 | }) | |
171 | }) | |
172 | }) | |
173 | ||
174 | describe('When deleting the configuration', function () { | |
175 | it('Should fail without token', async function () { | |
176 | await makeDeleteRequest({ | |
177 | url: server.url, | |
178 | path, | |
179 | statusCodeExpected: 401 | |
180 | }) | |
181 | }) | |
182 | ||
183 | it('Should fail if the user is not an administrator', async function () { | |
184 | await makeDeleteRequest({ | |
185 | url: server.url, | |
186 | path, | |
187 | token: userAccessToken, | |
188 | statusCodeExpected: 403 | |
189 | }) | |
190 | }) | |
191 | }) | |
192 | ||
193 | after(async function () { | |
194 | killallServers([ server ]) | |
195 | ||
196 | // Keep the logs if the test failed | |
197 | if (this['ok']) { | |
198 | await flushTests() | |
199 | } | |
200 | }) | |
201 | }) |