1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
14 setAccessTokensToServers,
16 } from '@shared/extra-utils'
17 import { CustomConfig } from '@shared/models'
19 const expect = chai.expect
21 function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
22 expect(data.instance.name).to.equal('PeerTube')
23 expect(data.instance.shortDescription).to.equal(
24 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
26 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
28 expect(data.instance.terms).to.equal('No terms for now.')
29 expect(data.instance.creationReason).to.be.empty
30 expect(data.instance.codeOfConduct).to.be.empty
31 expect(data.instance.moderationInformation).to.be.empty
32 expect(data.instance.administrator).to.be.empty
33 expect(data.instance.maintenanceLifetime).to.be.empty
34 expect(data.instance.businessModel).to.be.empty
35 expect(data.instance.hardwareInformation).to.be.empty
37 expect(data.instance.languages).to.have.lengthOf(0)
38 expect(data.instance.categories).to.have.lengthOf(0)
40 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
41 expect(data.instance.isNSFW).to.be.false
42 expect(data.instance.defaultNSFWPolicy).to.equal('display')
43 expect(data.instance.customizations.css).to.be.empty
44 expect(data.instance.customizations.javascript).to.be.empty
46 expect(data.services.twitter.username).to.equal('@Chocobozzz')
47 expect(data.services.twitter.whitelisted).to.be.false
49 expect(data.cache.previews.size).to.equal(1)
50 expect(data.cache.captions.size).to.equal(1)
51 expect(data.cache.torrents.size).to.equal(1)
53 expect(data.signup.enabled).to.be.true
54 expect(data.signup.limit).to.equal(4)
55 expect(data.signup.minimumAge).to.equal(16)
56 expect(data.signup.requiresEmailVerification).to.be.false
58 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
59 expect(data.contactForm.enabled).to.be.true
61 expect(data.user.videoQuota).to.equal(5242880)
62 expect(data.user.videoQuotaDaily).to.equal(-1)
64 expect(data.transcoding.enabled).to.be.false
65 expect(data.transcoding.allowAdditionalExtensions).to.be.false
66 expect(data.transcoding.allowAudioFiles).to.be.false
67 expect(data.transcoding.threads).to.equal(2)
68 expect(data.transcoding.concurrency).to.equal(2)
69 expect(data.transcoding.profile).to.equal('default')
70 expect(data.transcoding.resolutions['240p']).to.be.true
71 expect(data.transcoding.resolutions['360p']).to.be.true
72 expect(data.transcoding.resolutions['480p']).to.be.true
73 expect(data.transcoding.resolutions['720p']).to.be.true
74 expect(data.transcoding.resolutions['1080p']).to.be.true
75 expect(data.transcoding.resolutions['1440p']).to.be.true
76 expect(data.transcoding.resolutions['2160p']).to.be.true
77 expect(data.transcoding.webtorrent.enabled).to.be.true
78 expect(data.transcoding.hls.enabled).to.be.true
80 expect(data.live.enabled).to.be.false
81 expect(data.live.allowReplay).to.be.false
82 expect(data.live.maxDuration).to.equal(-1)
83 expect(data.live.maxInstanceLives).to.equal(20)
84 expect(data.live.maxUserLives).to.equal(3)
85 expect(data.live.transcoding.enabled).to.be.false
86 expect(data.live.transcoding.threads).to.equal(2)
87 expect(data.live.transcoding.profile).to.equal('default')
88 expect(data.live.transcoding.resolutions['240p']).to.be.false
89 expect(data.live.transcoding.resolutions['360p']).to.be.false
90 expect(data.live.transcoding.resolutions['480p']).to.be.false
91 expect(data.live.transcoding.resolutions['720p']).to.be.false
92 expect(data.live.transcoding.resolutions['1080p']).to.be.false
93 expect(data.live.transcoding.resolutions['1440p']).to.be.false
94 expect(data.live.transcoding.resolutions['2160p']).to.be.false
96 expect(data.import.videos.concurrency).to.equal(2)
97 expect(data.import.videos.http.enabled).to.be.true
98 expect(data.import.videos.torrent.enabled).to.be.true
99 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
101 expect(data.followers.instance.enabled).to.be.true
102 expect(data.followers.instance.manualApproval).to.be.false
104 expect(data.followings.instance.autoFollowBack.enabled).to.be.false
105 expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
106 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('')
108 expect(data.broadcastMessage.enabled).to.be.false
109 expect(data.broadcastMessage.level).to.equal('info')
110 expect(data.broadcastMessage.message).to.equal('')
111 expect(data.broadcastMessage.dismissable).to.be.false
114 function checkUpdatedConfig (data: CustomConfig) {
115 expect(data.instance.name).to.equal('PeerTube updated')
116 expect(data.instance.shortDescription).to.equal('my short description')
117 expect(data.instance.description).to.equal('my super description')
119 expect(data.instance.terms).to.equal('my super terms')
120 expect(data.instance.creationReason).to.equal('my super creation reason')
121 expect(data.instance.codeOfConduct).to.equal('my super coc')
122 expect(data.instance.moderationInformation).to.equal('my super moderation information')
123 expect(data.instance.administrator).to.equal('Kuja')
124 expect(data.instance.maintenanceLifetime).to.equal('forever')
125 expect(data.instance.businessModel).to.equal('my super business model')
126 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
128 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
129 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
131 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
132 expect(data.instance.isNSFW).to.be.true
133 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
134 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
135 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
137 expect(data.services.twitter.username).to.equal('@Kuja')
138 expect(data.services.twitter.whitelisted).to.be.true
140 expect(data.cache.previews.size).to.equal(2)
141 expect(data.cache.captions.size).to.equal(3)
142 expect(data.cache.torrents.size).to.equal(4)
144 expect(data.signup.enabled).to.be.false
145 expect(data.signup.limit).to.equal(5)
146 expect(data.signup.requiresEmailVerification).to.be.false
147 expect(data.signup.minimumAge).to.equal(10)
149 // We override admin email in parallel tests, so skip this exception
150 if (parallelTests() === false) {
151 expect(data.admin.email).to.equal('superadmin1@example.com')
154 expect(data.contactForm.enabled).to.be.false
156 expect(data.user.videoQuota).to.equal(5242881)
157 expect(data.user.videoQuotaDaily).to.equal(318742)
159 expect(data.transcoding.enabled).to.be.true
160 expect(data.transcoding.threads).to.equal(1)
161 expect(data.transcoding.concurrency).to.equal(3)
162 expect(data.transcoding.allowAdditionalExtensions).to.be.true
163 expect(data.transcoding.allowAudioFiles).to.be.true
164 expect(data.transcoding.profile).to.equal('vod_profile')
165 expect(data.transcoding.resolutions['240p']).to.be.false
166 expect(data.transcoding.resolutions['360p']).to.be.true
167 expect(data.transcoding.resolutions['480p']).to.be.true
168 expect(data.transcoding.resolutions['720p']).to.be.false
169 expect(data.transcoding.resolutions['1080p']).to.be.false
170 expect(data.transcoding.resolutions['2160p']).to.be.false
171 expect(data.transcoding.hls.enabled).to.be.false
172 expect(data.transcoding.webtorrent.enabled).to.be.true
174 expect(data.live.enabled).to.be.true
175 expect(data.live.allowReplay).to.be.true
176 expect(data.live.maxDuration).to.equal(5000)
177 expect(data.live.maxInstanceLives).to.equal(-1)
178 expect(data.live.maxUserLives).to.equal(10)
179 expect(data.live.transcoding.enabled).to.be.true
180 expect(data.live.transcoding.threads).to.equal(4)
181 expect(data.live.transcoding.profile).to.equal('live_profile')
182 expect(data.live.transcoding.resolutions['240p']).to.be.true
183 expect(data.live.transcoding.resolutions['360p']).to.be.true
184 expect(data.live.transcoding.resolutions['480p']).to.be.true
185 expect(data.live.transcoding.resolutions['720p']).to.be.true
186 expect(data.live.transcoding.resolutions['1080p']).to.be.true
187 expect(data.live.transcoding.resolutions['2160p']).to.be.true
189 expect(data.import.videos.concurrency).to.equal(4)
190 expect(data.import.videos.http.enabled).to.be.false
191 expect(data.import.videos.torrent.enabled).to.be.false
192 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
194 expect(data.followers.instance.enabled).to.be.false
195 expect(data.followers.instance.manualApproval).to.be.true
197 expect(data.followings.instance.autoFollowBack.enabled).to.be.true
198 expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
199 expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
201 expect(data.broadcastMessage.enabled).to.be.true
202 expect(data.broadcastMessage.level).to.equal('error')
203 expect(data.broadcastMessage.message).to.equal('super bad message')
204 expect(data.broadcastMessage.dismissable).to.be.true
207 describe('Test config', function () {
208 let server: ServerInfo = null
210 before(async function () {
213 server = await flushAndRunServer(1)
214 await setAccessTokensToServers([ server ])
217 it('Should have a correct config on a server with registration enabled', async function () {
218 const data = await server.configCommand.getConfig()
220 expect(data.signup.allowed).to.be.true
223 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
227 server.usersCommand.register({ username: 'user1' }),
228 server.usersCommand.register({ username: 'user2' }),
229 server.usersCommand.register({ username: 'user3' })
232 const data = await server.configCommand.getConfig()
234 expect(data.signup.allowed).to.be.false
237 it('Should have the correct video allowed extensions', async function () {
238 const data = await server.configCommand.getConfig()
240 expect(data.video.file.extensions).to.have.lengthOf(3)
241 expect(data.video.file.extensions).to.contain('.mp4')
242 expect(data.video.file.extensions).to.contain('.webm')
243 expect(data.video.file.extensions).to.contain('.ogv')
245 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
246 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
248 expect(data.contactForm.enabled).to.be.true
251 it('Should get the customized configuration', async function () {
252 const data = await server.configCommand.getCustomConfig()
254 checkInitialConfig(server, data)
257 it('Should update the customized configuration', async function () {
258 const newCustomConfig: CustomConfig = {
260 name: 'PeerTube updated',
261 shortDescription: 'my short description',
262 description: 'my super description',
263 terms: 'my super terms',
264 codeOfConduct: 'my super coc',
266 creationReason: 'my super creation reason',
267 moderationInformation: 'my super moderation information',
268 administrator: 'Kuja',
269 maintenanceLifetime: 'forever',
270 businessModel: 'my super business model',
271 hardwareInformation: '2vCore 3GB RAM',
273 languages: [ 'en', 'es' ],
274 categories: [ 1, 2 ],
277 defaultNSFWPolicy: 'blur' as 'blur',
279 defaultClientRoute: '/videos/recently-added',
282 javascript: 'alert("coucou")',
283 css: 'body { background-color: red; }'
309 requiresEmailVerification: false,
313 email: 'superadmin1@example.com'
320 videoQuotaDaily: 318742
324 allowAdditionalExtensions: true,
325 allowAudioFiles: true,
328 profile: 'vod_profile',
350 maxInstanceLives: -1,
355 profile: 'live_profile',
381 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
406 indexUrl: 'https://updated.example.com'
413 message: 'super bad message',
423 url: 'https://search.joinpeertube.org',
424 disableLocalSearch: true,
425 isDefaultSearch: true
429 await server.configCommand.updateCustomConfig({ newCustomConfig })
431 const data = await server.configCommand.getCustomConfig()
432 checkUpdatedConfig(data)
435 it('Should have the correct updated video allowed extensions', async function () {
438 const data = await server.configCommand.getConfig()
440 expect(data.video.file.extensions).to.have.length.above(4)
441 expect(data.video.file.extensions).to.contain('.mp4')
442 expect(data.video.file.extensions).to.contain('.webm')
443 expect(data.video.file.extensions).to.contain('.ogv')
444 expect(data.video.file.extensions).to.contain('.flv')
445 expect(data.video.file.extensions).to.contain('.wmv')
446 expect(data.video.file.extensions).to.contain('.mkv')
447 expect(data.video.file.extensions).to.contain('.mp3')
448 expect(data.video.file.extensions).to.contain('.ogg')
449 expect(data.video.file.extensions).to.contain('.flac')
451 await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.OK_200)
452 await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.OK_200)
455 it('Should have the configuration updated after a restart', async function () {
458 await killallServers([ server ])
460 await reRunServer(server)
462 const data = await server.configCommand.getCustomConfig()
464 checkUpdatedConfig(data)
467 it('Should fetch the about information', async function () {
468 const data = await server.configCommand.getAbout()
470 expect(data.instance.name).to.equal('PeerTube updated')
471 expect(data.instance.shortDescription).to.equal('my short description')
472 expect(data.instance.description).to.equal('my super description')
473 expect(data.instance.terms).to.equal('my super terms')
474 expect(data.instance.codeOfConduct).to.equal('my super coc')
476 expect(data.instance.creationReason).to.equal('my super creation reason')
477 expect(data.instance.moderationInformation).to.equal('my super moderation information')
478 expect(data.instance.administrator).to.equal('Kuja')
479 expect(data.instance.maintenanceLifetime).to.equal('forever')
480 expect(data.instance.businessModel).to.equal('my super business model')
481 expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
483 expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
484 expect(data.instance.categories).to.deep.equal([ 1, 2 ])
487 it('Should remove the custom configuration', async function () {
490 await server.configCommand.deleteCustomConfig()
492 const data = await server.configCommand.getCustomConfig()
493 checkInitialConfig(server, data)
496 it('Should enable frameguard', async function () {
500 const res = await makeGetRequest({
502 path: '/api/v1/config',
503 statusCodeExpected: 200
506 expect(res.headers['x-frame-options']).to.exist
509 await killallServers([ server ])
513 frameguard: { enabled: false }
516 server = await reRunServer(server, config)
519 const res = await makeGetRequest({
521 path: '/api/v1/config',
522 statusCodeExpected: 200
525 expect(res.headers['x-frame-options']).to.not.exist
529 after(async function () {
530 await cleanupTests([ server ])