]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { | |
6 | ChangeOwnershipCommand, | |
7 | cleanupTests, | |
8 | createMultipleServers, | |
9 | createSingleServer, | |
10 | doubleFollow, | |
11 | PeerTubeServer, | |
12 | setAccessTokensToServers, | |
13 | setDefaultVideoChannel, | |
14 | waitJobs | |
15 | } from '@shared/extra-utils' | |
16 | import { HttpStatusCode, VideoPrivacy } from '@shared/models' | |
17 | ||
18 | const expect = chai.expect | |
19 | ||
20 | describe('Test video change ownership - nominal', function () { | |
21 | let servers: PeerTubeServer[] = [] | |
22 | ||
23 | const firstUser = 'first' | |
24 | const secondUser = 'second' | |
25 | ||
26 | let firstUserToken = '' | |
27 | let firstUserChannelId: number | |
28 | ||
29 | let secondUserToken = '' | |
30 | let secondUserChannelId: number | |
31 | ||
32 | let lastRequestId: number | |
33 | ||
34 | let liveId: number | |
35 | ||
36 | let command: ChangeOwnershipCommand | |
37 | ||
38 | before(async function () { | |
39 | this.timeout(50000) | |
40 | ||
41 | servers = await createMultipleServers(2) | |
42 | await setAccessTokensToServers(servers) | |
43 | await setDefaultVideoChannel(servers) | |
44 | ||
45 | await servers[0].config.updateCustomSubConfig({ | |
46 | newConfig: { | |
47 | transcoding: { | |
48 | enabled: false | |
49 | }, | |
50 | live: { | |
51 | enabled: true | |
52 | } | |
53 | } | |
54 | }) | |
55 | ||
56 | firstUserToken = await servers[0].users.generateUserAndToken(firstUser) | |
57 | secondUserToken = await servers[0].users.generateUserAndToken(secondUser) | |
58 | ||
59 | { | |
60 | const { videoChannels } = await servers[0].users.getMyInfo({ token: firstUserToken }) | |
61 | firstUserChannelId = videoChannels[0].id | |
62 | } | |
63 | ||
64 | { | |
65 | const { videoChannels } = await servers[0].users.getMyInfo({ token: secondUserToken }) | |
66 | secondUserChannelId = videoChannels[0].id | |
67 | } | |
68 | ||
69 | { | |
70 | const attributes = { | |
71 | name: 'my super name', | |
72 | description: 'my super description' | |
73 | } | |
74 | const { id } = await servers[0].videos.upload({ token: firstUserToken, attributes }) | |
75 | ||
76 | servers[0].store.videoCreated = await servers[0].videos.get({ id }) | |
77 | } | |
78 | ||
79 | { | |
80 | const attributes = { name: 'live', channelId: firstUserChannelId, privacy: VideoPrivacy.PUBLIC } | |
81 | const video = await servers[0].live.create({ token: firstUserToken, fields: attributes }) | |
82 | ||
83 | liveId = video.id | |
84 | } | |
85 | ||
86 | command = servers[0].changeOwnership | |
87 | ||
88 | await doubleFollow(servers[0], servers[1]) | |
89 | }) | |
90 | ||
91 | it('Should not have video change ownership', async function () { | |
92 | { | |
93 | const body = await command.list({ token: firstUserToken }) | |
94 | ||
95 | expect(body.total).to.equal(0) | |
96 | expect(body.data).to.be.an('array') | |
97 | expect(body.data.length).to.equal(0) | |
98 | } | |
99 | ||
100 | { | |
101 | const body = await command.list({ token: secondUserToken }) | |
102 | ||
103 | expect(body.total).to.equal(0) | |
104 | expect(body.data).to.be.an('array') | |
105 | expect(body.data.length).to.equal(0) | |
106 | } | |
107 | }) | |
108 | ||
109 | it('Should send a request to change ownership of a video', async function () { | |
110 | this.timeout(15000) | |
111 | ||
112 | await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser }) | |
113 | }) | |
114 | ||
115 | it('Should only return a request to change ownership for the second user', async function () { | |
116 | { | |
117 | const body = await command.list({ token: firstUserToken }) | |
118 | ||
119 | expect(body.total).to.equal(0) | |
120 | expect(body.data).to.be.an('array') | |
121 | expect(body.data.length).to.equal(0) | |
122 | } | |
123 | ||
124 | { | |
125 | const body = await command.list({ token: secondUserToken }) | |
126 | ||
127 | expect(body.total).to.equal(1) | |
128 | expect(body.data).to.be.an('array') | |
129 | expect(body.data.length).to.equal(1) | |
130 | ||
131 | lastRequestId = body.data[0].id | |
132 | } | |
133 | }) | |
134 | ||
135 | it('Should accept the same change ownership request without crashing', async function () { | |
136 | this.timeout(10000) | |
137 | ||
138 | await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser }) | |
139 | }) | |
140 | ||
141 | it('Should not create multiple change ownership requests while one is waiting', async function () { | |
142 | this.timeout(10000) | |
143 | ||
144 | const body = await command.list({ token: secondUserToken }) | |
145 | ||
146 | expect(body.total).to.equal(1) | |
147 | expect(body.data).to.be.an('array') | |
148 | expect(body.data.length).to.equal(1) | |
149 | }) | |
150 | ||
151 | it('Should not be possible to refuse the change of ownership from first user', async function () { | |
152 | this.timeout(10000) | |
153 | ||
154 | await command.refuse({ token: firstUserToken, ownershipId: lastRequestId, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
155 | }) | |
156 | ||
157 | it('Should be possible to refuse the change of ownership from second user', async function () { | |
158 | this.timeout(10000) | |
159 | ||
160 | await command.refuse({ token: secondUserToken, ownershipId: lastRequestId }) | |
161 | }) | |
162 | ||
163 | it('Should send a new request to change ownership of a video', async function () { | |
164 | this.timeout(15000) | |
165 | ||
166 | await command.create({ token: firstUserToken, videoId: servers[0].store.videoCreated.id, username: secondUser }) | |
167 | }) | |
168 | ||
169 | it('Should return two requests to change ownership for the second user', async function () { | |
170 | { | |
171 | const body = await command.list({ token: firstUserToken }) | |
172 | ||
173 | expect(body.total).to.equal(0) | |
174 | expect(body.data).to.be.an('array') | |
175 | expect(body.data.length).to.equal(0) | |
176 | } | |
177 | ||
178 | { | |
179 | const body = await command.list({ token: secondUserToken }) | |
180 | ||
181 | expect(body.total).to.equal(2) | |
182 | expect(body.data).to.be.an('array') | |
183 | expect(body.data.length).to.equal(2) | |
184 | ||
185 | lastRequestId = body.data[0].id | |
186 | } | |
187 | }) | |
188 | ||
189 | it('Should not be possible to accept the change of ownership from first user', async function () { | |
190 | this.timeout(10000) | |
191 | ||
192 | await command.accept({ | |
193 | token: firstUserToken, | |
194 | ownershipId: lastRequestId, | |
195 | channelId: secondUserChannelId, | |
196 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
197 | }) | |
198 | }) | |
199 | ||
200 | it('Should be possible to accept the change of ownership from second user', async function () { | |
201 | this.timeout(10000) | |
202 | ||
203 | await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId }) | |
204 | ||
205 | await waitJobs(servers) | |
206 | }) | |
207 | ||
208 | it('Should have the channel of the video updated', async function () { | |
209 | for (const server of servers) { | |
210 | const video = await server.videos.get({ id: servers[0].store.videoCreated.uuid }) | |
211 | ||
212 | expect(video.name).to.equal('my super name') | |
213 | expect(video.channel.displayName).to.equal('Main second channel') | |
214 | expect(video.channel.name).to.equal('second_channel') | |
215 | } | |
216 | }) | |
217 | ||
218 | it('Should send a request to change ownership of a live', async function () { | |
219 | this.timeout(15000) | |
220 | ||
221 | await command.create({ token: firstUserToken, videoId: liveId, username: secondUser }) | |
222 | ||
223 | const body = await command.list({ token: secondUserToken }) | |
224 | ||
225 | expect(body.total).to.equal(3) | |
226 | expect(body.data.length).to.equal(3) | |
227 | ||
228 | lastRequestId = body.data[0].id | |
229 | }) | |
230 | ||
231 | it('Should accept a live ownership change', async function () { | |
232 | this.timeout(20000) | |
233 | ||
234 | await command.accept({ token: secondUserToken, ownershipId: lastRequestId, channelId: secondUserChannelId }) | |
235 | ||
236 | await waitJobs(servers) | |
237 | ||
238 | for (const server of servers) { | |
239 | const video = await server.videos.get({ id: servers[0].store.videoCreated.uuid }) | |
240 | ||
241 | expect(video.name).to.equal('my super name') | |
242 | expect(video.channel.displayName).to.equal('Main second channel') | |
243 | expect(video.channel.name).to.equal('second_channel') | |
244 | } | |
245 | }) | |
246 | ||
247 | after(async function () { | |
248 | await cleanupTests(servers) | |
249 | }) | |
250 | }) | |
251 | ||
252 | describe('Test video change ownership - quota too small', function () { | |
253 | let server: PeerTubeServer | |
254 | const firstUser = 'first' | |
255 | const secondUser = 'second' | |
256 | ||
257 | let firstUserToken = '' | |
258 | let secondUserToken = '' | |
259 | let lastRequestId: number | |
260 | ||
261 | before(async function () { | |
262 | this.timeout(50000) | |
263 | ||
264 | // Run one server | |
265 | server = await createSingleServer(1) | |
266 | await setAccessTokensToServers([ server ]) | |
267 | ||
268 | await server.users.create({ username: secondUser, videoQuota: 10 }) | |
269 | ||
270 | firstUserToken = await server.users.generateUserAndToken(firstUser) | |
271 | secondUserToken = await server.login.getAccessToken(secondUser) | |
272 | ||
273 | // Upload some videos on the server | |
274 | const attributes = { | |
275 | name: 'my super name', | |
276 | description: 'my super description' | |
277 | } | |
278 | await server.videos.upload({ token: firstUserToken, attributes }) | |
279 | ||
280 | await waitJobs(server) | |
281 | ||
282 | const { data } = await server.videos.list() | |
283 | expect(data.length).to.equal(1) | |
284 | ||
285 | server.store.videoCreated = data.find(video => video.name === 'my super name') | |
286 | }) | |
287 | ||
288 | it('Should send a request to change ownership of a video', async function () { | |
289 | this.timeout(15000) | |
290 | ||
291 | await server.changeOwnership.create({ token: firstUserToken, videoId: server.store.videoCreated.id, username: secondUser }) | |
292 | }) | |
293 | ||
294 | it('Should only return a request to change ownership for the second user', async function () { | |
295 | { | |
296 | const body = await server.changeOwnership.list({ token: firstUserToken }) | |
297 | ||
298 | expect(body.total).to.equal(0) | |
299 | expect(body.data).to.be.an('array') | |
300 | expect(body.data.length).to.equal(0) | |
301 | } | |
302 | ||
303 | { | |
304 | const body = await server.changeOwnership.list({ token: secondUserToken }) | |
305 | ||
306 | expect(body.total).to.equal(1) | |
307 | expect(body.data).to.be.an('array') | |
308 | expect(body.data.length).to.equal(1) | |
309 | ||
310 | lastRequestId = body.data[0].id | |
311 | } | |
312 | }) | |
313 | ||
314 | it('Should not be possible to accept the change of ownership from second user because of exceeded quota', async function () { | |
315 | this.timeout(10000) | |
316 | ||
317 | const { videoChannels } = await server.users.getMyInfo({ token: secondUserToken }) | |
318 | const channelId = videoChannels[0].id | |
319 | ||
320 | await server.changeOwnership.accept({ | |
321 | token: secondUserToken, | |
322 | ownershipId: lastRequestId, | |
323 | channelId, | |
324 | expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413 | |
325 | }) | |
326 | }) | |
327 | ||
328 | after(async function () { | |
329 | await cleanupTests([ server ]) | |
330 | }) | |
331 | }) |