]>
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, | |
9 | setAccessTokensToServers, userLogin | |
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', | |
19 | description: 'my super description', | |
00b5556c C |
20 | terms: 'my super terms', |
21 | customizations: { | |
22 | javascript: 'alert("coucou")', | |
23 | css: 'body { background-color: red; }' | |
24 | } | |
66b16caf | 25 | }, |
fd206f0b C |
26 | cache: { |
27 | previews: { | |
28 | size: 2 | |
29 | } | |
30 | }, | |
31 | signup: { | |
32 | enabled: false, | |
33 | limit: 5 | |
34 | }, | |
35 | admin: { | |
36 | email: 'superadmin1@example.com' | |
37 | }, | |
38 | user: { | |
39 | videoQuota: 5242881 | |
40 | }, | |
41 | transcoding: { | |
42 | enabled: true, | |
43 | threads: 1, | |
44 | resolutions: { | |
45 | '240p': false, | |
46 | '360p': true, | |
47 | '480p': true, | |
48 | '720p': false, | |
49 | '1080p': false | |
50 | } | |
51 | } | |
52 | } | |
53 | ||
54 | // --------------------------------------------------------------- | |
55 | ||
56 | before(async function () { | |
e212f887 | 57 | this.timeout(30000) |
fd206f0b C |
58 | |
59 | await flushTests() | |
60 | server = await runServer(1) | |
61 | ||
62 | await setAccessTokensToServers([ server ]) | |
63 | ||
64 | const user = { | |
65 | username: 'user1', | |
66 | password: 'password' | |
67 | } | |
68 | await createUser(server.url, server.accessToken, user.username, user.password) | |
69 | userAccessToken = await userLogin(server, user) | |
70 | }) | |
71 | ||
72 | describe('When getting the configuration', function () { | |
73 | it('Should fail without token', async function () { | |
74 | await makeGetRequest({ | |
75 | url: server.url, | |
76 | path, | |
77 | statusCodeExpected: 401 | |
78 | }) | |
79 | }) | |
80 | ||
81 | it('Should fail if the user is not an administrator', async function () { | |
82 | await makeGetRequest({ | |
83 | url: server.url, | |
84 | path, | |
85 | token: userAccessToken, | |
86 | statusCodeExpected: 403 | |
87 | }) | |
88 | }) | |
89 | }) | |
90 | ||
91 | describe('When updating the configuration', function () { | |
92 | it('Should fail without token', async function () { | |
93 | await makePutBodyRequest({ | |
94 | url: server.url, | |
95 | path, | |
96 | fields: updateParams, | |
97 | statusCodeExpected: 401 | |
98 | }) | |
99 | }) | |
100 | ||
101 | it('Should fail if the user is not an administrator', async function () { | |
102 | await makePutBodyRequest({ | |
103 | url: server.url, | |
104 | path, | |
105 | fields: updateParams, | |
106 | token: userAccessToken, | |
107 | statusCodeExpected: 403 | |
108 | }) | |
109 | }) | |
110 | ||
111 | it('Should fail if it misses a key', async function () { | |
112 | const newUpdateParams = omit(updateParams, 'admin.email') | |
113 | ||
114 | await makePutBodyRequest({ | |
115 | url: server.url, | |
116 | path, | |
117 | fields: newUpdateParams, | |
118 | token: server.accessToken, | |
119 | statusCodeExpected: 400 | |
120 | }) | |
121 | }) | |
122 | ||
123 | it('Should success with the correct parameters', async function () { | |
124 | await makePutBodyRequest({ | |
125 | url: server.url, | |
126 | path, | |
127 | fields: updateParams, | |
128 | token: server.accessToken, | |
129 | statusCodeExpected: 200 | |
130 | }) | |
131 | }) | |
132 | }) | |
133 | ||
134 | describe('When deleting the configuration', function () { | |
135 | it('Should fail without token', async function () { | |
136 | await makeDeleteRequest({ | |
137 | url: server.url, | |
138 | path, | |
139 | statusCodeExpected: 401 | |
140 | }) | |
141 | }) | |
142 | ||
143 | it('Should fail if the user is not an administrator', async function () { | |
144 | await makeDeleteRequest({ | |
145 | url: server.url, | |
146 | path, | |
147 | token: userAccessToken, | |
148 | statusCodeExpected: 403 | |
149 | }) | |
150 | }) | |
151 | }) | |
152 | ||
153 | after(async function () { | |
154 | killallServers([ server ]) | |
155 | ||
156 | // Keep the logs if the test failed | |
157 | if (this['ok']) { | |
158 | await flushTests() | |
159 | } | |
160 | }) | |
161 | }) |