diff options
author | Chocobozzz <me@florianbigard.com> | 2023-04-21 15:00:01 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-05-09 08:57:34 +0200 |
commit | d102de1b38f2877463529c3b27bd35ffef4fd8bf (patch) | |
tree | 31fa0bdf26ad7a2ee46d600d804a6f03260266c8 /server/tests/api/activitypub | |
parent | 2fe978744e5b74eb824e4d79c1bb9b840169f125 (diff) | |
download | PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.tar.gz PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.tar.zst PeerTube-d102de1b38f2877463529c3b27bd35ffef4fd8bf.zip |
Add runner server tests
Diffstat (limited to 'server/tests/api/activitypub')
-rw-r--r-- | server/tests/api/activitypub/cleaner.ts | 33 | ||||
-rw-r--r-- | server/tests/api/activitypub/fetch.ts | 9 | ||||
-rw-r--r-- | server/tests/api/activitypub/refresher.ts | 14 | ||||
-rw-r--r-- | server/tests/api/activitypub/security.ts | 58 |
4 files changed, 70 insertions, 44 deletions
diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index 1c1495022..d67175e20 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts | |||
@@ -1,6 +1,7 @@ | |||
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 { SQLCommand } from '@server/tests/shared' | ||
4 | import { wait } from '@shared/core-utils' | 5 | import { wait } from '@shared/core-utils' |
5 | import { | 6 | import { |
6 | cleanupTests, | 7 | cleanupTests, |
@@ -13,6 +14,8 @@ import { | |||
13 | 14 | ||
14 | describe('Test AP cleaner', function () { | 15 | describe('Test AP cleaner', function () { |
15 | let servers: PeerTubeServer[] = [] | 16 | let servers: PeerTubeServer[] = [] |
17 | const sqlCommands: SQLCommand[] = [] | ||
18 | |||
16 | let videoUUID1: string | 19 | let videoUUID1: string |
17 | let videoUUID2: string | 20 | let videoUUID2: string |
18 | let videoUUID3: string | 21 | let videoUUID3: string |
@@ -56,6 +59,8 @@ describe('Test AP cleaner', function () { | |||
56 | await server.videos.rate({ id: uuid, rating: 'like' }) | 59 | await server.videos.rate({ id: uuid, rating: 'like' }) |
57 | await server.comments.createThread({ videoId: uuid, text: 'comment' }) | 60 | await server.comments.createThread({ videoId: uuid, text: 'comment' }) |
58 | } | 61 | } |
62 | |||
63 | sqlCommands.push(new SQLCommand(server)) | ||
59 | } | 64 | } |
60 | 65 | ||
61 | await waitJobs(servers) | 66 | await waitJobs(servers) |
@@ -75,9 +80,9 @@ describe('Test AP cleaner', function () { | |||
75 | it('Should destroy server 3 internal likes and correctly clean them', async function () { | 80 | it('Should destroy server 3 internal likes and correctly clean them', async function () { |
76 | this.timeout(20000) | 81 | this.timeout(20000) |
77 | 82 | ||
78 | await servers[2].sql.deleteAll('accountVideoRate') | 83 | await sqlCommands[2].deleteAll('accountVideoRate') |
79 | for (const uuid of videoUUIDs) { | 84 | for (const uuid of videoUUIDs) { |
80 | await servers[2].sql.setVideoField(uuid, 'likes', '0') | 85 | await sqlCommands[2].setVideoField(uuid, 'likes', '0') |
81 | } | 86 | } |
82 | 87 | ||
83 | await wait(5000) | 88 | await wait(5000) |
@@ -121,10 +126,10 @@ describe('Test AP cleaner', function () { | |||
121 | it('Should destroy server 3 internal dislikes and correctly clean them', async function () { | 126 | it('Should destroy server 3 internal dislikes and correctly clean them', async function () { |
122 | this.timeout(20000) | 127 | this.timeout(20000) |
123 | 128 | ||
124 | await servers[2].sql.deleteAll('accountVideoRate') | 129 | await sqlCommands[2].deleteAll('accountVideoRate') |
125 | 130 | ||
126 | for (const uuid of videoUUIDs) { | 131 | for (const uuid of videoUUIDs) { |
127 | await servers[2].sql.setVideoField(uuid, 'dislikes', '0') | 132 | await sqlCommands[2].setVideoField(uuid, 'dislikes', '0') |
128 | } | 133 | } |
129 | 134 | ||
130 | await wait(5000) | 135 | await wait(5000) |
@@ -148,15 +153,15 @@ describe('Test AP cleaner', function () { | |||
148 | it('Should destroy server 3 internal shares and correctly clean them', async function () { | 153 | it('Should destroy server 3 internal shares and correctly clean them', async function () { |
149 | this.timeout(20000) | 154 | this.timeout(20000) |
150 | 155 | ||
151 | const preCount = await servers[0].sql.getVideoShareCount() | 156 | const preCount = await sqlCommands[0].getVideoShareCount() |
152 | expect(preCount).to.equal(6) | 157 | expect(preCount).to.equal(6) |
153 | 158 | ||
154 | await servers[2].sql.deleteAll('videoShare') | 159 | await sqlCommands[2].deleteAll('videoShare') |
155 | await wait(5000) | 160 | await wait(5000) |
156 | await waitJobs(servers) | 161 | await waitJobs(servers) |
157 | 162 | ||
158 | // Still 6 because we don't have remote shares on local videos | 163 | // Still 6 because we don't have remote shares on local videos |
159 | const postCount = await servers[0].sql.getVideoShareCount() | 164 | const postCount = await sqlCommands[0].getVideoShareCount() |
160 | expect(postCount).to.equal(6) | 165 | expect(postCount).to.equal(6) |
161 | }) | 166 | }) |
162 | 167 | ||
@@ -168,7 +173,7 @@ describe('Test AP cleaner', function () { | |||
168 | expect(total).to.equal(3) | 173 | expect(total).to.equal(3) |
169 | } | 174 | } |
170 | 175 | ||
171 | await servers[2].sql.deleteAll('videoComment') | 176 | await sqlCommands[2].deleteAll('videoComment') |
172 | 177 | ||
173 | await wait(5000) | 178 | await wait(5000) |
174 | await waitJobs(servers) | 179 | await waitJobs(servers) |
@@ -185,7 +190,7 @@ describe('Test AP cleaner', function () { | |||
185 | async function check (like: string, ofServerUrl: string, urlSuffix: string, remote: 'true' | 'false') { | 190 | async function check (like: string, ofServerUrl: string, urlSuffix: string, remote: 'true' | 'false') { |
186 | const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` + | 191 | const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` + |
187 | `INNER JOIN video ON "accountVideoRate"."videoId" = video.id AND remote IS ${remote} WHERE "accountVideoRate"."url" LIKE '${like}'` | 192 | `INNER JOIN video ON "accountVideoRate"."videoId" = video.id AND remote IS ${remote} WHERE "accountVideoRate"."url" LIKE '${like}'` |
188 | const res = await servers[0].sql.selectQuery<{ url: string }>(query) | 193 | const res = await sqlCommands[0].selectQuery<{ url: string }>(query) |
189 | 194 | ||
190 | for (const rate of res) { | 195 | for (const rate of res) { |
191 | const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`) | 196 | const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`) |
@@ -214,7 +219,7 @@ describe('Test AP cleaner', function () { | |||
214 | 219 | ||
215 | { | 220 | { |
216 | const query = `UPDATE "accountVideoRate" SET url = url || 'stan'` | 221 | const query = `UPDATE "accountVideoRate" SET url = url || 'stan'` |
217 | await servers[1].sql.updateQuery(query) | 222 | await sqlCommands[1].updateQuery(query) |
218 | 223 | ||
219 | await wait(5000) | 224 | await wait(5000) |
220 | await waitJobs(servers) | 225 | await waitJobs(servers) |
@@ -231,7 +236,7 @@ describe('Test AP cleaner', function () { | |||
231 | const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` + | 236 | const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` + |
232 | `INNER JOIN video ON "videoComment"."videoId" = video.id AND remote IS ${remote} WHERE "videoComment"."url" LIKE '${like}'` | 237 | `INNER JOIN video ON "videoComment"."videoId" = video.id AND remote IS ${remote} WHERE "videoComment"."url" LIKE '${like}'` |
233 | 238 | ||
234 | const res = await servers[0].sql.selectQuery<{ url: string, videoUUID: string }>(query) | 239 | const res = await sqlCommands[0].selectQuery<{ url: string, videoUUID: string }>(query) |
235 | 240 | ||
236 | for (const comment of res) { | 241 | for (const comment of res) { |
237 | const matcher = new RegExp(`${ofServerUrl}/videos/watch/${comment.videoUUID}/comments/\\d+${urlSuffix}`) | 242 | const matcher = new RegExp(`${ofServerUrl}/videos/watch/${comment.videoUUID}/comments/\\d+${urlSuffix}`) |
@@ -257,7 +262,7 @@ describe('Test AP cleaner', function () { | |||
257 | 262 | ||
258 | { | 263 | { |
259 | const query = `UPDATE "videoComment" SET url = url || 'kyle'` | 264 | const query = `UPDATE "videoComment" SET url = url || 'kyle'` |
260 | await servers[1].sql.updateQuery(query) | 265 | await sqlCommands[1].updateQuery(query) |
261 | 266 | ||
262 | await wait(5000) | 267 | await wait(5000) |
263 | await waitJobs(servers) | 268 | await waitJobs(servers) |
@@ -328,6 +333,10 @@ describe('Test AP cleaner', function () { | |||
328 | }) | 333 | }) |
329 | 334 | ||
330 | after(async function () { | 335 | after(async function () { |
336 | for (const sql of sqlCommands) { | ||
337 | await sql.cleanup() | ||
338 | } | ||
339 | |||
331 | await cleanupTests(servers) | 340 | await cleanupTests(servers) |
332 | }) | 341 | }) |
333 | }) | 342 | }) |
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index f0caea507..3899a6a49 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts | |||
@@ -1,6 +1,7 @@ | |||
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 { SQLCommand } from '@server/tests/shared' | ||
4 | import { | 5 | import { |
5 | cleanupTests, | 6 | cleanupTests, |
6 | createMultipleServers, | 7 | createMultipleServers, |
@@ -12,6 +13,7 @@ import { | |||
12 | 13 | ||
13 | describe('Test ActivityPub fetcher', function () { | 14 | describe('Test ActivityPub fetcher', function () { |
14 | let servers: PeerTubeServer[] | 15 | let servers: PeerTubeServer[] |
16 | let sqlCommandServer1: SQLCommand | ||
15 | 17 | ||
16 | // --------------------------------------------------------------- | 18 | // --------------------------------------------------------------- |
17 | 19 | ||
@@ -34,15 +36,17 @@ describe('Test ActivityPub fetcher', function () { | |||
34 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'bad video root' } }) | 36 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'bad video root' } }) |
35 | await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'video user' } }) | 37 | await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'video user' } }) |
36 | 38 | ||
39 | sqlCommandServer1 = new SQLCommand(servers[0]) | ||
40 | |||
37 | { | 41 | { |
38 | const to = servers[0].url + '/accounts/user1' | 42 | const to = servers[0].url + '/accounts/user1' |
39 | const value = servers[1].url + '/accounts/user1' | 43 | const value = servers[1].url + '/accounts/user1' |
40 | await servers[0].sql.setActorField(to, 'url', value) | 44 | await sqlCommandServer1.setActorField(to, 'url', value) |
41 | } | 45 | } |
42 | 46 | ||
43 | { | 47 | { |
44 | const value = servers[2].url + '/videos/watch/' + uuid | 48 | const value = servers[2].url + '/videos/watch/' + uuid |
45 | await servers[0].sql.setVideoField(uuid, 'url', value) | 49 | await sqlCommandServer1.setVideoField(uuid, 'url', value) |
46 | } | 50 | } |
47 | }) | 51 | }) |
48 | 52 | ||
@@ -72,6 +76,7 @@ describe('Test ActivityPub fetcher', function () { | |||
72 | after(async function () { | 76 | after(async function () { |
73 | this.timeout(20000) | 77 | this.timeout(20000) |
74 | 78 | ||
79 | await sqlCommandServer1.cleanup() | ||
75 | await cleanupTests(servers) | 80 | await cleanupTests(servers) |
76 | }) | 81 | }) |
77 | }) | 82 | }) |
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index 4fb22f512..6c48b7ac8 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.ts | |||
@@ -1,5 +1,6 @@ | |||
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 { SQLCommand } from '@server/tests/shared' | ||
3 | import { wait } from '@shared/core-utils' | 4 | import { wait } from '@shared/core-utils' |
4 | import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' | 5 | import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' |
5 | import { | 6 | import { |
@@ -15,6 +16,7 @@ import { | |||
15 | 16 | ||
16 | describe('Test AP refresher', function () { | 17 | describe('Test AP refresher', function () { |
17 | let servers: PeerTubeServer[] = [] | 18 | let servers: PeerTubeServer[] = [] |
19 | let sqlCommandServer2: SQLCommand | ||
18 | let videoUUID1: string | 20 | let videoUUID1: string |
19 | let videoUUID2: string | 21 | let videoUUID2: string |
20 | let videoUUID3: string | 22 | let videoUUID3: string |
@@ -61,6 +63,8 @@ describe('Test AP refresher', function () { | |||
61 | } | 63 | } |
62 | 64 | ||
63 | await doubleFollow(servers[0], servers[1]) | 65 | await doubleFollow(servers[0], servers[1]) |
66 | |||
67 | sqlCommandServer2 = new SQLCommand(servers[1]) | ||
64 | }) | 68 | }) |
65 | 69 | ||
66 | describe('Videos refresher', function () { | 70 | describe('Videos refresher', function () { |
@@ -71,7 +75,7 @@ describe('Test AP refresher', function () { | |||
71 | await wait(10000) | 75 | await wait(10000) |
72 | 76 | ||
73 | // Change UUID so the remote server returns a 404 | 77 | // Change UUID so the remote server returns a 404 |
74 | await servers[1].sql.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') | 78 | await sqlCommandServer2.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') |
75 | 79 | ||
76 | await servers[0].videos.get({ id: videoUUID1 }) | 80 | await servers[0].videos.get({ id: videoUUID1 }) |
77 | await servers[0].videos.get({ id: videoUUID2 }) | 81 | await servers[0].videos.get({ id: videoUUID2 }) |
@@ -87,7 +91,7 @@ describe('Test AP refresher', function () { | |||
87 | 91 | ||
88 | await killallServers([ servers[1] ]) | 92 | await killallServers([ servers[1] ]) |
89 | 93 | ||
90 | await servers[1].sql.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') | 94 | await sqlCommandServer2.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') |
91 | 95 | ||
92 | // Video will need a refresh | 96 | // Video will need a refresh |
93 | await wait(10000) | 97 | await wait(10000) |
@@ -113,7 +117,7 @@ describe('Test AP refresher', function () { | |||
113 | 117 | ||
114 | // Change actor name so the remote server returns a 404 | 118 | // Change actor name so the remote server returns a 404 |
115 | const to = servers[1].url + '/accounts/user2' | 119 | const to = servers[1].url + '/accounts/user2' |
116 | await servers[1].sql.setActorField(to, 'preferredUsername', 'toto') | 120 | await sqlCommandServer2.setActorField(to, 'preferredUsername', 'toto') |
117 | 121 | ||
118 | await command.get({ accountName: 'user1@' + servers[1].host }) | 122 | await command.get({ accountName: 'user1@' + servers[1].host }) |
119 | await command.get({ accountName: 'user2@' + servers[1].host }) | 123 | await command.get({ accountName: 'user2@' + servers[1].host }) |
@@ -133,7 +137,7 @@ describe('Test AP refresher', function () { | |||
133 | await wait(10000) | 137 | await wait(10000) |
134 | 138 | ||
135 | // Change UUID so the remote server returns a 404 | 139 | // Change UUID so the remote server returns a 404 |
136 | await servers[1].sql.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') | 140 | await sqlCommandServer2.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') |
137 | 141 | ||
138 | await servers[0].playlists.get({ playlistId: playlistUUID1 }) | 142 | await servers[0].playlists.get({ playlistId: playlistUUID1 }) |
139 | await servers[0].playlists.get({ playlistId: playlistUUID2 }) | 143 | await servers[0].playlists.get({ playlistId: playlistUUID2 }) |
@@ -148,6 +152,8 @@ describe('Test AP refresher', function () { | |||
148 | after(async function () { | 152 | after(async function () { |
149 | this.timeout(10000) | 153 | this.timeout(10000) |
150 | 154 | ||
155 | await sqlCommandServer2.cleanup() | ||
156 | |||
151 | await cleanupTests(servers) | 157 | await cleanupTests(servers) |
152 | }) | 158 | }) |
153 | }) | 159 | }) |
diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts index c6f171633..d6a07b87f 100644 --- a/server/tests/api/activitypub/security.ts +++ b/server/tests/api/activitypub/security.ts | |||
@@ -5,26 +5,26 @@ import { buildDigest } from '@server/helpers/peertube-crypto' | |||
5 | import { ACTIVITY_PUB, HTTP_SIGNATURE } from '@server/initializers/constants' | 5 | import { ACTIVITY_PUB, HTTP_SIGNATURE } from '@server/initializers/constants' |
6 | import { activityPubContextify } from '@server/lib/activitypub/context' | 6 | import { activityPubContextify } from '@server/lib/activitypub/context' |
7 | import { buildGlobalHeaders, signAndContextify } from '@server/lib/activitypub/send' | 7 | import { buildGlobalHeaders, signAndContextify } from '@server/lib/activitypub/send' |
8 | import { makePOSTAPRequest } from '@server/tests/shared' | 8 | import { makePOSTAPRequest, SQLCommand } from '@server/tests/shared' |
9 | import { buildAbsoluteFixturePath, wait } from '@shared/core-utils' | 9 | import { buildAbsoluteFixturePath, wait } from '@shared/core-utils' |
10 | import { HttpStatusCode } from '@shared/models' | 10 | import { HttpStatusCode } from '@shared/models' |
11 | import { cleanupTests, createMultipleServers, killallServers, PeerTubeServer } from '@shared/server-commands' | 11 | import { cleanupTests, createMultipleServers, killallServers, PeerTubeServer } from '@shared/server-commands' |
12 | 12 | ||
13 | function setKeysOfServer (onServer: PeerTubeServer, ofServer: PeerTubeServer, publicKey: string, privateKey: string) { | 13 | function setKeysOfServer (onServer: SQLCommand, ofServerUrl: string, publicKey: string, privateKey: string) { |
14 | const url = ofServer.url + '/accounts/peertube' | 14 | const url = ofServerUrl + '/accounts/peertube' |
15 | 15 | ||
16 | return Promise.all([ | 16 | return Promise.all([ |
17 | onServer.sql.setActorField(url, 'publicKey', publicKey), | 17 | onServer.setActorField(url, 'publicKey', publicKey), |
18 | onServer.sql.setActorField(url, 'privateKey', privateKey) | 18 | onServer.setActorField(url, 'privateKey', privateKey) |
19 | ]) | 19 | ]) |
20 | } | 20 | } |
21 | 21 | ||
22 | function setUpdatedAtOfServer (onServer: PeerTubeServer, ofServer: PeerTubeServer, updatedAt: string) { | 22 | function setUpdatedAtOfServer (onServer: SQLCommand, ofServerUrl: string, updatedAt: string) { |
23 | const url = ofServer.url + '/accounts/peertube' | 23 | const url = ofServerUrl + '/accounts/peertube' |
24 | 24 | ||
25 | return Promise.all([ | 25 | return Promise.all([ |
26 | onServer.sql.setActorField(url, 'createdAt', updatedAt), | 26 | onServer.setActorField(url, 'createdAt', updatedAt), |
27 | onServer.sql.setActorField(url, 'updatedAt', updatedAt) | 27 | onServer.setActorField(url, 'updatedAt', updatedAt) |
28 | ]) | 28 | ]) |
29 | } | 29 | } |
30 | 30 | ||
@@ -71,6 +71,8 @@ async function makeFollowRequest (to: { url: string }, by: { url: string, privat | |||
71 | 71 | ||
72 | describe('Test ActivityPub security', function () { | 72 | describe('Test ActivityPub security', function () { |
73 | let servers: PeerTubeServer[] | 73 | let servers: PeerTubeServer[] |
74 | let sqlCommands: SQLCommand[] | ||
75 | |||
74 | let url: string | 76 | let url: string |
75 | 77 | ||
76 | const keys = require(buildAbsoluteFixturePath('./ap-json/peertube/keys.json')) | 78 | const keys = require(buildAbsoluteFixturePath('./ap-json/peertube/keys.json')) |
@@ -90,10 +92,12 @@ describe('Test ActivityPub security', function () { | |||
90 | 92 | ||
91 | servers = await createMultipleServers(3) | 93 | servers = await createMultipleServers(3) |
92 | 94 | ||
95 | sqlCommands = servers.map(s => new SQLCommand(s)) | ||
96 | |||
93 | url = servers[0].url + '/inbox' | 97 | url = servers[0].url + '/inbox' |
94 | 98 | ||
95 | await setKeysOfServer(servers[0], servers[1], keys.publicKey, null) | 99 | await setKeysOfServer(sqlCommands[0], servers[1].url, keys.publicKey, null) |
96 | await setKeysOfServer(servers[1], servers[1], keys.publicKey, keys.privateKey) | 100 | await setKeysOfServer(sqlCommands[1], servers[1].url, keys.publicKey, keys.privateKey) |
97 | 101 | ||
98 | const to = { url: servers[0].url + '/accounts/peertube' } | 102 | const to = { url: servers[0].url + '/accounts/peertube' } |
99 | const by = { url: servers[1].url + '/accounts/peertube', privateKey: keys.privateKey } | 103 | const by = { url: servers[1].url + '/accounts/peertube', privateKey: keys.privateKey } |
@@ -130,8 +134,8 @@ describe('Test ActivityPub security', function () { | |||
130 | }) | 134 | }) |
131 | 135 | ||
132 | it('Should fail with bad keys', async function () { | 136 | it('Should fail with bad keys', async function () { |
133 | await setKeysOfServer(servers[0], servers[1], invalidKeys.publicKey, invalidKeys.privateKey) | 137 | await setKeysOfServer(sqlCommands[0], servers[1].url, invalidKeys.publicKey, invalidKeys.privateKey) |
134 | await setKeysOfServer(servers[1], servers[1], invalidKeys.publicKey, invalidKeys.privateKey) | 138 | await setKeysOfServer(sqlCommands[1], servers[1].url, invalidKeys.publicKey, invalidKeys.privateKey) |
135 | 139 | ||
136 | const body = await activityPubContextify(getAnnounceWithoutContext(servers[1]), 'Announce') | 140 | const body = await activityPubContextify(getAnnounceWithoutContext(servers[1]), 'Announce') |
137 | const headers = buildGlobalHeaders(body) | 141 | const headers = buildGlobalHeaders(body) |
@@ -145,8 +149,8 @@ describe('Test ActivityPub security', function () { | |||
145 | }) | 149 | }) |
146 | 150 | ||
147 | it('Should reject requests without appropriate signed headers', async function () { | 151 | it('Should reject requests without appropriate signed headers', async function () { |
148 | await setKeysOfServer(servers[0], servers[1], keys.publicKey, keys.privateKey) | 152 | await setKeysOfServer(sqlCommands[0], servers[1].url, keys.publicKey, keys.privateKey) |
149 | await setKeysOfServer(servers[1], servers[1], keys.publicKey, keys.privateKey) | 153 | await setKeysOfServer(sqlCommands[1], servers[1].url, keys.publicKey, keys.privateKey) |
150 | 154 | ||
151 | const body = await activityPubContextify(getAnnounceWithoutContext(servers[1]), 'Announce') | 155 | const body = await activityPubContextify(getAnnounceWithoutContext(servers[1]), 'Announce') |
152 | const headers = buildGlobalHeaders(body) | 156 | const headers = buildGlobalHeaders(body) |
@@ -194,8 +198,8 @@ describe('Test ActivityPub security', function () { | |||
194 | 198 | ||
195 | // Update keys of server 2 to invalid keys | 199 | // Update keys of server 2 to invalid keys |
196 | // Server 1 should refresh the actor and fail | 200 | // Server 1 should refresh the actor and fail |
197 | await setKeysOfServer(servers[1], servers[1], invalidKeys.publicKey, invalidKeys.privateKey) | 201 | await setKeysOfServer(sqlCommands[1], servers[1].url, invalidKeys.publicKey, invalidKeys.privateKey) |
198 | await setUpdatedAtOfServer(servers[0], servers[1], '2015-07-17 22:00:00+00') | 202 | await setUpdatedAtOfServer(sqlCommands[0], servers[1].url, '2015-07-17 22:00:00+00') |
199 | 203 | ||
200 | // Invalid peertube actor cache | 204 | // Invalid peertube actor cache |
201 | await killallServers([ servers[1] ]) | 205 | await killallServers([ servers[1] ]) |
@@ -218,9 +222,9 @@ describe('Test ActivityPub security', function () { | |||
218 | before(async function () { | 222 | before(async function () { |
219 | this.timeout(10000) | 223 | this.timeout(10000) |
220 | 224 | ||
221 | await setKeysOfServer(servers[0], servers[1], keys.publicKey, keys.privateKey) | 225 | await setKeysOfServer(sqlCommands[0], servers[1].url, keys.publicKey, keys.privateKey) |
222 | await setKeysOfServer(servers[1], servers[1], keys.publicKey, keys.privateKey) | 226 | await setKeysOfServer(sqlCommands[1], servers[1].url, keys.publicKey, keys.privateKey) |
223 | await setKeysOfServer(servers[2], servers[2], keys.publicKey, keys.privateKey) | 227 | await setKeysOfServer(sqlCommands[2], servers[2].url, keys.publicKey, keys.privateKey) |
224 | 228 | ||
225 | const to = { url: servers[0].url + '/accounts/peertube' } | 229 | const to = { url: servers[0].url + '/accounts/peertube' } |
226 | const by = { url: servers[2].url + '/accounts/peertube', privateKey: keys.privateKey } | 230 | const by = { url: servers[2].url + '/accounts/peertube', privateKey: keys.privateKey } |
@@ -230,8 +234,8 @@ describe('Test ActivityPub security', function () { | |||
230 | it('Should fail with bad keys', async function () { | 234 | it('Should fail with bad keys', async function () { |
231 | this.timeout(10000) | 235 | this.timeout(10000) |
232 | 236 | ||
233 | await setKeysOfServer(servers[0], servers[2], invalidKeys.publicKey, invalidKeys.privateKey) | 237 | await setKeysOfServer(sqlCommands[0], servers[2].url, invalidKeys.publicKey, invalidKeys.privateKey) |
234 | await setKeysOfServer(servers[2], servers[2], invalidKeys.publicKey, invalidKeys.privateKey) | 238 | await setKeysOfServer(sqlCommands[2], servers[2].url, invalidKeys.publicKey, invalidKeys.privateKey) |
235 | 239 | ||
236 | const body = getAnnounceWithoutContext(servers[1]) | 240 | const body = getAnnounceWithoutContext(servers[1]) |
237 | body.actor = servers[2].url + '/accounts/peertube' | 241 | body.actor = servers[2].url + '/accounts/peertube' |
@@ -252,8 +256,8 @@ describe('Test ActivityPub security', function () { | |||
252 | it('Should fail with an altered body', async function () { | 256 | it('Should fail with an altered body', async function () { |
253 | this.timeout(10000) | 257 | this.timeout(10000) |
254 | 258 | ||
255 | await setKeysOfServer(servers[0], servers[2], keys.publicKey, keys.privateKey) | 259 | await setKeysOfServer(sqlCommands[0], servers[2].url, keys.publicKey, keys.privateKey) |
256 | await setKeysOfServer(servers[0], servers[2], keys.publicKey, keys.privateKey) | 260 | await setKeysOfServer(sqlCommands[0], servers[2].url, keys.publicKey, keys.privateKey) |
257 | 261 | ||
258 | const body = getAnnounceWithoutContext(servers[1]) | 262 | const body = getAnnounceWithoutContext(servers[1]) |
259 | body.actor = servers[2].url + '/accounts/peertube' | 263 | body.actor = servers[2].url + '/accounts/peertube' |
@@ -296,7 +300,7 @@ describe('Test ActivityPub security', function () { | |||
296 | 300 | ||
297 | // Update keys of server 3 to invalid keys | 301 | // Update keys of server 3 to invalid keys |
298 | // Server 1 should refresh the actor and fail | 302 | // Server 1 should refresh the actor and fail |
299 | await setKeysOfServer(servers[2], servers[2], invalidKeys.publicKey, invalidKeys.privateKey) | 303 | await setKeysOfServer(sqlCommands[2], servers[2].url, invalidKeys.publicKey, invalidKeys.privateKey) |
300 | 304 | ||
301 | const body = getAnnounceWithoutContext(servers[1]) | 305 | const body = getAnnounceWithoutContext(servers[1]) |
302 | body.actor = servers[2].url + '/accounts/peertube' | 306 | body.actor = servers[2].url + '/accounts/peertube' |
@@ -316,7 +320,9 @@ describe('Test ActivityPub security', function () { | |||
316 | }) | 320 | }) |
317 | 321 | ||
318 | after(async function () { | 322 | after(async function () { |
319 | this.timeout(10000) | 323 | for (const sql of sqlCommands) { |
324 | await sql.cleanup() | ||
325 | } | ||
320 | 326 | ||
321 | await cleanupTests(servers) | 327 | await cleanupTests(servers) |
322 | }) | 328 | }) |