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