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