aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/server/config.ts
blob: 97cc99eeaf892494bc22a8d8ab22ef7b4d9a16aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/* tslint:disable:no-unused-expression */

import 'mocha'
import * as chai from 'chai'
import { About } from '../../../../shared/models/server/about.model'
import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
import {
  cleanupTests,
  deleteCustomConfig,
  flushAndRunServer,
  getAbout,
  getConfig,
  getCustomConfig,
  killallServers, parallelTests,
  registerUser,
  reRunServer, ServerInfo,
  setAccessTokensToServers,
  updateCustomConfig, uploadVideo
} from '../../../../shared/extra-utils'
import { ServerConfig } from '../../../../shared/models'

const expect = chai.expect

function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
  expect(data.instance.name).to.equal('PeerTube')
  expect(data.instance.shortDescription).to.equal(
    'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
    'with WebTorrent and Angular.'
  )
  expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')

  expect(data.instance.terms).to.equal('No terms for now.')
  expect(data.instance.creationReason).to.be.empty
  expect(data.instance.codeOfConduct).to.be.empty
  expect(data.instance.moderationInformation).to.be.empty
  expect(data.instance.administrator).to.be.empty
  expect(data.instance.maintenanceLifetime).to.be.empty
  expect(data.instance.businessModel).to.be.empty
  expect(data.instance.hardwareInformation).to.be.empty

  expect(data.instance.languages).to.have.lengthOf(0)
  expect(data.instance.categories).to.have.lengthOf(0)

  expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
  expect(data.instance.isNSFW).to.be.false
  expect(data.instance.defaultNSFWPolicy).to.equal('display')
  expect(data.instance.customizations.css).to.be.empty
  expect(data.instance.customizations.javascript).to.be.empty

  expect(data.services.twitter.username).to.equal('@Chocobozzz')
  expect(data.services.twitter.whitelisted).to.be.false

  expect(data.cache.previews.size).to.equal(1)
  expect(data.cache.captions.size).to.equal(1)

  expect(data.signup.enabled).to.be.true
  expect(data.signup.limit).to.equal(4)
  expect(data.signup.requiresEmailVerification).to.be.false

  expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
  expect(data.contactForm.enabled).to.be.true

  expect(data.user.videoQuota).to.equal(5242880)
  expect(data.user.videoQuotaDaily).to.equal(-1)
  expect(data.transcoding.enabled).to.be.false
  expect(data.transcoding.allowAdditionalExtensions).to.be.false
  expect(data.transcoding.allowAudioFiles).to.be.false
  expect(data.transcoding.threads).to.equal(2)
  expect(data.transcoding.resolutions['240p']).to.be.true
  expect(data.transcoding.resolutions['360p']).to.be.true
  expect(data.transcoding.resolutions['480p']).to.be.true
  expect(data.transcoding.resolutions['720p']).to.be.true
  expect(data.transcoding.resolutions['1080p']).to.be.true
  expect(data.transcoding.resolutions['2160p']).to.be.true
  expect(data.transcoding.hls.enabled).to.be.true

  expect(data.import.videos.http.enabled).to.be.true
  expect(data.import.videos.torrent.enabled).to.be.true
  expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false

  expect(data.followers.instance.enabled).to.be.true
  expect(data.followers.instance.manualApproval).to.be.false

  expect(data.followings.instance.autoFollowBack.enabled).to.be.false
  expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
  expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://instances.joinpeertube.org')
}

function checkUpdatedConfig (data: CustomConfig) {
  expect(data.instance.name).to.equal('PeerTube updated')
  expect(data.instance.shortDescription).to.equal('my short description')
  expect(data.instance.description).to.equal('my super description')

  expect(data.instance.terms).to.equal('my super terms')
  expect(data.instance.creationReason).to.equal('my super creation reason')
  expect(data.instance.codeOfConduct).to.equal('my super coc')
  expect(data.instance.moderationInformation).to.equal('my super moderation information')
  expect(data.instance.administrator).to.equal('Kuja')
  expect(data.instance.maintenanceLifetime).to.equal('forever')
  expect(data.instance.businessModel).to.equal('my super business model')
  expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')

  expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
  expect(data.instance.categories).to.deep.equal([ 1, 2 ])

  expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
  expect(data.instance.isNSFW).to.be.true
  expect(data.instance.defaultNSFWPolicy).to.equal('blur')
  expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
  expect(data.instance.customizations.css).to.equal('body { background-color: red; }')

  expect(data.services.twitter.username).to.equal('@Kuja')
  expect(data.services.twitter.whitelisted).to.be.true

  expect(data.cache.previews.size).to.equal(2)
  expect(data.cache.captions.size).to.equal(3)

  expect(data.signup.enabled).to.be.false
  expect(data.signup.limit).to.equal(5)
  expect(data.signup.requiresEmailVerification).to.be.false

  // We override admin email in parallel tests, so skip this exception
  if (parallelTests() === false) {
    expect(data.admin.email).to.equal('superadmin1@example.com')
  }

  expect(data.contactForm.enabled).to.be.false

  expect(data.user.videoQuota).to.equal(5242881)
  expect(data.user.videoQuotaDaily).to.equal(318742)

  expect(data.transcoding.enabled).to.be.true
  expect(data.transcoding.threads).to.equal(1)
  expect(data.transcoding.allowAdditionalExtensions).to.be.true
  expect(data.transcoding.allowAudioFiles).to.be.true
  expect(data.transcoding.resolutions['240p']).to.be.false
  expect(data.transcoding.resolutions['360p']).to.be.true
  expect(data.transcoding.resolutions['480p']).to.be.true
  expect(data.transcoding.resolutions['720p']).to.be.false
  expect(data.transcoding.resolutions['1080p']).to.be.false
  expect(data.transcoding.resolutions['2160p']).to.be.false
  expect(data.transcoding.hls.enabled).to.be.false

  expect(data.import.videos.http.enabled).to.be.false
  expect(data.import.videos.torrent.enabled).to.be.false
  expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true

  expect(data.followers.instance.enabled).to.be.false
  expect(data.followers.instance.manualApproval).to.be.true

  expect(data.followings.instance.autoFollowBack.enabled).to.be.true
  expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
  expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
}

describe('Test config', function () {
  let server = null

  before(async function () {
    this.timeout(30000)

    server = await flushAndRunServer(1)
    await setAccessTokensToServers([ server ])
  })

  it('Should have a correct config on a server with registration enabled', async function () {
    const res = await getConfig(server.url)
    const data: ServerConfig = res.body

    expect(data.signup.allowed).to.be.true
  })

  it('Should have a correct config on a server with registration enabled and a users limit', async function () {
    this.timeout(5000)

    await Promise.all([
      registerUser(server.url, 'user1', 'super password'),
      registerUser(server.url, 'user2', 'super password'),
      registerUser(server.url, 'user3', 'super password')
    ])

    const res = await getConfig(server.url)
    const data: ServerConfig = res.body

    expect(data.signup.allowed).to.be.false
  })

  it('Should have the correct video allowed extensions', async function () {
    const res = await getConfig(server.url)
    const data: ServerConfig = res.body

    expect(data.video.file.extensions).to.have.lengthOf(3)
    expect(data.video.file.extensions).to.contain('.mp4')
    expect(data.video.file.extensions).to.contain('.webm')
    expect(data.video.file.extensions).to.contain('.ogv')

    await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
    await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)

    expect(data.contactForm.enabled).to.be.true
  })

  it('Should get the customized configuration', async function () {
    const res = await getCustomConfig(server.url, server.accessToken)
    const data = res.body as CustomConfig

    checkInitialConfig(server, data)
  })

  it('Should update the customized configuration', async function () {
    const newCustomConfig: CustomConfig = {
      instance: {
        name: 'PeerTube updated',
        shortDescription: 'my short description',
        description: 'my super description',
        terms: 'my super terms',
        codeOfConduct: 'my super coc',

        creationReason: 'my super creation reason',
        moderationInformation: 'my super moderation information',
        administrator: 'Kuja',
        maintenanceLifetime: 'forever',
        businessModel: 'my super business model',
        hardwareInformation: '2vCore 3GB RAM',

        languages: [ 'en', 'es' ],
        categories: [ 1, 2 ],

        defaultClientRoute: '/videos/recently-added',
        isNSFW: true,
        defaultNSFWPolicy: 'blur' as 'blur',
        customizations: {
          javascript: 'alert("coucou")',
          css: 'body { background-color: red; }'
        }
      },
      theme: {
        default: 'default'
      },
      services: {
        twitter: {
          username: '@Kuja',
          whitelisted: true
        }
      },
      cache: {
        previews: {
          size: 2
        },
        captions: {
          size: 3
        }
      },
      signup: {
        enabled: false,
        limit: 5,
        requiresEmailVerification: false
      },
      admin: {
        email: 'superadmin1@example.com'
      },
      contactForm: {
        enabled: false
      },
      user: {
        videoQuota: 5242881,
        videoQuotaDaily: 318742
      },
      transcoding: {
        enabled: true,
        allowAdditionalExtensions: true,
        allowAudioFiles: true,
        threads: 1,
        resolutions: {
          '240p': false,
          '360p': true,
          '480p': true,
          '720p': false,
          '1080p': false,
          '2160p': false
        },
        hls: {
          enabled: false
        }
      },
      import: {
        videos: {
          http: {
            enabled: false
          },
          torrent: {
            enabled: false
          }
        }
      },
      autoBlacklist: {
        videos: {
          ofUsers: {
            enabled: true
          }
        }
      },
      followers: {
        instance: {
          enabled: false,
          manualApproval: true
        }
      },
      followings: {
        instance: {
          autoFollowBack: {
            enabled: true
          },
          autoFollowIndex: {
            enabled: true,
            indexUrl: 'https://updated.example.com'
          }
        }
      }
    }
    await updateCustomConfig(server.url, server.accessToken, newCustomConfig)

    const res = await getCustomConfig(server.url, server.accessToken)
    const data = res.body

    checkUpdatedConfig(data)
  })

  it('Should have the correct updated video allowed extensions', async function () {
    const res = await getConfig(server.url)
    const data: ServerConfig = res.body

    expect(data.video.file.extensions).to.have.length.above(3)
    expect(data.video.file.extensions).to.contain('.mp4')
    expect(data.video.file.extensions).to.contain('.webm')
    expect(data.video.file.extensions).to.contain('.ogv')
    expect(data.video.file.extensions).to.contain('.flv')
    expect(data.video.file.extensions).to.contain('.mkv')
    expect(data.video.file.extensions).to.contain('.mp3')
    expect(data.video.file.extensions).to.contain('.ogg')
    expect(data.video.file.extensions).to.contain('.flac')

    await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
    await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
  })

  it('Should have the configuration updated after a restart', async function () {
    this.timeout(10000)

    killallServers([ server ])

    await reRunServer(server)

    const res = await getCustomConfig(server.url, server.accessToken)
    const data = res.body

    checkUpdatedConfig(data)
  })

  it('Should fetch the about information', async function () {
    const res = await getAbout(server.url)
    const data: About = res.body

    expect(data.instance.name).to.equal('PeerTube updated')
    expect(data.instance.shortDescription).to.equal('my short description')
    expect(data.instance.description).to.equal('my super description')
    expect(data.instance.terms).to.equal('my super terms')
    expect(data.instance.codeOfConduct).to.equal('my super coc')

    expect(data.instance.creationReason).to.equal('my super creation reason')
    expect(data.instance.moderationInformation).to.equal('my super moderation information')
    expect(data.instance.administrator).to.equal('Kuja')
    expect(data.instance.maintenanceLifetime).to.equal('forever')
    expect(data.instance.businessModel).to.equal('my super business model')
    expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')

    expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
    expect(data.instance.categories).to.deep.equal([ 1, 2 ])
  })

  it('Should remove the custom configuration', async function () {
    this.timeout(10000)

    await deleteCustomConfig(server.url, server.accessToken)

    const res = await getCustomConfig(server.url, server.accessToken)
    const data = res.body

    checkInitialConfig(server, data)
  })

  after(async function () {
    await cleanupTests([ server ])
  })
})