config.ts 14 KB

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