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