diff options
Diffstat (limited to 'server/tests/api/server/config.ts')
-rw-r--r-- | server/tests/api/server/config.ts | 86 |
1 files changed, 32 insertions, 54 deletions
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 19bf9582c..fd61e95df 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts | |||
@@ -2,31 +2,20 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { About } from '../../../../shared/models/server/about.model' | ||
6 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' | ||
7 | import { | 5 | import { |
8 | cleanupTests, | 6 | cleanupTests, |
9 | deleteCustomConfig, | 7 | createSingleServer, |
10 | flushAndRunServer, | ||
11 | getAbout, | ||
12 | getConfig, | ||
13 | getCustomConfig, | ||
14 | killallServers, | 8 | killallServers, |
15 | makeGetRequest, | 9 | makeGetRequest, |
16 | parallelTests, | 10 | parallelTests, |
17 | registerUser, | 11 | PeerTubeServer, |
18 | reRunServer, | 12 | setAccessTokensToServers |
19 | ServerInfo, | 13 | } from '@shared/extra-utils' |
20 | setAccessTokensToServers, | 14 | import { CustomConfig, HttpStatusCode } from '@shared/models' |
21 | updateCustomConfig, | ||
22 | uploadVideo | ||
23 | } from '../../../../shared/extra-utils' | ||
24 | import { ServerConfig } from '../../../../shared/models' | ||
25 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
26 | 15 | ||
27 | const expect = chai.expect | 16 | const expect = chai.expect |
28 | 17 | ||
29 | function checkInitialConfig (server: ServerInfo, data: CustomConfig) { | 18 | function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) { |
30 | expect(data.instance.name).to.equal('PeerTube') | 19 | expect(data.instance.name).to.equal('PeerTube') |
31 | expect(data.instance.shortDescription).to.equal( | 20 | expect(data.instance.shortDescription).to.equal( |
32 | 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' | 21 | 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' |
@@ -213,18 +202,17 @@ function checkUpdatedConfig (data: CustomConfig) { | |||
213 | } | 202 | } |
214 | 203 | ||
215 | describe('Test config', function () { | 204 | describe('Test config', function () { |
216 | let server = null | 205 | let server: PeerTubeServer = null |
217 | 206 | ||
218 | before(async function () { | 207 | before(async function () { |
219 | this.timeout(30000) | 208 | this.timeout(30000) |
220 | 209 | ||
221 | server = await flushAndRunServer(1) | 210 | server = await createSingleServer(1) |
222 | await setAccessTokensToServers([ server ]) | 211 | await setAccessTokensToServers([ server ]) |
223 | }) | 212 | }) |
224 | 213 | ||
225 | it('Should have a correct config on a server with registration enabled', async function () { | 214 | it('Should have a correct config on a server with registration enabled', async function () { |
226 | const res = await getConfig(server.url) | 215 | const data = await server.config.getConfig() |
227 | const data: ServerConfig = res.body | ||
228 | 216 | ||
229 | expect(data.signup.allowed).to.be.true | 217 | expect(data.signup.allowed).to.be.true |
230 | }) | 218 | }) |
@@ -233,35 +221,32 @@ describe('Test config', function () { | |||
233 | this.timeout(5000) | 221 | this.timeout(5000) |
234 | 222 | ||
235 | await Promise.all([ | 223 | await Promise.all([ |
236 | registerUser(server.url, 'user1', 'super password'), | 224 | server.users.register({ username: 'user1' }), |
237 | registerUser(server.url, 'user2', 'super password'), | 225 | server.users.register({ username: 'user2' }), |
238 | registerUser(server.url, 'user3', 'super password') | 226 | server.users.register({ username: 'user3' }) |
239 | ]) | 227 | ]) |
240 | 228 | ||
241 | const res = await getConfig(server.url) | 229 | const data = await server.config.getConfig() |
242 | const data: ServerConfig = res.body | ||
243 | 230 | ||
244 | expect(data.signup.allowed).to.be.false | 231 | expect(data.signup.allowed).to.be.false |
245 | }) | 232 | }) |
246 | 233 | ||
247 | it('Should have the correct video allowed extensions', async function () { | 234 | it('Should have the correct video allowed extensions', async function () { |
248 | const res = await getConfig(server.url) | 235 | const data = await server.config.getConfig() |
249 | const data: ServerConfig = res.body | ||
250 | 236 | ||
251 | expect(data.video.file.extensions).to.have.lengthOf(3) | 237 | expect(data.video.file.extensions).to.have.lengthOf(3) |
252 | expect(data.video.file.extensions).to.contain('.mp4') | 238 | expect(data.video.file.extensions).to.contain('.mp4') |
253 | expect(data.video.file.extensions).to.contain('.webm') | 239 | expect(data.video.file.extensions).to.contain('.webm') |
254 | expect(data.video.file.extensions).to.contain('.ogv') | 240 | expect(data.video.file.extensions).to.contain('.ogv') |
255 | 241 | ||
256 | await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415) | 242 | await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 }) |
257 | await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415) | 243 | await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 }) |
258 | 244 | ||
259 | expect(data.contactForm.enabled).to.be.true | 245 | expect(data.contactForm.enabled).to.be.true |
260 | }) | 246 | }) |
261 | 247 | ||
262 | it('Should get the customized configuration', async function () { | 248 | it('Should get the customized configuration', async function () { |
263 | const res = await getCustomConfig(server.url, server.accessToken) | 249 | const data = await server.config.getCustomConfig() |
264 | const data = res.body as CustomConfig | ||
265 | 250 | ||
266 | checkInitialConfig(server, data) | 251 | checkInitialConfig(server, data) |
267 | }) | 252 | }) |
@@ -438,19 +423,16 @@ describe('Test config', function () { | |||
438 | } | 423 | } |
439 | } | 424 | } |
440 | } | 425 | } |
441 | await updateCustomConfig(server.url, server.accessToken, newCustomConfig) | 426 | await server.config.updateCustomConfig({ newCustomConfig }) |
442 | |||
443 | const res = await getCustomConfig(server.url, server.accessToken) | ||
444 | const data = res.body | ||
445 | 427 | ||
428 | const data = await server.config.getCustomConfig() | ||
446 | checkUpdatedConfig(data) | 429 | checkUpdatedConfig(data) |
447 | }) | 430 | }) |
448 | 431 | ||
449 | it('Should have the correct updated video allowed extensions', async function () { | 432 | it('Should have the correct updated video allowed extensions', async function () { |
450 | this.timeout(10000) | 433 | this.timeout(10000) |
451 | 434 | ||
452 | const res = await getConfig(server.url) | 435 | const data = await server.config.getConfig() |
453 | const data: ServerConfig = res.body | ||
454 | 436 | ||
455 | expect(data.video.file.extensions).to.have.length.above(4) | 437 | expect(data.video.file.extensions).to.have.length.above(4) |
456 | expect(data.video.file.extensions).to.contain('.mp4') | 438 | expect(data.video.file.extensions).to.contain('.mp4') |
@@ -463,26 +445,24 @@ describe('Test config', function () { | |||
463 | expect(data.video.file.extensions).to.contain('.ogg') | 445 | expect(data.video.file.extensions).to.contain('.ogg') |
464 | expect(data.video.file.extensions).to.contain('.flac') | 446 | expect(data.video.file.extensions).to.contain('.flac') |
465 | 447 | ||
466 | await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.OK_200) | 448 | await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 }) |
467 | await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.OK_200) | 449 | await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 }) |
468 | }) | 450 | }) |
469 | 451 | ||
470 | it('Should have the configuration updated after a restart', async function () { | 452 | it('Should have the configuration updated after a restart', async function () { |
471 | this.timeout(10000) | 453 | this.timeout(10000) |
472 | 454 | ||
473 | killallServers([ server ]) | 455 | await killallServers([ server ]) |
474 | 456 | ||
475 | await reRunServer(server) | 457 | await server.run() |
476 | 458 | ||
477 | const res = await getCustomConfig(server.url, server.accessToken) | 459 | const data = await server.config.getCustomConfig() |
478 | const data = res.body | ||
479 | 460 | ||
480 | checkUpdatedConfig(data) | 461 | checkUpdatedConfig(data) |
481 | }) | 462 | }) |
482 | 463 | ||
483 | it('Should fetch the about information', async function () { | 464 | it('Should fetch the about information', async function () { |
484 | const res = await getAbout(server.url) | 465 | const data = await server.config.getAbout() |
485 | const data: About = res.body | ||
486 | 466 | ||
487 | expect(data.instance.name).to.equal('PeerTube updated') | 467 | expect(data.instance.name).to.equal('PeerTube updated') |
488 | expect(data.instance.shortDescription).to.equal('my short description') | 468 | expect(data.instance.shortDescription).to.equal('my short description') |
@@ -504,11 +484,9 @@ describe('Test config', function () { | |||
504 | it('Should remove the custom configuration', async function () { | 484 | it('Should remove the custom configuration', async function () { |
505 | this.timeout(10000) | 485 | this.timeout(10000) |
506 | 486 | ||
507 | await deleteCustomConfig(server.url, server.accessToken) | 487 | await server.config.deleteCustomConfig() |
508 | |||
509 | const res = await getCustomConfig(server.url, server.accessToken) | ||
510 | const data = res.body | ||
511 | 488 | ||
489 | const data = await server.config.getCustomConfig() | ||
512 | checkInitialConfig(server, data) | 490 | checkInitialConfig(server, data) |
513 | }) | 491 | }) |
514 | 492 | ||
@@ -519,26 +497,26 @@ describe('Test config', function () { | |||
519 | const res = await makeGetRequest({ | 497 | const res = await makeGetRequest({ |
520 | url: server.url, | 498 | url: server.url, |
521 | path: '/api/v1/config', | 499 | path: '/api/v1/config', |
522 | statusCodeExpected: 200 | 500 | expectedStatus: 200 |
523 | }) | 501 | }) |
524 | 502 | ||
525 | expect(res.headers['x-frame-options']).to.exist | 503 | expect(res.headers['x-frame-options']).to.exist |
526 | } | 504 | } |
527 | 505 | ||
528 | killallServers([ server ]) | 506 | await killallServers([ server ]) |
529 | 507 | ||
530 | const config = { | 508 | const config = { |
531 | security: { | 509 | security: { |
532 | frameguard: { enabled: false } | 510 | frameguard: { enabled: false } |
533 | } | 511 | } |
534 | } | 512 | } |
535 | server = await reRunServer(server, config) | 513 | await server.run(config) |
536 | 514 | ||
537 | { | 515 | { |
538 | const res = await makeGetRequest({ | 516 | const res = await makeGetRequest({ |
539 | url: server.url, | 517 | url: server.url, |
540 | path: '/api/v1/config', | 518 | path: '/api/v1/config', |
541 | statusCodeExpected: 200 | 519 | expectedStatus: 200 |
542 | }) | 520 | }) |
543 | 521 | ||
544 | expect(res.headers['x-frame-options']).to.not.exist | 522 | expect(res.headers['x-frame-options']).to.not.exist |