diff options
author | Chocobozzz <me@florianbigard.com> | 2022-11-07 10:11:51 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-11-07 10:11:51 +0100 |
commit | 11ae7e2917ddf6e3c8e53d0855fd786163112d59 (patch) | |
tree | a0fb395434fb6003889ffcd8eaa4ac94ac5592ad /server | |
parent | 0015924ad67d30bbc2d6966427794f5e1143e70f (diff) | |
download | PeerTube-11ae7e2917ddf6e3c8e53d0855fd786163112d59.tar.gz PeerTube-11ae7e2917ddf6e3c8e53d0855fd786163112d59.tar.zst PeerTube-11ae7e2917ddf6e3c8e53d0855fd786163112d59.zip |
Fix follow constraint check with an account
Diffstat (limited to 'server')
-rw-r--r-- | server/models/video/video.ts | 6 | ||||
-rw-r--r-- | server/tests/api/server/follow-constraints.ts | 88 |
2 files changed, 93 insertions, 1 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 2ff92cbf1..f3907bed4 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -1458,6 +1458,12 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> { | |||
1458 | const query = 'SELECT 1 FROM "videoShare" ' + | 1458 | const query = 'SELECT 1 FROM "videoShare" ' + |
1459 | 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' + | 1459 | 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' + |
1460 | 'WHERE "actorFollow"."actorId" = $followerActorId AND "actorFollow"."state" = \'accepted\' AND "videoShare"."videoId" = $videoId ' + | 1460 | 'WHERE "actorFollow"."actorId" = $followerActorId AND "actorFollow"."state" = \'accepted\' AND "videoShare"."videoId" = $videoId ' + |
1461 | 'UNION ' + | ||
1462 | 'SELECT 1 FROM "video" ' + | ||
1463 | 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' + | ||
1464 | 'INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId" ' + | ||
1465 | 'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "account"."actorId" ' + | ||
1466 | 'WHERE "actorFollow"."actorId" = $followerActorId AND "actorFollow"."state" = \'accepted\' AND "video"."id" = $videoId ' + | ||
1461 | 'LIMIT 1' | 1467 | 'LIMIT 1' |
1462 | 1468 | ||
1463 | const options = { | 1469 | const options = { |
diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts index 5998f58cc..e1ec2b069 100644 --- a/server/tests/api/server/follow-constraints.ts +++ b/server/tests/api/server/follow-constraints.ts | |||
@@ -1,8 +1,15 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
4 | import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' | ||
5 | import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' | 4 | import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models' |
5 | import { | ||
6 | cleanupTests, | ||
7 | createMultipleServers, | ||
8 | doubleFollow, | ||
9 | PeerTubeServer, | ||
10 | setAccessTokensToServers, | ||
11 | waitJobs | ||
12 | } from '@shared/server-commands' | ||
6 | 13 | ||
7 | describe('Test follow constraints', function () { | 14 | describe('Test follow constraints', function () { |
8 | let servers: PeerTubeServer[] = [] | 15 | let servers: PeerTubeServer[] = [] |
@@ -189,6 +196,7 @@ describe('Test follow constraints', function () { | |||
189 | }) | 196 | }) |
190 | 197 | ||
191 | describe('With a logged user', function () { | 198 | describe('With a logged user', function () { |
199 | |||
192 | it('Should get the local video', async function () { | 200 | it('Should get the local video', async function () { |
193 | await servers[0].videos.getWithToken({ token: userToken, id: video1UUID }) | 201 | await servers[0].videos.getWithToken({ token: userToken, id: video1UUID }) |
194 | }) | 202 | }) |
@@ -229,6 +237,84 @@ describe('Test follow constraints', function () { | |||
229 | }) | 237 | }) |
230 | }) | 238 | }) |
231 | 239 | ||
240 | describe('When following a remote account', function () { | ||
241 | |||
242 | before(async function () { | ||
243 | this.timeout(60000) | ||
244 | |||
245 | await servers[0].follows.follow({ handles: [ 'root@' + servers[1].host ] }) | ||
246 | await waitJobs(servers) | ||
247 | }) | ||
248 | |||
249 | it('Should get the remote video with an unlogged user', async function () { | ||
250 | await servers[0].videos.get({ id: video2UUID }) | ||
251 | }) | ||
252 | |||
253 | it('Should get the remote video with a logged in user', async function () { | ||
254 | await servers[0].videos.getWithToken({ token: userToken, id: video2UUID }) | ||
255 | }) | ||
256 | }) | ||
257 | |||
258 | describe('When unfollowing a remote account', function () { | ||
259 | |||
260 | before(async function () { | ||
261 | this.timeout(60000) | ||
262 | |||
263 | await servers[0].follows.unfollow({ target: 'root@' + servers[1].host }) | ||
264 | await waitJobs(servers) | ||
265 | }) | ||
266 | |||
267 | it('Should not get the remote video with an unlogged user', async function () { | ||
268 | const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | ||
269 | |||
270 | const error = body as unknown as PeerTubeProblemDocument | ||
271 | expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS) | ||
272 | }) | ||
273 | |||
274 | it('Should get the remote video with a logged in user', async function () { | ||
275 | await servers[0].videos.getWithToken({ token: userToken, id: video2UUID }) | ||
276 | }) | ||
277 | }) | ||
278 | |||
279 | describe('When following a remote channel', function () { | ||
280 | |||
281 | before(async function () { | ||
282 | this.timeout(60000) | ||
283 | |||
284 | await servers[0].follows.follow({ handles: [ 'root_channel@' + servers[1].host ] }) | ||
285 | await waitJobs(servers) | ||
286 | }) | ||
287 | |||
288 | it('Should get the remote video with an unlogged user', async function () { | ||
289 | await servers[0].videos.get({ id: video2UUID }) | ||
290 | }) | ||
291 | |||
292 | it('Should get the remote video with a logged in user', async function () { | ||
293 | await servers[0].videos.getWithToken({ token: userToken, id: video2UUID }) | ||
294 | }) | ||
295 | }) | ||
296 | |||
297 | describe('When unfollowing a remote channel', function () { | ||
298 | |||
299 | before(async function () { | ||
300 | this.timeout(60000) | ||
301 | |||
302 | await servers[0].follows.unfollow({ target: 'root_channel@' + servers[1].host }) | ||
303 | await waitJobs(servers) | ||
304 | }) | ||
305 | |||
306 | it('Should not get the remote video with an unlogged user', async function () { | ||
307 | const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | ||
308 | |||
309 | const error = body as unknown as PeerTubeProblemDocument | ||
310 | expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS) | ||
311 | }) | ||
312 | |||
313 | it('Should get the remote video with a logged in user', async function () { | ||
314 | await servers[0].videos.getWithToken({ token: userToken, id: video2UUID }) | ||
315 | }) | ||
316 | }) | ||
317 | |||
232 | after(async function () { | 318 | after(async function () { |
233 | await cleanupTests(servers) | 319 | await cleanupTests(servers) |
234 | }) | 320 | }) |