123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
- import { expect } from 'chai'
- import { VideoDetails, VideoPrivacy } from '@peertube/peertube-models'
- import {
- cleanupTests,
- createSingleServer,
- PeerTubeServer,
- setAccessTokensToServers,
- setDefaultVideoChannel
- } from '@peertube/peertube-server-commands'
- import { FIXTURE_URLS } from '@tests/shared/fixture-urls.js'
- describe('Test config defaults', function () {
- let server: PeerTubeServer
- let channelId: number
- before(async function () {
- this.timeout(30000)
- server = await createSingleServer(1)
- await setAccessTokensToServers([ server ])
- await setDefaultVideoChannel([ server ])
- channelId = server.store.channel.id
- })
- describe('Default publish values', function () {
- before(async function () {
- const overrideConfig = {
- defaults: {
- publish: {
- comments_enabled: false,
- download_enabled: false,
- privacy: VideoPrivacy.INTERNAL,
- licence: 4
- }
- }
- }
- await server.kill()
- await server.run(overrideConfig)
- })
- const attributes = {
- name: 'video',
- downloadEnabled: undefined,
- commentsEnabled: undefined,
- licence: undefined,
- privacy: VideoPrivacy.PUBLIC // Privacy is mandatory for server
- }
- function checkVideo (video: VideoDetails) {
- expect(video.downloadEnabled).to.be.false
- expect(video.commentsEnabled).to.be.false
- expect(video.licence.id).to.equal(4)
- }
- before(async function () {
- await server.config.disableTranscoding()
- await server.config.enableVideoImports()
- await server.config.enableLive({ allowReplay: false, transcoding: false })
- })
- it('Should have the correct server configuration', async function () {
- const config = await server.config.getConfig()
- expect(config.defaults.publish.commentsEnabled).to.be.false
- expect(config.defaults.publish.downloadEnabled).to.be.false
- expect(config.defaults.publish.licence).to.equal(4)
- expect(config.defaults.publish.privacy).to.equal(VideoPrivacy.INTERNAL)
- })
- it('Should respect default values when uploading a video', async function () {
- for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) {
- const { id } = await server.videos.upload({ attributes, mode })
- const video = await server.videos.get({ id })
- checkVideo(video)
- }
- })
- it('Should respect default values when importing a video using URL', async function () {
- const { video: { id } } = await server.videoImports.importVideo({
- attributes: {
- ...attributes,
- channelId,
- targetUrl: FIXTURE_URLS.goodVideo
- }
- })
- const video = await server.videos.get({ id })
- checkVideo(video)
- })
- it('Should respect default values when importing a video using magnet URI', async function () {
- const { video: { id } } = await server.videoImports.importVideo({
- attributes: {
- ...attributes,
- channelId,
- magnetUri: FIXTURE_URLS.magnet
- }
- })
- const video = await server.videos.get({ id })
- checkVideo(video)
- })
- it('Should respect default values when creating a live', async function () {
- const { id } = await server.live.create({
- fields: {
- ...attributes,
- channelId
- }
- })
- const video = await server.videos.get({ id })
- checkVideo(video)
- })
- })
- describe('Default P2P values', function () {
- describe('Webapp default value', function () {
- before(async function () {
- const overrideConfig = {
- defaults: {
- p2p: {
- webapp: {
- enabled: false
- }
- }
- }
- }
- await server.kill()
- await server.run(overrideConfig)
- })
- it('Should have appropriate P2P config', async function () {
- const config = await server.config.getConfig()
- expect(config.defaults.p2p.webapp.enabled).to.be.false
- expect(config.defaults.p2p.embed.enabled).to.be.true
- })
- it('Should create a user with this default setting', async function () {
- await server.users.create({ username: 'user_p2p_1' })
- const userToken = await server.login.getAccessToken('user_p2p_1')
- const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
- expect(p2pEnabled).to.be.false
- })
- it('Should register a user with this default setting', async function () {
- await server.registrations.register({ username: 'user_p2p_2' })
- const userToken = await server.login.getAccessToken('user_p2p_2')
- const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
- expect(p2pEnabled).to.be.false
- })
- })
- describe('Embed default value', function () {
- before(async function () {
- const overrideConfig = {
- defaults: {
- p2p: {
- embed: {
- enabled: false
- }
- }
- },
- signup: {
- limit: 15
- }
- }
- await server.kill()
- await server.run(overrideConfig)
- })
- it('Should have appropriate P2P config', async function () {
- const config = await server.config.getConfig()
- expect(config.defaults.p2p.webapp.enabled).to.be.true
- expect(config.defaults.p2p.embed.enabled).to.be.false
- })
- it('Should create a user with this default setting', async function () {
- await server.users.create({ username: 'user_p2p_3' })
- const userToken = await server.login.getAccessToken('user_p2p_3')
- const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
- expect(p2pEnabled).to.be.true
- })
- it('Should register a user with this default setting', async function () {
- await server.registrations.register({ username: 'user_p2p_4' })
- const userToken = await server.login.getAccessToken('user_p2p_4')
- const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
- expect(p2pEnabled).to.be.true
- })
- })
- })
- describe('Default user attributes', function () {
- it('Should create a user and register a user with the default config', async function () {
- await server.config.updateExistingConfig({
- newConfig: {
- user: {
- history: {
- videos: {
- enabled: true
- }
- },
- videoQuota : -1,
- videoQuotaDaily: -1
- },
- signup: {
- enabled: true,
- requiresApproval: false
- }
- }
- })
- const config = await server.config.getConfig()
- expect(config.user.videoQuota).to.equal(-1)
- expect(config.user.videoQuotaDaily).to.equal(-1)
- const user1Token = await server.users.generateUserAndToken('user1')
- const user1 = await server.users.getMyInfo({ token: user1Token })
- const user = { displayName: 'super user 2', username: 'user2', password: 'super password' }
- const channel = { name: 'my_user_2_channel', displayName: 'my channel' }
- await server.registrations.register({ ...user, channel })
- const user2Token = await server.login.getAccessToken(user)
- const user2 = await server.users.getMyInfo({ token: user2Token })
- for (const user of [ user1, user2 ]) {
- expect(user.videosHistoryEnabled).to.be.true
- expect(user.videoQuota).to.equal(-1)
- expect(user.videoQuotaDaily).to.equal(-1)
- }
- })
- it('Should update config and create a user and register a user with the new default config', async function () {
- await server.config.updateExistingConfig({
- newConfig: {
- user: {
- history: {
- videos: {
- enabled: false
- }
- },
- videoQuota : 5242881,
- videoQuotaDaily: 318742
- },
- signup: {
- enabled: true,
- requiresApproval: false
- }
- }
- })
- const user3Token = await server.users.generateUserAndToken('user3')
- const user3 = await server.users.getMyInfo({ token: user3Token })
- const user = { displayName: 'super user 4', username: 'user4', password: 'super password' }
- const channel = { name: 'my_user_4_channel', displayName: 'my channel' }
- await server.registrations.register({ ...user, channel })
- const user4Token = await server.login.getAccessToken(user)
- const user4 = await server.users.getMyInfo({ token: user4Token })
- for (const user of [ user3, user4 ]) {
- expect(user.videosHistoryEnabled).to.be.false
- expect(user.videoQuota).to.equal(5242881)
- expect(user.videoQuotaDaily).to.equal(318742)
- }
- })
- })
- after(async function () {
- await cleanupTests([ server ])
- })
- })
|