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