]>
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 | }, | |
53 | transcoding: { | |
54 | enabled: true, | |
55 | threads: 1, | |
56 | resolutions: { | |
57 | '240p': false, | |
58 | '360p': true, | |
59 | '480p': true, | |
60 | '720p': false, | |
61 | '1080p': false | |
62 | } | |
63 | }, | |
64 | import: { | |
65 | videos: { | |
66 | http: { | |
67 | enabled: false | |
68 | }, | |
69 | torrent: { | |
70 | enabled: false | |
71 | } | |
72 | } | |
73 | } | |
74 | } | |
75 | ||
76 | // --------------------------------------------------------------- | |
77 | ||
78 | before(async function () { | |
79 | this.timeout(30000) | |
80 | ||
81 | await flushTests() | |
82 | server = await runServer(1) | |
83 | ||
84 | await setAccessTokensToServers([ server ]) | |
85 | ||
86 | const user = { | |
87 | username: 'user1', | |
88 | password: 'password' | |
89 | } | |
90 | await createUser(server.url, server.accessToken, user.username, user.password) | |
91 | userAccessToken = await userLogin(server, user) | |
92 | }) | |
93 | ||
94 | describe('When getting the configuration', function () { | |
95 | it('Should fail without token', async function () { | |
96 | await makeGetRequest({ | |
97 | url: server.url, | |
98 | path, | |
99 | statusCodeExpected: 401 | |
100 | }) | |
101 | }) | |
102 | ||
103 | it('Should fail if the user is not an administrator', async function () { | |
104 | await makeGetRequest({ | |
105 | url: server.url, | |
106 | path, | |
107 | token: userAccessToken, | |
108 | statusCodeExpected: 403 | |
109 | }) | |
110 | }) | |
111 | }) | |
112 | ||
113 | describe('When updating the configuration', function () { | |
114 | it('Should fail without token', async function () { | |
115 | await makePutBodyRequest({ | |
116 | url: server.url, | |
117 | path, | |
118 | fields: updateParams, | |
119 | statusCodeExpected: 401 | |
120 | }) | |
121 | }) | |
122 | ||
123 | it('Should fail if the user is not an administrator', async function () { | |
124 | await makePutBodyRequest({ | |
125 | url: server.url, | |
126 | path, | |
127 | fields: updateParams, | |
128 | token: userAccessToken, | |
129 | statusCodeExpected: 403 | |
130 | }) | |
131 | }) | |
132 | ||
133 | it('Should fail if it misses a key', async function () { | |
134 | const newUpdateParams = omit(updateParams, 'admin.email') | |
135 | ||
136 | await makePutBodyRequest({ | |
137 | url: server.url, | |
138 | path, | |
139 | fields: newUpdateParams, | |
140 | token: server.accessToken, | |
141 | statusCodeExpected: 400 | |
142 | }) | |
143 | }) | |
144 | ||
145 | it('Should fail with a bad default NSFW policy', async function () { | |
146 | const newUpdateParams = immutableAssign(updateParams, { | |
147 | instance: { | |
148 | defaultNSFWPolicy: 'hello' | |
149 | } | |
150 | }) | |
151 | ||
152 | await makePutBodyRequest({ | |
153 | url: server.url, | |
154 | path, | |
155 | fields: newUpdateParams, | |
156 | token: server.accessToken, | |
157 | statusCodeExpected: 400 | |
158 | }) | |
159 | }) | |
160 | ||
161 | it('Should success with the correct parameters', async function () { | |
162 | await makePutBodyRequest({ | |
163 | url: server.url, | |
164 | path, | |
165 | fields: updateParams, | |
166 | token: server.accessToken, | |
167 | statusCodeExpected: 200 | |
168 | }) | |
169 | }) | |
170 | }) | |
171 | ||
172 | describe('When deleting the configuration', function () { | |
173 | it('Should fail without token', async function () { | |
174 | await makeDeleteRequest({ | |
175 | url: server.url, | |
176 | path, | |
177 | statusCodeExpected: 401 | |
178 | }) | |
179 | }) | |
180 | ||
181 | it('Should fail if the user is not an administrator', async function () { | |
182 | await makeDeleteRequest({ | |
183 | url: server.url, | |
184 | path, | |
185 | token: userAccessToken, | |
186 | statusCodeExpected: 403 | |
187 | }) | |
188 | }) | |
189 | }) | |
190 | ||
191 | after(async function () { | |
192 | killallServers([ server ]) | |
193 | ||
194 | // Keep the logs if the test failed | |
195 | if (this['ok']) { | |
196 | await flushTests() | |
197 | } | |
198 | }) | |
199 | }) |