From 9293139fde7091e9badcafa9b570b83cea9a10ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 15:37:43 +0200 Subject: Introduce sql command --- server/tests/api/activitypub/cleaner.ts | 32 ++++++++++++------------------- server/tests/api/activitypub/fetch.ts | 12 +++--------- server/tests/api/activitypub/refresher.ts | 16 +++++----------- server/tests/api/activitypub/security.ts | 14 +++++--------- 4 files changed, 25 insertions(+), 49 deletions(-) (limited to 'server/tests/api/activitypub') 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' import * as chai from 'chai' import { cleanupTests, - closeAllSequelize, - deleteAll, doubleFollow, flushAndRunMultipleServers, - getCount, getVideo, rateVideo, - selectQuery, ServerInfo, setAccessTokensToServers, - setVideoField, - updateQuery, uploadVideoAndGetId, wait, waitJobs @@ -86,9 +80,9 @@ describe('Test AP cleaner', function () { it('Should destroy server 3 internal likes and correctly clean them', async function () { this.timeout(20000) - await deleteAll(servers[2].internalServerNumber, 'accountVideoRate') + await servers[2].sqlCommand.deleteAll('accountVideoRate') for (const uuid of videoUUIDs) { - await setVideoField(servers[2].internalServerNumber, uuid, 'likes', '0') + await servers[2].sqlCommand.setVideoField(uuid, 'likes', '0') } await wait(5000) @@ -132,10 +126,10 @@ describe('Test AP cleaner', function () { it('Should destroy server 3 internal dislikes and correctly clean them', async function () { this.timeout(20000) - await deleteAll(servers[2].internalServerNumber, 'accountVideoRate') + await servers[2].sqlCommand.deleteAll('accountVideoRate') for (const uuid of videoUUIDs) { - await setVideoField(servers[2].internalServerNumber, uuid, 'dislikes', '0') + await servers[2].sqlCommand.setVideoField(uuid, 'dislikes', '0') } await wait(5000) @@ -159,15 +153,15 @@ describe('Test AP cleaner', function () { it('Should destroy server 3 internal shares and correctly clean them', async function () { this.timeout(20000) - const preCount = await getCount(servers[0].internalServerNumber, 'videoShare') + const preCount = await servers[0].sqlCommand.getCount('videoShare') expect(preCount).to.equal(6) - await deleteAll(servers[2].internalServerNumber, 'videoShare') + await servers[2].sqlCommand.deleteAll('videoShare') await wait(5000) await waitJobs(servers) // Still 6 because we don't have remote shares on local videos - const postCount = await getCount(servers[0].internalServerNumber, 'videoShare') + const postCount = await servers[0].sqlCommand.getCount('videoShare') expect(postCount).to.equal(6) }) @@ -179,7 +173,7 @@ describe('Test AP cleaner', function () { expect(total).to.equal(3) } - await deleteAll(servers[2].internalServerNumber, 'videoComment') + await servers[2].sqlCommand.deleteAll('videoComment') await wait(5000) await waitJobs(servers) @@ -196,7 +190,7 @@ describe('Test AP cleaner', function () { async function check (like: string, ofServerUrl: string, urlSuffix: string, remote: 'true' | 'false') { const query = `SELECT "videoId", "accountVideoRate".url FROM "accountVideoRate" ` + `INNER JOIN video ON "accountVideoRate"."videoId" = video.id AND remote IS ${remote} WHERE "accountVideoRate"."url" LIKE '${like}'` - const res = await selectQuery(servers[0].internalServerNumber, query) + const res = await servers[0].sqlCommand.selectQuery(query) for (const rate of res) { const matcher = new RegExp(`^${ofServerUrl}/accounts/root/dislikes/\\d+${urlSuffix}$`) @@ -225,7 +219,7 @@ describe('Test AP cleaner', function () { { const query = `UPDATE "accountVideoRate" SET url = url || 'stan'` - await updateQuery(servers[1].internalServerNumber, query) + await servers[1].sqlCommand.updateQuery(query) await wait(5000) await waitJobs(servers) @@ -242,7 +236,7 @@ describe('Test AP cleaner', function () { const query = `SELECT "videoId", "videoComment".url, uuid as "videoUUID" FROM "videoComment" ` + `INNER JOIN video ON "videoComment"."videoId" = video.id AND remote IS ${remote} WHERE "videoComment"."url" LIKE '${like}'` - const res = await selectQuery(servers[0].internalServerNumber, query) + const res = await servers[0].sqlCommand.selectQuery(query) for (const comment of res) { const matcher = new RegExp(`${ofServerUrl}/videos/watch/${comment.videoUUID}/comments/\\d+${urlSuffix}`) @@ -268,7 +262,7 @@ describe('Test AP cleaner', function () { { const query = `UPDATE "videoComment" SET url = url || 'kyle'` - await updateQuery(servers[1].internalServerNumber, query) + await servers[1].sqlCommand.updateQuery(query) await wait(5000) await waitJobs(servers) @@ -280,7 +274,5 @@ describe('Test AP cleaner', function () { after(async function () { await cleanupTests(servers) - - await closeAllSequelize(servers) }) }) 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 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - +import * as chai from 'chai' import { cleanupTests, - closeAllSequelize, createUser, doubleFollow, flushAndRunMultipleServers, getVideosListSort, ServerInfo, setAccessTokensToServers, - setActorField, - setVideoField, uploadVideo, userLogin, waitJobs } from '../../../../shared/extra-utils' -import * as chai from 'chai' import { Video } from '../../../../shared/models/videos' const expect = chai.expect @@ -50,12 +46,12 @@ describe('Test ActivityPub fetcher', function () { { const to = 'http://localhost:' + servers[0].port + '/accounts/user1' const value = 'http://localhost:' + servers[1].port + '/accounts/user1' - await setActorField(servers[0].internalServerNumber, to, 'url', value) + await servers[0].sqlCommand.setActorField(to, 'url', value) } { const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID - await setVideoField(servers[0].internalServerNumber, badVideoUUID, 'url', value) + await servers[0].sqlCommand.setVideoField(badVideoUUID, 'url', value) } }) @@ -88,7 +84,5 @@ describe('Test ActivityPub fetcher', function () { this.timeout(20000) await cleanupTests(servers) - - await closeAllSequelize(servers) }) }) 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' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - closeAllSequelize, doubleFollow, flushAndRunMultipleServers, generateUserAccessToken, @@ -13,10 +12,7 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - setActorField, setDefaultVideoChannel, - setPlaylistField, - setVideoField, uploadVideo, uploadVideoAndGetId, wait, @@ -78,7 +74,7 @@ describe('Test AP refresher', function () { await wait(10000) // Change UUID so the remote server returns a 404 - await setVideoField(servers[1].internalServerNumber, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') + await servers[1].sqlCommand.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') await getVideo(servers[0].url, videoUUID1) await getVideo(servers[0].url, videoUUID2) @@ -92,9 +88,9 @@ describe('Test AP refresher', function () { it('Should not update a remote video if the remote instance is down', async function () { this.timeout(70000) - killallServers([ servers[1] ]) + await killallServers([ servers[1] ]) - await setVideoField(servers[1].internalServerNumber, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') + await servers[1].sqlCommand.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') // Video will need a refresh await wait(10000) @@ -120,7 +116,7 @@ describe('Test AP refresher', function () { // Change actor name so the remote server returns a 404 const to = 'http://localhost:' + servers[1].port + '/accounts/user2' - await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto') + await servers[1].sqlCommand.setActorField(to, 'preferredUsername', 'toto') await command.get({ accountName: 'user1@localhost:' + servers[1].port }) await command.get({ accountName: 'user2@localhost:' + servers[1].port }) @@ -140,7 +136,7 @@ describe('Test AP refresher', function () { await wait(10000) // Change UUID so the remote server returns a 404 - await setPlaylistField(servers[1].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') + await servers[1].sqlCommand.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') await servers[0].playlistsCommand.get({ playlistId: playlistUUID1 }) await servers[0].playlistsCommand.get({ playlistId: playlistUUID2 }) @@ -156,7 +152,5 @@ describe('Test AP refresher', function () { this.timeout(10000) await cleanupTests(servers) - - await closeAllSequelize(servers) }) }) 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 import { buildAbsoluteFixturePath, cleanupTests, - closeAllSequelize, flushAndRunMultipleServers, killallServers, reRunServer, ServerInfo, - setActorField, wait } from '../../../../shared/extra-utils' import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub' @@ -26,8 +24,8 @@ function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey: const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' return Promise.all([ - setActorField(onServer.internalServerNumber, url, 'publicKey', publicKey), - setActorField(onServer.internalServerNumber, url, 'privateKey', privateKey) + onServer.sqlCommand.setActorField(url, 'publicKey', publicKey), + onServer.sqlCommand.setActorField(url, 'privateKey', privateKey) ]) } @@ -35,8 +33,8 @@ function setUpdatedAtOfServer (onServer: ServerInfo, ofServer: ServerInfo, updat const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' return Promise.all([ - setActorField(onServer.internalServerNumber, url, 'createdAt', updatedAt), - setActorField(onServer.internalServerNumber, url, 'updatedAt', updatedAt) + onServer.sqlCommand.setActorField(url, 'createdAt', updatedAt), + onServer.sqlCommand.setActorField(url, 'updatedAt', updatedAt) ]) } @@ -173,7 +171,7 @@ describe('Test ActivityPub security', function () { await setUpdatedAtOfServer(servers[0], servers[1], '2015-07-17 22:00:00+00') // Invalid peertube actor cache - killallServers([ servers[1] ]) + await killallServers([ servers[1] ]) await reRunServer(servers[1]) const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) @@ -294,7 +292,5 @@ describe('Test ActivityPub security', function () { this.timeout(10000) await cleanupTests(servers) - - await closeAllSequelize(servers) }) }) -- cgit v1.2.3