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