config.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /* tslint:disable:no-unused-expression */
  2. import 'mocha'
  3. import * as chai from 'chai'
  4. import { About } from '../../../../shared/models/server/about.model'
  5. import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
  6. import {
  7. cleanupTests,
  8. deleteCustomConfig,
  9. flushAndRunServer,
  10. getAbout,
  11. getConfig,
  12. getCustomConfig,
  13. killallServers, parallelTests,
  14. registerUser,
  15. reRunServer, ServerInfo,
  16. setAccessTokensToServers,
  17. updateCustomConfig, uploadVideo
  18. } from '../../../../shared/extra-utils'
  19. import { ServerConfig } from '../../../../shared/models'
  20. 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, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
  25. 'with WebTorrent and Angular.'
  26. )
  27. 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
  36. expect(data.instance.languages).to.have.lengthOf(0)
  37. expect(data.instance.categories).to.have.lengthOf(0)
  38. expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
  39. expect(data.instance.isNSFW).to.be.false
  40. expect(data.instance.defaultNSFWPolicy).to.equal('display')
  41. expect(data.instance.customizations.css).to.be.empty
  42. expect(data.instance.customizations.javascript).to.be.empty
  43. expect(data.services.twitter.username).to.equal('@Chocobozzz')
  44. expect(data.services.twitter.whitelisted).to.be.false
  45. expect(data.cache.previews.size).to.equal(1)
  46. expect(data.cache.captions.size).to.equal(1)
  47. expect(data.signup.enabled).to.be.true
  48. expect(data.signup.limit).to.equal(4)
  49. expect(data.signup.requiresEmailVerification).to.be.false
  50. expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
  51. expect(data.contactForm.enabled).to.be.true
  52. expect(data.user.videoQuota).to.equal(5242880)
  53. expect(data.user.videoQuotaDaily).to.equal(-1)
  54. expect(data.transcoding.enabled).to.be.false
  55. expect(data.transcoding.allowAdditionalExtensions).to.be.false
  56. expect(data.transcoding.allowAudioFiles).to.be.false
  57. expect(data.transcoding.threads).to.equal(2)
  58. expect(data.transcoding.resolutions['240p']).to.be.true
  59. expect(data.transcoding.resolutions['360p']).to.be.true
  60. expect(data.transcoding.resolutions['480p']).to.be.true
  61. expect(data.transcoding.resolutions['720p']).to.be.true
  62. expect(data.transcoding.resolutions['1080p']).to.be.true
  63. expect(data.transcoding.resolutions['2160p']).to.be.true
  64. expect(data.transcoding.webtorrent.enabled).to.be.true
  65. expect(data.transcoding.hls.enabled).to.be.true
  66. expect(data.import.videos.http.enabled).to.be.true
  67. expect(data.import.videos.torrent.enabled).to.be.true
  68. expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
  69. expect(data.followers.instance.enabled).to.be.true
  70. expect(data.followers.instance.manualApproval).to.be.false
  71. expect(data.followings.instance.autoFollowBack.enabled).to.be.false
  72. expect(data.followings.instance.autoFollowIndex.enabled).to.be.false
  73. expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://instances.joinpeertube.org')
  74. }
  75. function checkUpdatedConfig (data: CustomConfig) {
  76. expect(data.instance.name).to.equal('PeerTube updated')
  77. expect(data.instance.shortDescription).to.equal('my short description')
  78. expect(data.instance.description).to.equal('my super description')
  79. expect(data.instance.terms).to.equal('my super terms')
  80. expect(data.instance.creationReason).to.equal('my super creation reason')
  81. expect(data.instance.codeOfConduct).to.equal('my super coc')
  82. expect(data.instance.moderationInformation).to.equal('my super moderation information')
  83. expect(data.instance.administrator).to.equal('Kuja')
  84. expect(data.instance.maintenanceLifetime).to.equal('forever')
  85. expect(data.instance.businessModel).to.equal('my super business model')
  86. expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
  87. expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
  88. expect(data.instance.categories).to.deep.equal([ 1, 2 ])
  89. expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
  90. expect(data.instance.isNSFW).to.be.true
  91. expect(data.instance.defaultNSFWPolicy).to.equal('blur')
  92. expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
  93. expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
  94. expect(data.services.twitter.username).to.equal('@Kuja')
  95. expect(data.services.twitter.whitelisted).to.be.true
  96. expect(data.cache.previews.size).to.equal(2)
  97. expect(data.cache.captions.size).to.equal(3)
  98. expect(data.signup.enabled).to.be.false
  99. expect(data.signup.limit).to.equal(5)
  100. expect(data.signup.requiresEmailVerification).to.be.false
  101. // We override admin email in parallel tests, so skip this exception
  102. if (parallelTests() === false) {
  103. expect(data.admin.email).to.equal('superadmin1@example.com')
  104. }
  105. expect(data.contactForm.enabled).to.be.false
  106. expect(data.user.videoQuota).to.equal(5242881)
  107. expect(data.user.videoQuotaDaily).to.equal(318742)
  108. expect(data.transcoding.enabled).to.be.true
  109. expect(data.transcoding.threads).to.equal(1)
  110. expect(data.transcoding.allowAdditionalExtensions).to.be.true
  111. expect(data.transcoding.allowAudioFiles).to.be.true
  112. expect(data.transcoding.resolutions['240p']).to.be.false
  113. expect(data.transcoding.resolutions['360p']).to.be.true
  114. expect(data.transcoding.resolutions['480p']).to.be.true
  115. expect(data.transcoding.resolutions['720p']).to.be.false
  116. expect(data.transcoding.resolutions['1080p']).to.be.false
  117. expect(data.transcoding.resolutions['2160p']).to.be.false
  118. expect(data.transcoding.hls.enabled).to.be.false
  119. expect(data.transcoding.webtorrent.enabled).to.be.true
  120. expect(data.import.videos.http.enabled).to.be.false
  121. expect(data.import.videos.torrent.enabled).to.be.false
  122. expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
  123. expect(data.followers.instance.enabled).to.be.false
  124. expect(data.followers.instance.manualApproval).to.be.true
  125. expect(data.followings.instance.autoFollowBack.enabled).to.be.true
  126. expect(data.followings.instance.autoFollowIndex.enabled).to.be.true
  127. expect(data.followings.instance.autoFollowIndex.indexUrl).to.equal('https://updated.example.com')
  128. }
  129. describe('Test config', function () {
  130. let server = null
  131. before(async function () {
  132. this.timeout(30000)
  133. server = await flushAndRunServer(1)
  134. await setAccessTokensToServers([ server ])
  135. })
  136. it('Should have a correct config on a server with registration enabled', async function () {
  137. const res = await getConfig(server.url)
  138. const data: ServerConfig = res.body
  139. expect(data.signup.allowed).to.be.true
  140. })
  141. it('Should have a correct config on a server with registration enabled and a users limit', async function () {
  142. this.timeout(5000)
  143. await Promise.all([
  144. registerUser(server.url, 'user1', 'super password'),
  145. registerUser(server.url, 'user2', 'super password'),
  146. registerUser(server.url, 'user3', 'super password')
  147. ])
  148. const res = await getConfig(server.url)
  149. const data: ServerConfig = res.body
  150. expect(data.signup.allowed).to.be.false
  151. })
  152. it('Should have the correct video allowed extensions', async function () {
  153. const res = await getConfig(server.url)
  154. const data: ServerConfig = res.body
  155. expect(data.video.file.extensions).to.have.lengthOf(3)
  156. expect(data.video.file.extensions).to.contain('.mp4')
  157. expect(data.video.file.extensions).to.contain('.webm')
  158. expect(data.video.file.extensions).to.contain('.ogv')
  159. await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 400)
  160. await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 400)
  161. expect(data.contactForm.enabled).to.be.true
  162. })
  163. it('Should get the customized configuration', async function () {
  164. const res = await getCustomConfig(server.url, server.accessToken)
  165. const data = res.body as CustomConfig
  166. checkInitialConfig(server, data)
  167. })
  168. it('Should update the customized configuration', async function () {
  169. const newCustomConfig: CustomConfig = {
  170. instance: {
  171. name: 'PeerTube updated',
  172. shortDescription: 'my short description',
  173. description: 'my super description',
  174. terms: 'my super terms',
  175. codeOfConduct: 'my super coc',
  176. creationReason: 'my super creation reason',
  177. moderationInformation: 'my super moderation information',
  178. administrator: 'Kuja',
  179. maintenanceLifetime: 'forever',
  180. businessModel: 'my super business model',
  181. hardwareInformation: '2vCore 3GB RAM',
  182. languages: [ 'en', 'es' ],
  183. categories: [ 1, 2 ],
  184. defaultClientRoute: '/videos/recently-added',
  185. isNSFW: true,
  186. defaultNSFWPolicy: 'blur' as 'blur',
  187. customizations: {
  188. javascript: 'alert("coucou")',
  189. css: 'body { background-color: red; }'
  190. }
  191. },
  192. theme: {
  193. default: 'default'
  194. },
  195. services: {
  196. twitter: {
  197. username: '@Kuja',
  198. whitelisted: true
  199. }
  200. },
  201. cache: {
  202. previews: {
  203. size: 2
  204. },
  205. captions: {
  206. size: 3
  207. }
  208. },
  209. signup: {
  210. enabled: false,
  211. limit: 5,
  212. requiresEmailVerification: false
  213. },
  214. admin: {
  215. email: 'superadmin1@example.com'
  216. },
  217. contactForm: {
  218. enabled: false
  219. },
  220. user: {
  221. videoQuota: 5242881,
  222. videoQuotaDaily: 318742
  223. },
  224. transcoding: {
  225. enabled: true,
  226. allowAdditionalExtensions: true,
  227. allowAudioFiles: true,
  228. threads: 1,
  229. resolutions: {
  230. '240p': false,
  231. '360p': true,
  232. '480p': true,
  233. '720p': false,
  234. '1080p': false,
  235. '2160p': false
  236. },
  237. webtorrent: {
  238. enabled: true
  239. },
  240. hls: {
  241. enabled: false
  242. }
  243. },
  244. import: {
  245. videos: {
  246. http: {
  247. enabled: false
  248. },
  249. torrent: {
  250. enabled: false
  251. }
  252. }
  253. },
  254. autoBlacklist: {
  255. videos: {
  256. ofUsers: {
  257. enabled: true
  258. }
  259. }
  260. },
  261. followers: {
  262. instance: {
  263. enabled: false,
  264. manualApproval: true
  265. }
  266. },
  267. followings: {
  268. instance: {
  269. autoFollowBack: {
  270. enabled: true
  271. },
  272. autoFollowIndex: {
  273. enabled: true,
  274. indexUrl: 'https://updated.example.com'
  275. }
  276. }
  277. }
  278. }
  279. await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
  280. const res = await getCustomConfig(server.url, server.accessToken)
  281. const data = res.body
  282. checkUpdatedConfig(data)
  283. })
  284. it('Should have the correct updated video allowed extensions', async function () {
  285. const res = await getConfig(server.url)
  286. const data: ServerConfig = res.body
  287. expect(data.video.file.extensions).to.have.length.above(3)
  288. expect(data.video.file.extensions).to.contain('.mp4')
  289. expect(data.video.file.extensions).to.contain('.webm')
  290. expect(data.video.file.extensions).to.contain('.ogv')
  291. expect(data.video.file.extensions).to.contain('.flv')
  292. expect(data.video.file.extensions).to.contain('.mkv')
  293. expect(data.video.file.extensions).to.contain('.mp3')
  294. expect(data.video.file.extensions).to.contain('.ogg')
  295. expect(data.video.file.extensions).to.contain('.flac')
  296. await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, 200)
  297. await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, 200)
  298. })
  299. it('Should have the configuration updated after a restart', async function () {
  300. this.timeout(10000)
  301. killallServers([ server ])
  302. await reRunServer(server)
  303. const res = await getCustomConfig(server.url, server.accessToken)
  304. const data = res.body
  305. checkUpdatedConfig(data)
  306. })
  307. it('Should fetch the about information', async function () {
  308. const res = await getAbout(server.url)
  309. const data: About = res.body
  310. expect(data.instance.name).to.equal('PeerTube updated')
  311. expect(data.instance.shortDescription).to.equal('my short description')
  312. expect(data.instance.description).to.equal('my super description')
  313. expect(data.instance.terms).to.equal('my super terms')
  314. expect(data.instance.codeOfConduct).to.equal('my super coc')
  315. expect(data.instance.creationReason).to.equal('my super creation reason')
  316. expect(data.instance.moderationInformation).to.equal('my super moderation information')
  317. expect(data.instance.administrator).to.equal('Kuja')
  318. expect(data.instance.maintenanceLifetime).to.equal('forever')
  319. expect(data.instance.businessModel).to.equal('my super business model')
  320. expect(data.instance.hardwareInformation).to.equal('2vCore 3GB RAM')
  321. expect(data.instance.languages).to.deep.equal([ 'en', 'es' ])
  322. expect(data.instance.categories).to.deep.equal([ 1, 2 ])
  323. })
  324. it('Should remove the custom configuration', async function () {
  325. this.timeout(10000)
  326. await deleteCustomConfig(server.url, server.accessToken)
  327. const res = await getCustomConfig(server.url, server.accessToken)
  328. const data = res.body
  329. checkInitialConfig(server, data)
  330. })
  331. after(async function () {
  332. await cleanupTests([ server ])
  333. })
  334. })