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