config-defaults.ts 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
  2. import { expect } from 'chai'
  3. import { VideoDetails, VideoPrivacy } from '@peertube/peertube-models'
  4. import {
  5. cleanupTests,
  6. createSingleServer,
  7. PeerTubeServer,
  8. setAccessTokensToServers,
  9. setDefaultVideoChannel
  10. } from '@peertube/peertube-server-commands'
  11. import { FIXTURE_URLS } from '@tests/shared/fixture-urls.js'
  12. describe('Test config defaults', function () {
  13. let server: PeerTubeServer
  14. let channelId: number
  15. before(async function () {
  16. this.timeout(30000)
  17. server = await createSingleServer(1)
  18. await setAccessTokensToServers([ server ])
  19. await setDefaultVideoChannel([ server ])
  20. channelId = server.store.channel.id
  21. })
  22. describe('Default publish values', function () {
  23. before(async function () {
  24. const overrideConfig = {
  25. defaults: {
  26. publish: {
  27. comments_enabled: false,
  28. download_enabled: false,
  29. privacy: VideoPrivacy.INTERNAL,
  30. licence: 4
  31. }
  32. }
  33. }
  34. await server.kill()
  35. await server.run(overrideConfig)
  36. })
  37. const attributes = {
  38. name: 'video',
  39. downloadEnabled: undefined,
  40. commentsEnabled: undefined,
  41. licence: undefined,
  42. privacy: VideoPrivacy.PUBLIC // Privacy is mandatory for server
  43. }
  44. function checkVideo (video: VideoDetails) {
  45. expect(video.downloadEnabled).to.be.false
  46. expect(video.commentsEnabled).to.be.false
  47. expect(video.licence.id).to.equal(4)
  48. }
  49. before(async function () {
  50. await server.config.disableTranscoding()
  51. await server.config.enableVideoImports()
  52. await server.config.enableLive({ allowReplay: false, transcoding: false })
  53. })
  54. it('Should have the correct server configuration', async function () {
  55. const config = await server.config.getConfig()
  56. expect(config.defaults.publish.commentsEnabled).to.be.false
  57. expect(config.defaults.publish.downloadEnabled).to.be.false
  58. expect(config.defaults.publish.licence).to.equal(4)
  59. expect(config.defaults.publish.privacy).to.equal(VideoPrivacy.INTERNAL)
  60. })
  61. it('Should respect default values when uploading a video', async function () {
  62. for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) {
  63. const { id } = await server.videos.upload({ attributes, mode })
  64. const video = await server.videos.get({ id })
  65. checkVideo(video)
  66. }
  67. })
  68. it('Should respect default values when importing a video using URL', async function () {
  69. const { video: { id } } = await server.videoImports.importVideo({
  70. attributes: {
  71. ...attributes,
  72. channelId,
  73. targetUrl: FIXTURE_URLS.goodVideo
  74. }
  75. })
  76. const video = await server.videos.get({ id })
  77. checkVideo(video)
  78. })
  79. it('Should respect default values when importing a video using magnet URI', async function () {
  80. const { video: { id } } = await server.videoImports.importVideo({
  81. attributes: {
  82. ...attributes,
  83. channelId,
  84. magnetUri: FIXTURE_URLS.magnet
  85. }
  86. })
  87. const video = await server.videos.get({ id })
  88. checkVideo(video)
  89. })
  90. it('Should respect default values when creating a live', async function () {
  91. const { id } = await server.live.create({
  92. fields: {
  93. ...attributes,
  94. channelId
  95. }
  96. })
  97. const video = await server.videos.get({ id })
  98. checkVideo(video)
  99. })
  100. })
  101. describe('Default P2P values', function () {
  102. describe('Webapp default value', function () {
  103. before(async function () {
  104. const overrideConfig = {
  105. defaults: {
  106. p2p: {
  107. webapp: {
  108. enabled: false
  109. }
  110. }
  111. }
  112. }
  113. await server.kill()
  114. await server.run(overrideConfig)
  115. })
  116. it('Should have appropriate P2P config', async function () {
  117. const config = await server.config.getConfig()
  118. expect(config.defaults.p2p.webapp.enabled).to.be.false
  119. expect(config.defaults.p2p.embed.enabled).to.be.true
  120. })
  121. it('Should create a user with this default setting', async function () {
  122. await server.users.create({ username: 'user_p2p_1' })
  123. const userToken = await server.login.getAccessToken('user_p2p_1')
  124. const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
  125. expect(p2pEnabled).to.be.false
  126. })
  127. it('Should register a user with this default setting', async function () {
  128. await server.registrations.register({ username: 'user_p2p_2' })
  129. const userToken = await server.login.getAccessToken('user_p2p_2')
  130. const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
  131. expect(p2pEnabled).to.be.false
  132. })
  133. })
  134. describe('Embed default value', function () {
  135. before(async function () {
  136. const overrideConfig = {
  137. defaults: {
  138. p2p: {
  139. embed: {
  140. enabled: false
  141. }
  142. }
  143. },
  144. signup: {
  145. limit: 15
  146. }
  147. }
  148. await server.kill()
  149. await server.run(overrideConfig)
  150. })
  151. it('Should have appropriate P2P config', async function () {
  152. const config = await server.config.getConfig()
  153. expect(config.defaults.p2p.webapp.enabled).to.be.true
  154. expect(config.defaults.p2p.embed.enabled).to.be.false
  155. })
  156. it('Should create a user with this default setting', async function () {
  157. await server.users.create({ username: 'user_p2p_3' })
  158. const userToken = await server.login.getAccessToken('user_p2p_3')
  159. const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
  160. expect(p2pEnabled).to.be.true
  161. })
  162. it('Should register a user with this default setting', async function () {
  163. await server.registrations.register({ username: 'user_p2p_4' })
  164. const userToken = await server.login.getAccessToken('user_p2p_4')
  165. const { p2pEnabled } = await server.users.getMyInfo({ token: userToken })
  166. expect(p2pEnabled).to.be.true
  167. })
  168. })
  169. })
  170. describe('Default user attributes', function () {
  171. it('Should create a user and register a user with the default config', async function () {
  172. await server.config.updateExistingConfig({
  173. newConfig: {
  174. user: {
  175. history: {
  176. videos: {
  177. enabled: true
  178. }
  179. },
  180. videoQuota : -1,
  181. videoQuotaDaily: -1
  182. },
  183. signup: {
  184. enabled: true,
  185. requiresApproval: false
  186. }
  187. }
  188. })
  189. const config = await server.config.getConfig()
  190. expect(config.user.videoQuota).to.equal(-1)
  191. expect(config.user.videoQuotaDaily).to.equal(-1)
  192. const user1Token = await server.users.generateUserAndToken('user1')
  193. const user1 = await server.users.getMyInfo({ token: user1Token })
  194. const user = { displayName: 'super user 2', username: 'user2', password: 'super password' }
  195. const channel = { name: 'my_user_2_channel', displayName: 'my channel' }
  196. await server.registrations.register({ ...user, channel })
  197. const user2Token = await server.login.getAccessToken(user)
  198. const user2 = await server.users.getMyInfo({ token: user2Token })
  199. for (const user of [ user1, user2 ]) {
  200. expect(user.videosHistoryEnabled).to.be.true
  201. expect(user.videoQuota).to.equal(-1)
  202. expect(user.videoQuotaDaily).to.equal(-1)
  203. }
  204. })
  205. it('Should update config and create a user and register a user with the new default config', async function () {
  206. await server.config.updateExistingConfig({
  207. newConfig: {
  208. user: {
  209. history: {
  210. videos: {
  211. enabled: false
  212. }
  213. },
  214. videoQuota : 5242881,
  215. videoQuotaDaily: 318742
  216. },
  217. signup: {
  218. enabled: true,
  219. requiresApproval: false
  220. }
  221. }
  222. })
  223. const user3Token = await server.users.generateUserAndToken('user3')
  224. const user3 = await server.users.getMyInfo({ token: user3Token })
  225. const user = { displayName: 'super user 4', username: 'user4', password: 'super password' }
  226. const channel = { name: 'my_user_4_channel', displayName: 'my channel' }
  227. await server.registrations.register({ ...user, channel })
  228. const user4Token = await server.login.getAccessToken(user)
  229. const user4 = await server.users.getMyInfo({ token: user4Token })
  230. for (const user of [ user3, user4 ]) {
  231. expect(user.videosHistoryEnabled).to.be.false
  232. expect(user.videoQuota).to.equal(5242881)
  233. expect(user.videoQuotaDaily).to.equal(318742)
  234. }
  235. })
  236. })
  237. after(async function () {
  238. await cleanupTests([ server ])
  239. })
  240. })