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