aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
committerChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
commita24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch)
treea54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tests/api/activitypub
parent5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff)
parentc63830f15403ac4e750829f27d8bbbdc9a59282c (diff)
downloadPeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip
Merge branch 'next' into develop
Diffstat (limited to 'server/tests/api/activitypub')
-rw-r--r--server/tests/api/activitypub/cleaner.ts105
-rw-r--r--server/tests/api/activitypub/client.ts24
-rw-r--r--server/tests/api/activitypub/fetch.ts51
-rw-r--r--server/tests/api/activitypub/helpers.ts5
-rw-r--r--server/tests/api/activitypub/refresher.ts96
-rw-r--r--server/tests/api/activitypub/security.ts46
6 files changed, 135 insertions, 192 deletions
diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts
index 75ef56ce3..51cf6e599 100644
--- a/server/tests/api/activitypub/cleaner.ts
+++ b/server/tests/api/activitypub/cleaner.ts
@@ -4,24 +4,18 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { 5import {
6 cleanupTests, 6 cleanupTests,
7 closeAllSequelize, 7 createMultipleServers,
8 deleteAll,
9 doubleFollow, 8 doubleFollow,
10 getCount, 9 PeerTubeServer,
11 selectQuery, 10 setAccessTokensToServers,
12 setVideoField, 11 wait,
13 updateQuery, 12 waitJobs
14 wait 13} from '@shared/extra-utils'
15} from '../../../../shared/extra-utils'
16import { flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
17import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
18import { addVideoCommentThread, getVideoCommentThreads } from '../../../../shared/extra-utils/videos/video-comments'
19import { getVideo, rateVideo, uploadVideoAndGetId } from '../../../../shared/extra-utils/videos/videos'
20 14
21const expect = chai.expect 15const expect = chai.expect
22 16
23describe('Test AP cleaner', function () { 17describe('Test AP cleaner', function () {
24 let servers: ServerInfo[] = [] 18 let servers: PeerTubeServer[] = []
25 let videoUUID1: string 19 let videoUUID1: string
26 let videoUUID2: string 20 let videoUUID2: string
27 let videoUUID3: string 21 let videoUUID3: string
@@ -36,7 +30,7 @@ describe('Test AP cleaner', function () {
36 videos: { cleanup_remote_interactions: true } 30 videos: { cleanup_remote_interactions: true }
37 } 31 }
38 } 32 }
39 servers = await flushAndRunMultipleServers(3, config) 33 servers = await createMultipleServers(3, config)
40 34
41 // Get the access tokens 35 // Get the access tokens
42 await setAccessTokensToServers(servers) 36 await setAccessTokensToServers(servers)
@@ -52,9 +46,9 @@ describe('Test AP cleaner', function () {
52 // Create 1 comment per video 46 // Create 1 comment per video
53 // Update 1 remote URL and 1 local URL on 47 // Update 1 remote URL and 1 local URL on
54 48
55 videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'server 1' })).uuid 49 videoUUID1 = (await servers[0].videos.quickUpload({ name: 'server 1' })).uuid
56 videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid 50 videoUUID2 = (await servers[1].videos.quickUpload({ name: 'server 2' })).uuid
57 videoUUID3 = (await uploadVideoAndGetId({ server: servers[2], videoName: 'server 3' })).uuid 51 videoUUID3 = (await servers[2].videos.quickUpload({ name: 'server 3' })).uuid
58 52
59 videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ] 53 videoUUIDs = [ videoUUID1, videoUUID2, videoUUID3 ]
60 54
@@ -62,8 +56,8 @@ describe('Test AP cleaner', function () {
62 56
63 for (const server of servers) { 57 for (const server of servers) {
64 for (const uuid of videoUUIDs) { 58 for (const uuid of videoUUIDs) {
65 await rateVideo(server.url, server.accessToken, uuid, 'like') 59 await server.videos.rate({ id: uuid, rating: 'like' })
66 await addVideoCommentThread(server.url, server.accessToken, uuid, 'comment') 60 await server.comments.createThread({ videoId: uuid, text: 'comment' })
67 } 61 }
68 } 62 }
69 63
@@ -73,9 +67,10 @@ describe('Test AP cleaner', function () {
73 it('Should have the correct likes', async function () { 67 it('Should have the correct likes', async function () {
74 for (const server of servers) { 68 for (const server of servers) {
75 for (const uuid of videoUUIDs) { 69 for (const uuid of videoUUIDs) {
76 const res = await getVideo(server.url, uuid) 70 const video = await server.videos.get({ id: uuid })
77 expect(res.body.likes).to.equal(3) 71
78 expect(res.body.dislikes).to.equal(0) 72 expect(video.likes).to.equal(3)
73 expect(video.dislikes).to.equal(0)
79 } 74 }
80 } 75 }
81 }) 76 })
@@ -83,9 +78,9 @@ describe('Test AP cleaner', function () {
83 it('Should destroy server 3 internal likes and correctly clean them', async function () { 78 it('Should destroy server 3 internal likes and correctly clean them', async function () {
84 this.timeout(20000) 79 this.timeout(20000)
85 80
86 await deleteAll(servers[2].internalServerNumber, 'accountVideoRate') 81 await servers[2].sql.deleteAll('accountVideoRate')
87 for (const uuid of videoUUIDs) { 82 for (const uuid of videoUUIDs) {
88 await setVideoField(servers[2].internalServerNumber, uuid, 'likes', '0') 83 await servers[2].sql.setVideoField(uuid, 'likes', '0')
89 } 84 }
90 85
91 await wait(5000) 86 await wait(5000)
@@ -93,16 +88,16 @@ describe('Test AP cleaner', function () {
93 88
94 // Updated rates of my video 89 // Updated rates of my video
95 { 90 {
96 const res = await getVideo(servers[0].url, videoUUID1) 91 const video = await servers[0].videos.get({ id: videoUUID1 })
97 expect(res.body.likes).to.equal(2) 92 expect(video.likes).to.equal(2)
98 expect(res.body.dislikes).to.equal(0) 93 expect(video.dislikes).to.equal(0)
99 } 94 }
100 95
101 // Did not update rates of a remote video 96 // Did not update rates of a remote video
102 { 97 {
103 const res = await getVideo(servers[0].url, videoUUID2) 98 const video = await servers[0].videos.get({ id: videoUUID2 })
104 expect(res.body.likes).to.equal(3) 99 expect(video.likes).to.equal(3)
105 expect(res.body.dislikes).to.equal(0) 100 expect(video.dislikes).to.equal(0)
106 } 101 }
107 }) 102 })
108 103
@@ -111,7 +106,7 @@ describe('Test AP cleaner', function () {
111 106
112 for (const server of servers) { 107 for (const server of servers) {
113 for (const uuid of videoUUIDs) { 108 for (const uuid of videoUUIDs) {
114 await rateVideo(server.url, server.accessToken, uuid, 'dislike') 109 await server.videos.rate({ id: uuid, rating: 'dislike' })
115 } 110 }
116 } 111 }
117 112
@@ -119,9 +114,9 @@ describe('Test AP cleaner', function () {
119 114
120 for (const server of servers) { 115 for (const server of servers) {
121 for (const uuid of videoUUIDs) { 116 for (const uuid of videoUUIDs) {
122 const res = await getVideo(server.url, uuid) 117 const video = await server.videos.get({ id: uuid })
123 expect(res.body.likes).to.equal(0) 118 expect(video.likes).to.equal(0)
124 expect(res.body.dislikes).to.equal(3) 119 expect(video.dislikes).to.equal(3)
125 } 120 }
126 } 121 }
127 }) 122 })
@@ -129,10 +124,10 @@ describe('Test AP cleaner', function () {
129 it('Should destroy server 3 internal dislikes and correctly clean them', async function () { 124 it('Should destroy server 3 internal dislikes and correctly clean them', async function () {
130 this.timeout(20000) 125 this.timeout(20000)
131 126
132 await deleteAll(servers[2].internalServerNumber, 'accountVideoRate') 127 await servers[2].sql.deleteAll('accountVideoRate')
133 128
134 for (const uuid of videoUUIDs) { 129 for (const uuid of videoUUIDs) {
135 await setVideoField(servers[2].internalServerNumber, uuid, 'dislikes', '0') 130 await servers[2].sql.setVideoField(uuid, 'dislikes', '0')
136 } 131 }
137 132
138 await wait(5000) 133 await wait(5000)
@@ -140,31 +135,31 @@ describe('Test AP cleaner', function () {
140 135
141 // Updated rates of my video 136 // Updated rates of my video
142 { 137 {
143 const res = await getVideo(servers[0].url, videoUUID1) 138 const video = await servers[0].videos.get({ id: videoUUID1 })
144 expect(res.body.likes).to.equal(0) 139 expect(video.likes).to.equal(0)
145 expect(res.body.dislikes).to.equal(2) 140 expect(video.dislikes).to.equal(2)
146 } 141 }
147 142
148 // Did not update rates of a remote video 143 // Did not update rates of a remote video
149 { 144 {
150 const res = await getVideo(servers[0].url, videoUUID2) 145 const video = await servers[0].videos.get({ id: videoUUID2 })
151 expect(res.body.likes).to.equal(0) 146 expect(video.likes).to.equal(0)
152 expect(res.body.dislikes).to.equal(3) 147 expect(video.dislikes).to.equal(3)
153 } 148 }
154 }) 149 })
155 150
156 it('Should destroy server 3 internal shares and correctly clean them', async function () { 151 it('Should destroy server 3 internal shares and correctly clean them', async function () {
157 this.timeout(20000) 152 this.timeout(20000)
158 153
159 const preCount = await getCount(servers[0].internalServerNumber, 'videoShare') 154 const preCount = await servers[0].sql.getCount('videoShare')
160 expect(preCount).to.equal(6) 155 expect(preCount).to.equal(6)
161 156
162 await deleteAll(servers[2].internalServerNumber, 'videoShare') 157 await servers[2].sql.deleteAll('videoShare')
163 await wait(5000) 158 await wait(5000)
164 await waitJobs(servers) 159 await waitJobs(servers)
165 160
166 // Still 6 because we don't have remote shares on local videos 161 // Still 6 because we don't have remote shares on local videos
167 const postCount = await getCount(servers[0].internalServerNumber, 'videoShare') 162 const postCount = await servers[0].sql.getCount('videoShare')
168 expect(postCount).to.equal(6) 163 expect(postCount).to.equal(6)
169 }) 164 })
170 165
@@ -172,18 +167,18 @@ describe('Test AP cleaner', function () {
172 this.timeout(20000) 167 this.timeout(20000)
173 168
174 { 169 {
175 const res = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5) 170 const { total } = await servers[0].comments.listThreads({ videoId: videoUUID1 })
176 expect(res.body.total).to.equal(3) 171 expect(total).to.equal(3)
177 } 172 }
178 173
179 await deleteAll(servers[2].internalServerNumber, 'videoComment') 174 await servers[2].sql.deleteAll('videoComment')
180 175
181 await wait(5000) 176 await wait(5000)
182 await waitJobs(servers) 177 await waitJobs(servers)
183 178
184 { 179 {
185 const res = await getVideoCommentThreads(servers[0].url, videoUUID1, 0, 5) 180 const { total } = await servers[0].comments.listThreads({ videoId: videoUUID1 })
186 expect(res.body.total).to.equal(2) 181 expect(total).to.equal(2)
187 } 182 }
188 }) 183 })
189 184
@@ -193,7 +188,7 @@ describe('Test AP cleaner', function () {
193 async function check (like: string, ofServerUrl: string, urlSuffix: string, remote: 'true' | 'false') { 188 async function check (like: string, ofServerUrl: string, urlSuffix: string, remote: 'true' | 'false') {
194 const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` + 189 const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` +
195 `INNER JOIN video ON "accountVideoRate"."videoId" = video.id AND remote IS ${remote} WHERE "accountVideoRate"."url" LIKE '${like}'` 190 `INNER JOIN video ON "accountVideoRate"."videoId" = video.id AND remote IS ${remote} WHERE "accountVideoRate"."url" LIKE '${like}'`
196 const res = await selectQuery(servers[0].internalServerNumber, query) 191 const res = await servers[0].sql.selectQuery(query)
197 192
198 for (const rate of res) { 193 for (const rate of res) {
199 const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`) 194 const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`)
@@ -222,7 +217,7 @@ describe('Test AP cleaner', function () {
222 217
223 { 218 {
224 const query = `UPDATE "accountVideoRate" SET url = url || 'stan'` 219 const query = `UPDATE "accountVideoRate" SET url = url || 'stan'`
225 await updateQuery(servers[1].internalServerNumber, query) 220 await servers[1].sql.updateQuery(query)
226 221
227 await wait(5000) 222 await wait(5000)
228 await waitJobs(servers) 223 await waitJobs(servers)
@@ -239,7 +234,7 @@ describe('Test AP cleaner', function () {
239 const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` + 234 const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` +
240 `INNER JOIN video ON "videoComment"."videoId" = video.id AND remote IS ${remote} WHERE "videoComment"."url" LIKE '${like}'` 235 `INNER JOIN video ON "videoComment"."videoId" = video.id AND remote IS ${remote} WHERE "videoComment"."url" LIKE '${like}'`
241 236
242 const res = await selectQuery(servers[0].internalServerNumber, query) 237 const res = await servers[0].sql.selectQuery(query)
243 238
244 for (const comment of res) { 239 for (const comment of res) {
245 const matcher = new RegExp(`${ofServerUrl}/videos/watch/${comment.videoUUID}/comments/\\d+${urlSuffix}`) 240 const matcher = new RegExp(`${ofServerUrl}/videos/watch/${comment.videoUUID}/comments/\\d+${urlSuffix}`)
@@ -265,7 +260,7 @@ describe('Test AP cleaner', function () {
265 260
266 { 261 {
267 const query = `UPDATE "videoComment" SET url = url || 'kyle'` 262 const query = `UPDATE "videoComment" SET url = url || 'kyle'`
268 await updateQuery(servers[1].internalServerNumber, query) 263 await servers[1].sql.updateQuery(query)
269 264
270 await wait(5000) 265 await wait(5000)
271 await waitJobs(servers) 266 await waitJobs(servers)
@@ -277,7 +272,5 @@ describe('Test AP cleaner', function () {
277 272
278 after(async function () { 273 after(async function () {
279 await cleanupTests(servers) 274 await cleanupTests(servers)
280
281 await closeAllSequelize(servers)
282 }) 275 })
283}) 276})
diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts
index be94e219c..c3e4b7f74 100644
--- a/server/tests/api/activitypub/client.ts
+++ b/server/tests/api/activitypub/client.ts
@@ -2,24 +2,21 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoPlaylistPrivacy } from '@shared/models'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 5import {
8 cleanupTests, 6 cleanupTests,
9 createVideoPlaylist, 7 createMultipleServers,
10 doubleFollow, 8 doubleFollow,
11 flushAndRunMultipleServers,
12 makeActivityPubGetRequest, 9 makeActivityPubGetRequest,
13 ServerInfo, 10 PeerTubeServer,
14 setAccessTokensToServers, 11 setAccessTokensToServers,
15 setDefaultVideoChannel, 12 setDefaultVideoChannel
16 uploadVideoAndGetId 13} from '@shared/extra-utils'
17} from '../../../../shared/extra-utils' 14import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
18 15
19const expect = chai.expect 16const expect = chai.expect
20 17
21describe('Test activitypub', function () { 18describe('Test activitypub', function () {
22 let servers: ServerInfo[] = [] 19 let servers: PeerTubeServer[] = []
23 let video: { id: number, uuid: string, shortUUID: string } 20 let video: { id: number, uuid: string, shortUUID: string }
24 let playlist: { id: number, uuid: string, shortUUID: string } 21 let playlist: { id: number, uuid: string, shortUUID: string }
25 22
@@ -64,19 +61,18 @@ describe('Test activitypub', function () {
64 before(async function () { 61 before(async function () {
65 this.timeout(30000) 62 this.timeout(30000)
66 63
67 servers = await flushAndRunMultipleServers(2) 64 servers = await createMultipleServers(2)
68 65
69 await setAccessTokensToServers(servers) 66 await setAccessTokensToServers(servers)
70 await setDefaultVideoChannel(servers) 67 await setDefaultVideoChannel(servers)
71 68
72 { 69 {
73 video = await uploadVideoAndGetId({ server: servers[0], videoName: 'video' }) 70 video = await servers[0].videos.quickUpload({ name: 'video' })
74 } 71 }
75 72
76 { 73 {
77 const playlistAttrs = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id } 74 const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].store.channel.id }
78 const resCreate = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs }) 75 playlist = await servers[0].playlists.create({ attributes })
79 playlist = resCreate.body.videoPlaylist
80 } 76 }
81 77
82 await doubleFollow(servers[0], servers[1]) 78 await doubleFollow(servers[0], servers[1])
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts
index 35fd94eed..422a75d6e 100644
--- a/server/tests/api/activitypub/fetch.ts
+++ b/server/tests/api/activitypub/fetch.ts
@@ -1,61 +1,44 @@
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
3import 'mocha' 3import 'mocha'
4
5import {
6 cleanupTests,
7 closeAllSequelize,
8 createUser,
9 doubleFollow,
10 flushAndRunMultipleServers,
11 getVideosListSort,
12 ServerInfo,
13 setAccessTokensToServers,
14 setActorField,
15 setVideoField,
16 uploadVideo,
17 userLogin,
18 waitJobs
19} from '../../../../shared/extra-utils'
20import * as chai from 'chai' 4import * as chai from 'chai'
21import { Video } from '../../../../shared/models/videos' 5import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
22 6
23const expect = chai.expect 7const expect = chai.expect
24 8
25describe('Test ActivityPub fetcher', function () { 9describe('Test ActivityPub fetcher', function () {
26 let servers: ServerInfo[] 10 let servers: PeerTubeServer[]
27 11
28 // --------------------------------------------------------------- 12 // ---------------------------------------------------------------
29 13
30 before(async function () { 14 before(async function () {
31 this.timeout(60000) 15 this.timeout(60000)
32 16
33 servers = await flushAndRunMultipleServers(3) 17 servers = await createMultipleServers(3)
34 18
35 // Get the access tokens 19 // Get the access tokens
36 await setAccessTokensToServers(servers) 20 await setAccessTokensToServers(servers)
37 21
38 const user = { username: 'user1', password: 'password' } 22 const user = { username: 'user1', password: 'password' }
39 for (const server of servers) { 23 for (const server of servers) {
40 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 24 await server.users.create({ username: user.username, password: user.password })
41 } 25 }
42 26
43 const userAccessToken = await userLogin(servers[0], user) 27 const userAccessToken = await servers[0].login.getAccessToken(user)
44 28
45 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video root' }) 29 await servers[0].videos.upload({ attributes: { name: 'video root' } })
46 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'bad video root' }) 30 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'bad video root' } })
47 const badVideoUUID = res.body.video.uuid 31 await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'video user' } })
48 await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' })
49 32
50 { 33 {
51 const to = 'http://localhost:' + servers[0].port + '/accounts/user1' 34 const to = 'http://localhost:' + servers[0].port + '/accounts/user1'
52 const value = 'http://localhost:' + servers[1].port + '/accounts/user1' 35 const value = 'http://localhost:' + servers[1].port + '/accounts/user1'
53 await setActorField(servers[0].internalServerNumber, to, 'url', value) 36 await servers[0].sql.setActorField(to, 'url', value)
54 } 37 }
55 38
56 { 39 {
57 const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID 40 const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + uuid
58 await setVideoField(servers[0].internalServerNumber, badVideoUUID, 'url', value) 41 await servers[0].sql.setVideoField(uuid, 'url', value)
59 } 42 }
60 }) 43 })
61 44
@@ -66,20 +49,18 @@ describe('Test ActivityPub fetcher', function () {
66 await waitJobs(servers) 49 await waitJobs(servers)
67 50
68 { 51 {
69 const res = await getVideosListSort(servers[0].url, 'createdAt') 52 const { total, data } = await servers[0].videos.list({ sort: 'createdAt' })
70 expect(res.body.total).to.equal(3)
71 53
72 const data: Video[] = res.body.data 54 expect(total).to.equal(3)
73 expect(data[0].name).to.equal('video root') 55 expect(data[0].name).to.equal('video root')
74 expect(data[1].name).to.equal('bad video root') 56 expect(data[1].name).to.equal('bad video root')
75 expect(data[2].name).to.equal('video user') 57 expect(data[2].name).to.equal('video user')
76 } 58 }
77 59
78 { 60 {
79 const res = await getVideosListSort(servers[1].url, 'createdAt') 61 const { total, data } = await servers[1].videos.list({ sort: 'createdAt' })
80 expect(res.body.total).to.equal(1)
81 62
82 const data: Video[] = res.body.data 63 expect(total).to.equal(1)
83 expect(data[0].name).to.equal('video root') 64 expect(data[0].name).to.equal('video root')
84 } 65 }
85 }) 66 })
@@ -88,7 +69,5 @@ describe('Test ActivityPub fetcher', function () {
88 this.timeout(20000) 69 this.timeout(20000)
89 70
90 await cleanupTests(servers) 71 await cleanupTests(servers)
91
92 await closeAllSequelize(servers)
93 }) 72 })
94}) 73})
diff --git a/server/tests/api/activitypub/helpers.ts b/server/tests/api/activitypub/helpers.ts
index 66d7631b7..57b1cab23 100644
--- a/server/tests/api/activitypub/helpers.ts
+++ b/server/tests/api/activitypub/helpers.ts
@@ -2,11 +2,10 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { buildRequestStub } from '../../../../shared/extra-utils/miscs/stubs'
6import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto'
7import { cloneDeep } from 'lodash' 5import { cloneDeep } from 'lodash'
6import { buildAbsoluteFixturePath, buildRequestStub } from '@shared/extra-utils'
8import { buildSignedActivity } from '../../../helpers/activitypub' 7import { buildSignedActivity } from '../../../helpers/activitypub'
9import { buildAbsoluteFixturePath } from '@shared/extra-utils' 8import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto'
10 9
11describe('Test activity pub helpers', function () { 10describe('Test activity pub helpers', function () {
12 describe('When checking the Linked Signature', function () { 11 describe('When checking the Linked Signature', function () {
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts
index c717f1a30..81fee0044 100644
--- a/server/tests/api/activitypub/refresher.ts
+++ b/server/tests/api/activitypub/refresher.ts
@@ -2,32 +2,20 @@
2 2
3import 'mocha' 3import 'mocha'
4import { 4import {
5 cleanupTests, closeAllSequelize, 5 cleanupTests,
6 createVideoPlaylist, 6 createMultipleServers,
7 doubleFollow, 7 doubleFollow,
8 flushAndRunMultipleServers,
9 generateUserAccessToken,
10 getVideo,
11 getVideoPlaylist,
12 killallServers, 8 killallServers,
13 reRunServer, 9 PeerTubeServer,
14 ServerInfo,
15 setAccessTokensToServers, 10 setAccessTokensToServers,
16 setActorField,
17 setDefaultVideoChannel, 11 setDefaultVideoChannel,
18 setPlaylistField,
19 setVideoField,
20 uploadVideo,
21 uploadVideoAndGetId,
22 wait, 12 wait,
23 waitJobs 13 waitJobs
24} from '../../../../shared/extra-utils' 14} from '@shared/extra-utils'
25import { getAccount } from '../../../../shared/extra-utils/users/accounts' 15import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
26import { VideoPlaylistPrivacy } from '../../../../shared/models/videos'
27import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
28 16
29describe('Test AP refresher', function () { 17describe('Test AP refresher', function () {
30 let servers: ServerInfo[] = [] 18 let servers: PeerTubeServer[] = []
31 let videoUUID1: string 19 let videoUUID1: string
32 let videoUUID2: string 20 let videoUUID2: string
33 let videoUUID3: string 21 let videoUUID3: string
@@ -37,36 +25,36 @@ describe('Test AP refresher', function () {
37 before(async function () { 25 before(async function () {
38 this.timeout(60000) 26 this.timeout(60000)
39 27
40 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } }) 28 servers = await createMultipleServers(2, { transcoding: { enabled: false } })
41 29
42 // Get the access tokens 30 // Get the access tokens
43 await setAccessTokensToServers(servers) 31 await setAccessTokensToServers(servers)
44 await setDefaultVideoChannel(servers) 32 await setDefaultVideoChannel(servers)
45 33
46 { 34 {
47 videoUUID1 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video1' })).uuid 35 videoUUID1 = (await servers[1].videos.quickUpload({ name: 'video1' })).uuid
48 videoUUID2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video2' })).uuid 36 videoUUID2 = (await servers[1].videos.quickUpload({ name: 'video2' })).uuid
49 videoUUID3 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video3' })).uuid 37 videoUUID3 = (await servers[1].videos.quickUpload({ name: 'video3' })).uuid
50 } 38 }
51 39
52 { 40 {
53 const a1 = await generateUserAccessToken(servers[1], 'user1') 41 const token1 = await servers[1].users.generateUserAndToken('user1')
54 await uploadVideo(servers[1].url, a1, { name: 'video4' }) 42 await servers[1].videos.upload({ token: token1, attributes: { name: 'video4' } })
55 43
56 const a2 = await generateUserAccessToken(servers[1], 'user2') 44 const token2 = await servers[1].users.generateUserAndToken('user2')
57 await uploadVideo(servers[1].url, a2, { name: 'video5' }) 45 await servers[1].videos.upload({ token: token2, attributes: { name: 'video5' } })
58 } 46 }
59 47
60 { 48 {
61 const playlistAttrs = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } 49 const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
62 const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs }) 50 const created = await servers[1].playlists.create({ attributes })
63 playlistUUID1 = res.body.videoPlaylist.uuid 51 playlistUUID1 = created.uuid
64 } 52 }
65 53
66 { 54 {
67 const playlistAttrs = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } 55 const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
68 const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs }) 56 const created = await servers[1].playlists.create({ attributes })
69 playlistUUID2 = res.body.videoPlaylist.uuid 57 playlistUUID2 = created.uuid
70 } 58 }
71 59
72 await doubleFollow(servers[0], servers[1]) 60 await doubleFollow(servers[0], servers[1])
@@ -80,34 +68,34 @@ describe('Test AP refresher', function () {
80 await wait(10000) 68 await wait(10000)
81 69
82 // Change UUID so the remote server returns a 404 70 // Change UUID so the remote server returns a 404
83 await setVideoField(servers[1].internalServerNumber, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') 71 await servers[1].sql.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
84 72
85 await getVideo(servers[0].url, videoUUID1) 73 await servers[0].videos.get({ id: videoUUID1 })
86 await getVideo(servers[0].url, videoUUID2) 74 await servers[0].videos.get({ id: videoUUID2 })
87 75
88 await waitJobs(servers) 76 await waitJobs(servers)
89 77
90 await getVideo(servers[0].url, videoUUID1, HttpStatusCode.NOT_FOUND_404) 78 await servers[0].videos.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
91 await getVideo(servers[0].url, videoUUID2, HttpStatusCode.OK_200) 79 await servers[0].videos.get({ id: videoUUID2 })
92 }) 80 })
93 81
94 it('Should not update a remote video if the remote instance is down', async function () { 82 it('Should not update a remote video if the remote instance is down', async function () {
95 this.timeout(70000) 83 this.timeout(70000)
96 84
97 killallServers([ servers[1] ]) 85 await killallServers([ servers[1] ])
98 86
99 await setVideoField(servers[1].internalServerNumber, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') 87 await servers[1].sql.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
100 88
101 // Video will need a refresh 89 // Video will need a refresh
102 await wait(10000) 90 await wait(10000)
103 91
104 await getVideo(servers[0].url, videoUUID3) 92 await servers[0].videos.get({ id: videoUUID3 })
105 // The refresh should fail 93 // The refresh should fail
106 await waitJobs([ servers[0] ]) 94 await waitJobs([ servers[0] ])
107 95
108 await reRunServer(servers[1]) 96 await servers[1].run()
109 97
110 await getVideo(servers[0].url, videoUUID3, HttpStatusCode.OK_200) 98 await servers[0].videos.get({ id: videoUUID3 })
111 }) 99 })
112 }) 100 })
113 101
@@ -116,19 +104,21 @@ describe('Test AP refresher', function () {
116 it('Should remove a deleted actor', async function () { 104 it('Should remove a deleted actor', async function () {
117 this.timeout(60000) 105 this.timeout(60000)
118 106
107 const command = servers[0].accounts
108
119 await wait(10000) 109 await wait(10000)
120 110
121 // Change actor name so the remote server returns a 404 111 // Change actor name so the remote server returns a 404
122 const to = 'http://localhost:' + servers[1].port + '/accounts/user2' 112 const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
123 await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto') 113 await servers[1].sql.setActorField(to, 'preferredUsername', 'toto')
124 114
125 await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port) 115 await command.get({ accountName: 'user1@localhost:' + servers[1].port })
126 await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port) 116 await command.get({ accountName: 'user2@localhost:' + servers[1].port })
127 117
128 await waitJobs(servers) 118 await waitJobs(servers)
129 119
130 await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port, HttpStatusCode.OK_200) 120 await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 })
131 await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port, HttpStatusCode.NOT_FOUND_404) 121 await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
132 }) 122 })
133 }) 123 })
134 124
@@ -140,15 +130,15 @@ describe('Test AP refresher', function () {
140 await wait(10000) 130 await wait(10000)
141 131
142 // Change UUID so the remote server returns a 404 132 // Change UUID so the remote server returns a 404
143 await setPlaylistField(servers[1].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') 133 await servers[1].sql.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
144 134
145 await getVideoPlaylist(servers[0].url, playlistUUID1) 135 await servers[0].playlists.get({ playlistId: playlistUUID1 })
146 await getVideoPlaylist(servers[0].url, playlistUUID2) 136 await servers[0].playlists.get({ playlistId: playlistUUID2 })
147 137
148 await waitJobs(servers) 138 await waitJobs(servers)
149 139
150 await getVideoPlaylist(servers[0].url, playlistUUID1, HttpStatusCode.OK_200) 140 await servers[0].playlists.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
151 await getVideoPlaylist(servers[0].url, playlistUUID2, HttpStatusCode.NOT_FOUND_404) 141 await servers[0].playlists.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
152 }) 142 })
153 }) 143 })
154 144
@@ -156,7 +146,5 @@ describe('Test AP refresher', function () {
156 this.timeout(10000) 146 this.timeout(10000)
157 147
158 await cleanupTests(servers) 148 await cleanupTests(servers)
159
160 await closeAllSequelize(servers)
161 }) 149 })
162}) 150})
diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts
index 61db272f6..94d946563 100644
--- a/server/tests/api/activitypub/security.ts
+++ b/server/tests/api/activitypub/security.ts
@@ -2,45 +2,35 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { activityPubContextify, buildSignedActivity } from '@server/helpers/activitypub'
5import { buildDigest } from '@server/helpers/peertube-crypto' 6import { buildDigest } from '@server/helpers/peertube-crypto'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 7import { HTTP_SIGNATURE } from '@server/initializers/constants'
7import { 8import { buildGlobalHeaders } from '@server/lib/job-queue/handlers/utils/activitypub-http-utils'
8 buildAbsoluteFixturePath, 9import { buildAbsoluteFixturePath, cleanupTests, createMultipleServers, killallServers, PeerTubeServer, wait } from '@shared/extra-utils'
9 cleanupTests, 10import { makeFollowRequest, makePOSTAPRequest } from '@shared/extra-utils/requests/activitypub'
10 closeAllSequelize, 11import { HttpStatusCode } from '@shared/models'
11 flushAndRunMultipleServers,
12 killallServers,
13 reRunServer,
14 ServerInfo,
15 setActorField,
16 wait
17} from '../../../../shared/extra-utils'
18import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub'
19import { activityPubContextify, buildSignedActivity } from '../../../helpers/activitypub'
20import { HTTP_SIGNATURE } from '../../../initializers/constants'
21import { buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activitypub-http-utils'
22 12
23const expect = chai.expect 13const expect = chai.expect
24 14
25function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey: string, privateKey: string) { 15function setKeysOfServer (onServer: PeerTubeServer, ofServer: PeerTubeServer, publicKey: string, privateKey: string) {
26 const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' 16 const url = 'http://localhost:' + ofServer.port + '/accounts/peertube'
27 17
28 return Promise.all([ 18 return Promise.all([
29 setActorField(onServer.internalServerNumber, url, 'publicKey', publicKey), 19 onServer.sql.setActorField(url, 'publicKey', publicKey),
30 setActorField(onServer.internalServerNumber, url, 'privateKey', privateKey) 20 onServer.sql.setActorField(url, 'privateKey', privateKey)
31 ]) 21 ])
32} 22}
33 23
34function setUpdatedAtOfServer (onServer: ServerInfo, ofServer: ServerInfo, updatedAt: string) { 24function setUpdatedAtOfServer (onServer: PeerTubeServer, ofServer: PeerTubeServer, updatedAt: string) {
35 const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' 25 const url = 'http://localhost:' + ofServer.port + '/accounts/peertube'
36 26
37 return Promise.all([ 27 return Promise.all([
38 setActorField(onServer.internalServerNumber, url, 'createdAt', updatedAt), 28 onServer.sql.setActorField(url, 'createdAt', updatedAt),
39 setActorField(onServer.internalServerNumber, url, 'updatedAt', updatedAt) 29 onServer.sql.setActorField(url, 'updatedAt', updatedAt)
40 ]) 30 ])
41} 31}
42 32
43function getAnnounceWithoutContext (server: ServerInfo) { 33function getAnnounceWithoutContext (server: PeerTubeServer) {
44 const json = require(buildAbsoluteFixturePath('./ap-json/peertube/announce-without-context.json')) 34 const json = require(buildAbsoluteFixturePath('./ap-json/peertube/announce-without-context.json'))
45 const result: typeof json = {} 35 const result: typeof json = {}
46 36
@@ -56,7 +46,7 @@ function getAnnounceWithoutContext (server: ServerInfo) {
56} 46}
57 47
58describe('Test ActivityPub security', function () { 48describe('Test ActivityPub security', function () {
59 let servers: ServerInfo[] 49 let servers: PeerTubeServer[]
60 let url: string 50 let url: string
61 51
62 const keys = require(buildAbsoluteFixturePath('./ap-json/peertube/keys.json')) 52 const keys = require(buildAbsoluteFixturePath('./ap-json/peertube/keys.json'))
@@ -74,7 +64,7 @@ describe('Test ActivityPub security', function () {
74 before(async function () { 64 before(async function () {
75 this.timeout(60000) 65 this.timeout(60000)
76 66
77 servers = await flushAndRunMultipleServers(3) 67 servers = await createMultipleServers(3)
78 68
79 url = servers[0].url + '/inbox' 69 url = servers[0].url + '/inbox'
80 70
@@ -173,8 +163,8 @@ describe('Test ActivityPub security', function () {
173 await setUpdatedAtOfServer(servers[0], servers[1], '2015-07-17 22:00:00+00') 163 await setUpdatedAtOfServer(servers[0], servers[1], '2015-07-17 22:00:00+00')
174 164
175 // Invalid peertube actor cache 165 // Invalid peertube actor cache
176 killallServers([ servers[1] ]) 166 await killallServers([ servers[1] ])
177 await reRunServer(servers[1]) 167 await servers[1].run()
178 168
179 const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) 169 const body = activityPubContextify(getAnnounceWithoutContext(servers[1]))
180 const headers = buildGlobalHeaders(body) 170 const headers = buildGlobalHeaders(body)
@@ -294,7 +284,5 @@ describe('Test ActivityPub security', function () {
294 this.timeout(10000) 284 this.timeout(10000)
295 285
296 await cleanupTests(servers) 286 await cleanupTests(servers)
297
298 await closeAllSequelize(servers)
299 }) 287 })
300}) 288})