diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-09 15:37:43 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:18 +0200 |
commit | 9293139fde7091e9badcafa9b570b83cea9a10ad (patch) | |
tree | 9728412f02af4aa59d2c016db47624251e8f6be6 /server/tests/api/activitypub | |
parent | 078f17e6d90376050f43ce639e88e11869b49ee7 (diff) | |
download | PeerTube-9293139fde7091e9badcafa9b570b83cea9a10ad.tar.gz PeerTube-9293139fde7091e9badcafa9b570b83cea9a10ad.tar.zst PeerTube-9293139fde7091e9badcafa9b570b83cea9a10ad.zip |
Introduce sql command
Diffstat (limited to 'server/tests/api/activitypub')
-rw-r--r-- | server/tests/api/activitypub/cleaner.ts | 32 | ||||
-rw-r--r-- | server/tests/api/activitypub/fetch.ts | 12 | ||||
-rw-r--r-- | server/tests/api/activitypub/refresher.ts | 16 | ||||
-rw-r--r-- | server/tests/api/activitypub/security.ts | 14 |
4 files changed, 25 insertions, 49 deletions
diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index 27f17b4d6..5b08880bf 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts | |||
@@ -4,18 +4,12 @@ import 'mocha' | |||
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { | 5 | import { |
6 | cleanupTests, | 6 | cleanupTests, |
7 | closeAllSequelize, | ||
8 | deleteAll, | ||
9 | doubleFollow, | 7 | doubleFollow, |
10 | flushAndRunMultipleServers, | 8 | flushAndRunMultipleServers, |
11 | getCount, | ||
12 | getVideo, | 9 | getVideo, |
13 | rateVideo, | 10 | rateVideo, |
14 | selectQuery, | ||
15 | ServerInfo, | 11 | ServerInfo, |
16 | setAccessTokensToServers, | 12 | setAccessTokensToServers, |
17 | setVideoField, | ||
18 | updateQuery, | ||
19 | uploadVideoAndGetId, | 13 | uploadVideoAndGetId, |
20 | wait, | 14 | wait, |
21 | waitJobs | 15 | waitJobs |
@@ -86,9 +80,9 @@ describe('Test AP cleaner', function () { | |||
86 | 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 () { |
87 | this.timeout(20000) | 81 | this.timeout(20000) |
88 | 82 | ||
89 | await deleteAll(servers[2].internalServerNumber, 'accountVideoRate') | 83 | await servers[2].sqlCommand.deleteAll('accountVideoRate') |
90 | for (const uuid of videoUUIDs) { | 84 | for (const uuid of videoUUIDs) { |
91 | await setVideoField(servers[2].internalServerNumber, uuid, 'likes', '0') | 85 | await servers[2].sqlCommand.setVideoField(uuid, 'likes', '0') |
92 | } | 86 | } |
93 | 87 | ||
94 | await wait(5000) | 88 | await wait(5000) |
@@ -132,10 +126,10 @@ describe('Test AP cleaner', function () { | |||
132 | 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 () { |
133 | this.timeout(20000) | 127 | this.timeout(20000) |
134 | 128 | ||
135 | await deleteAll(servers[2].internalServerNumber, 'accountVideoRate') | 129 | await servers[2].sqlCommand.deleteAll('accountVideoRate') |
136 | 130 | ||
137 | for (const uuid of videoUUIDs) { | 131 | for (const uuid of videoUUIDs) { |
138 | await setVideoField(servers[2].internalServerNumber, uuid, 'dislikes', '0') | 132 | await servers[2].sqlCommand.setVideoField(uuid, 'dislikes', '0') |
139 | } | 133 | } |
140 | 134 | ||
141 | await wait(5000) | 135 | await wait(5000) |
@@ -159,15 +153,15 @@ describe('Test AP cleaner', function () { | |||
159 | 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 () { |
160 | this.timeout(20000) | 154 | this.timeout(20000) |
161 | 155 | ||
162 | const preCount = await getCount(servers[0].internalServerNumber, 'videoShare') | 156 | const preCount = await servers[0].sqlCommand.getCount('videoShare') |
163 | expect(preCount).to.equal(6) | 157 | expect(preCount).to.equal(6) |
164 | 158 | ||
165 | await deleteAll(servers[2].internalServerNumber, 'videoShare') | 159 | await servers[2].sqlCommand.deleteAll('videoShare') |
166 | await wait(5000) | 160 | await wait(5000) |
167 | await waitJobs(servers) | 161 | await waitJobs(servers) |
168 | 162 | ||
169 | // 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 |
170 | const postCount = await getCount(servers[0].internalServerNumber, 'videoShare') | 164 | const postCount = await servers[0].sqlCommand.getCount('videoShare') |
171 | expect(postCount).to.equal(6) | 165 | expect(postCount).to.equal(6) |
172 | }) | 166 | }) |
173 | 167 | ||
@@ -179,7 +173,7 @@ describe('Test AP cleaner', function () { | |||
179 | expect(total).to.equal(3) | 173 | expect(total).to.equal(3) |
180 | } | 174 | } |
181 | 175 | ||
182 | await deleteAll(servers[2].internalServerNumber, 'videoComment') | 176 | await servers[2].sqlCommand.deleteAll('videoComment') |
183 | 177 | ||
184 | await wait(5000) | 178 | await wait(5000) |
185 | await waitJobs(servers) | 179 | await waitJobs(servers) |
@@ -196,7 +190,7 @@ describe('Test AP cleaner', function () { | |||
196 | 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') { |
197 | const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` + | 191 | const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` + |
198 | `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}'` |
199 | const res = await selectQuery(servers[0].internalServerNumber, query) | 193 | const res = await servers[0].sqlCommand.selectQuery(query) |
200 | 194 | ||
201 | for (const rate of res) { | 195 | for (const rate of res) { |
202 | const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`) | 196 | const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`) |
@@ -225,7 +219,7 @@ describe('Test AP cleaner', function () { | |||
225 | 219 | ||
226 | { | 220 | { |
227 | const query = `UPDATE "accountVideoRate" SET url = url || 'stan'` | 221 | const query = `UPDATE "accountVideoRate" SET url = url || 'stan'` |
228 | await updateQuery(servers[1].internalServerNumber, query) | 222 | await servers[1].sqlCommand.updateQuery(query) |
229 | 223 | ||
230 | await wait(5000) | 224 | await wait(5000) |
231 | await waitJobs(servers) | 225 | await waitJobs(servers) |
@@ -242,7 +236,7 @@ describe('Test AP cleaner', function () { | |||
242 | const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` + | 236 | const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` + |
243 | `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}'` |
244 | 238 | ||
245 | const res = await selectQuery(servers[0].internalServerNumber, query) | 239 | const res = await servers[0].sqlCommand.selectQuery(query) |
246 | 240 | ||
247 | for (const comment of res) { | 241 | for (const comment of res) { |
248 | 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}`) |
@@ -268,7 +262,7 @@ describe('Test AP cleaner', function () { | |||
268 | 262 | ||
269 | { | 263 | { |
270 | const query = `UPDATE "videoComment" SET url = url || 'kyle'` | 264 | const query = `UPDATE "videoComment" SET url = url || 'kyle'` |
271 | await updateQuery(servers[1].internalServerNumber, query) | 265 | await servers[1].sqlCommand.updateQuery(query) |
272 | 266 | ||
273 | await wait(5000) | 267 | await wait(5000) |
274 | await waitJobs(servers) | 268 | await waitJobs(servers) |
@@ -280,7 +274,5 @@ describe('Test AP cleaner', function () { | |||
280 | 274 | ||
281 | after(async function () { | 275 | after(async function () { |
282 | await cleanupTests(servers) | 276 | await cleanupTests(servers) |
283 | |||
284 | await closeAllSequelize(servers) | ||
285 | }) | 277 | }) |
286 | }) | 278 | }) |
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index 35fd94eed..d5e21404c 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts | |||
@@ -1,23 +1,19 @@ | |||
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 'mocha' | 3 | import 'mocha' |
4 | 4 | import * as chai from 'chai' | |
5 | import { | 5 | import { |
6 | cleanupTests, | 6 | cleanupTests, |
7 | closeAllSequelize, | ||
8 | createUser, | 7 | createUser, |
9 | doubleFollow, | 8 | doubleFollow, |
10 | flushAndRunMultipleServers, | 9 | flushAndRunMultipleServers, |
11 | getVideosListSort, | 10 | getVideosListSort, |
12 | ServerInfo, | 11 | ServerInfo, |
13 | setAccessTokensToServers, | 12 | setAccessTokensToServers, |
14 | setActorField, | ||
15 | setVideoField, | ||
16 | uploadVideo, | 13 | uploadVideo, |
17 | userLogin, | 14 | userLogin, |
18 | waitJobs | 15 | waitJobs |
19 | } from '../../../../shared/extra-utils' | 16 | } from '../../../../shared/extra-utils' |
20 | import * as chai from 'chai' | ||
21 | import { Video } from '../../../../shared/models/videos' | 17 | import { Video } from '../../../../shared/models/videos' |
22 | 18 | ||
23 | const expect = chai.expect | 19 | const expect = chai.expect |
@@ -50,12 +46,12 @@ describe('Test ActivityPub fetcher', function () { | |||
50 | { | 46 | { |
51 | const to = 'http://localhost:' + servers[0].port + '/accounts/user1' | 47 | const to = 'http://localhost:' + servers[0].port + '/accounts/user1' |
52 | const value = 'http://localhost:' + servers[1].port + '/accounts/user1' | 48 | const value = 'http://localhost:' + servers[1].port + '/accounts/user1' |
53 | await setActorField(servers[0].internalServerNumber, to, 'url', value) | 49 | await servers[0].sqlCommand.setActorField(to, 'url', value) |
54 | } | 50 | } |
55 | 51 | ||
56 | { | 52 | { |
57 | const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID | 53 | const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID |
58 | await setVideoField(servers[0].internalServerNumber, badVideoUUID, 'url', value) | 54 | await servers[0].sqlCommand.setVideoField(badVideoUUID, 'url', value) |
59 | } | 55 | } |
60 | }) | 56 | }) |
61 | 57 | ||
@@ -88,7 +84,5 @@ describe('Test ActivityPub fetcher', function () { | |||
88 | this.timeout(20000) | 84 | this.timeout(20000) |
89 | 85 | ||
90 | await cleanupTests(servers) | 86 | await cleanupTests(servers) |
91 | |||
92 | await closeAllSequelize(servers) | ||
93 | }) | 87 | }) |
94 | }) | 88 | }) |
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index f295dfab7..af919f2f3 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.ts | |||
@@ -4,7 +4,6 @@ import 'mocha' | |||
4 | import { HttpStatusCode } from '@shared/core-utils' | 4 | import { HttpStatusCode } from '@shared/core-utils' |
5 | import { | 5 | import { |
6 | cleanupTests, | 6 | cleanupTests, |
7 | closeAllSequelize, | ||
8 | doubleFollow, | 7 | doubleFollow, |
9 | flushAndRunMultipleServers, | 8 | flushAndRunMultipleServers, |
10 | generateUserAccessToken, | 9 | generateUserAccessToken, |
@@ -13,10 +12,7 @@ import { | |||
13 | reRunServer, | 12 | reRunServer, |
14 | ServerInfo, | 13 | ServerInfo, |
15 | setAccessTokensToServers, | 14 | setAccessTokensToServers, |
16 | setActorField, | ||
17 | setDefaultVideoChannel, | 15 | setDefaultVideoChannel, |
18 | setPlaylistField, | ||
19 | setVideoField, | ||
20 | uploadVideo, | 16 | uploadVideo, |
21 | uploadVideoAndGetId, | 17 | uploadVideoAndGetId, |
22 | wait, | 18 | wait, |
@@ -78,7 +74,7 @@ describe('Test AP refresher', function () { | |||
78 | await wait(10000) | 74 | await wait(10000) |
79 | 75 | ||
80 | // Change UUID so the remote server returns a 404 | 76 | // Change UUID so the remote server returns a 404 |
81 | await setVideoField(servers[1].internalServerNumber, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') | 77 | await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') |
82 | 78 | ||
83 | await getVideo(servers[0].url, videoUUID1) | 79 | await getVideo(servers[0].url, videoUUID1) |
84 | await getVideo(servers[0].url, videoUUID2) | 80 | await getVideo(servers[0].url, videoUUID2) |
@@ -92,9 +88,9 @@ describe('Test AP refresher', function () { | |||
92 | it('Should not update a remote video if the remote instance is down', async function () { | 88 | it('Should not update a remote video if the remote instance is down', async function () { |
93 | this.timeout(70000) | 89 | this.timeout(70000) |
94 | 90 | ||
95 | killallServers([ servers[1] ]) | 91 | await killallServers([ servers[1] ]) |
96 | 92 | ||
97 | await setVideoField(servers[1].internalServerNumber, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') | 93 | await servers[1].sqlCommand.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') |
98 | 94 | ||
99 | // Video will need a refresh | 95 | // Video will need a refresh |
100 | await wait(10000) | 96 | await wait(10000) |
@@ -120,7 +116,7 @@ describe('Test AP refresher', function () { | |||
120 | 116 | ||
121 | // Change actor name so the remote server returns a 404 | 117 | // Change actor name so the remote server returns a 404 |
122 | const to = 'http://localhost:' + servers[1].port + '/accounts/user2' | 118 | const to = 'http://localhost:' + servers[1].port + '/accounts/user2' |
123 | await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto') | 119 | await servers[1].sqlCommand.setActorField(to, 'preferredUsername', 'toto') |
124 | 120 | ||
125 | await command.get({ accountName: 'user1@localhost:' + servers[1].port }) | 121 | await command.get({ accountName: 'user1@localhost:' + servers[1].port }) |
126 | await command.get({ accountName: 'user2@localhost:' + servers[1].port }) | 122 | await command.get({ accountName: 'user2@localhost:' + servers[1].port }) |
@@ -140,7 +136,7 @@ describe('Test AP refresher', function () { | |||
140 | await wait(10000) | 136 | await wait(10000) |
141 | 137 | ||
142 | // Change UUID so the remote server returns a 404 | 138 | // Change UUID so the remote server returns a 404 |
143 | await setPlaylistField(servers[1].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') | 139 | await servers[1].sqlCommand.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') |
144 | 140 | ||
145 | await servers[0].playlistsCommand.get({ playlistId: playlistUUID1 }) | 141 | await servers[0].playlistsCommand.get({ playlistId: playlistUUID1 }) |
146 | await servers[0].playlistsCommand.get({ playlistId: playlistUUID2 }) | 142 | await servers[0].playlistsCommand.get({ playlistId: playlistUUID2 }) |
@@ -156,7 +152,5 @@ describe('Test AP refresher', function () { | |||
156 | this.timeout(10000) | 152 | this.timeout(10000) |
157 | 153 | ||
158 | await cleanupTests(servers) | 154 | await cleanupTests(servers) |
159 | |||
160 | await closeAllSequelize(servers) | ||
161 | }) | 155 | }) |
162 | }) | 156 | }) |
diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts index 61db272f6..c32940070 100644 --- a/server/tests/api/activitypub/security.ts +++ b/server/tests/api/activitypub/security.ts | |||
@@ -7,12 +7,10 @@ import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-c | |||
7 | import { | 7 | import { |
8 | buildAbsoluteFixturePath, | 8 | buildAbsoluteFixturePath, |
9 | cleanupTests, | 9 | cleanupTests, |
10 | closeAllSequelize, | ||
11 | flushAndRunMultipleServers, | 10 | flushAndRunMultipleServers, |
12 | killallServers, | 11 | killallServers, |
13 | reRunServer, | 12 | reRunServer, |
14 | ServerInfo, | 13 | ServerInfo, |
15 | setActorField, | ||
16 | wait | 14 | wait |
17 | } from '../../../../shared/extra-utils' | 15 | } from '../../../../shared/extra-utils' |
18 | import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub' | 16 | import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub' |
@@ -26,8 +24,8 @@ function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey: | |||
26 | const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' | 24 | const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' |
27 | 25 | ||
28 | return Promise.all([ | 26 | return Promise.all([ |
29 | setActorField(onServer.internalServerNumber, url, 'publicKey', publicKey), | 27 | onServer.sqlCommand.setActorField(url, 'publicKey', publicKey), |
30 | setActorField(onServer.internalServerNumber, url, 'privateKey', privateKey) | 28 | onServer.sqlCommand.setActorField(url, 'privateKey', privateKey) |
31 | ]) | 29 | ]) |
32 | } | 30 | } |
33 | 31 | ||
@@ -35,8 +33,8 @@ function setUpdatedAtOfServer (onServer: ServerInfo, ofServer: ServerInfo, updat | |||
35 | const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' | 33 | const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' |
36 | 34 | ||
37 | return Promise.all([ | 35 | return Promise.all([ |
38 | setActorField(onServer.internalServerNumber, url, 'createdAt', updatedAt), | 36 | onServer.sqlCommand.setActorField(url, 'createdAt', updatedAt), |
39 | setActorField(onServer.internalServerNumber, url, 'updatedAt', updatedAt) | 37 | onServer.sqlCommand.setActorField(url, 'updatedAt', updatedAt) |
40 | ]) | 38 | ]) |
41 | } | 39 | } |
42 | 40 | ||
@@ -173,7 +171,7 @@ describe('Test ActivityPub security', function () { | |||
173 | await setUpdatedAtOfServer(servers[0], servers[1], '2015-07-17 22:00:00+00') | 171 | await setUpdatedAtOfServer(servers[0], servers[1], '2015-07-17 22:00:00+00') |
174 | 172 | ||
175 | // Invalid peertube actor cache | 173 | // Invalid peertube actor cache |
176 | killallServers([ servers[1] ]) | 174 | await killallServers([ servers[1] ]) |
177 | await reRunServer(servers[1]) | 175 | await reRunServer(servers[1]) |
178 | 176 | ||
179 | const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) | 177 | const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) |
@@ -294,7 +292,5 @@ describe('Test ActivityPub security', function () { | |||
294 | this.timeout(10000) | 292 | this.timeout(10000) |
295 | 293 | ||
296 | await cleanupTests(servers) | 294 | await cleanupTests(servers) |
297 | |||
298 | await closeAllSequelize(servers) | ||
299 | }) | 295 | }) |
300 | }) | 296 | }) |