diff options
Diffstat (limited to 'server/tests/api/activitypub/security.ts')
-rw-r--r-- | server/tests/api/activitypub/security.ts | 46 |
1 files changed, 17 insertions, 29 deletions
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 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { activityPubContextify, buildSignedActivity } from '@server/helpers/activitypub' | ||
5 | import { buildDigest } from '@server/helpers/peertube-crypto' | 6 | import { buildDigest } from '@server/helpers/peertube-crypto' |
6 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 7 | import { HTTP_SIGNATURE } from '@server/initializers/constants' |
7 | import { | 8 | import { buildGlobalHeaders } from '@server/lib/job-queue/handlers/utils/activitypub-http-utils' |
8 | buildAbsoluteFixturePath, | 9 | import { buildAbsoluteFixturePath, cleanupTests, createMultipleServers, killallServers, PeerTubeServer, wait } from '@shared/extra-utils' |
9 | cleanupTests, | 10 | import { makeFollowRequest, makePOSTAPRequest } from '@shared/extra-utils/requests/activitypub' |
10 | closeAllSequelize, | 11 | import { HttpStatusCode } from '@shared/models' |
11 | flushAndRunMultipleServers, | ||
12 | killallServers, | ||
13 | reRunServer, | ||
14 | ServerInfo, | ||
15 | setActorField, | ||
16 | wait | ||
17 | } from '../../../../shared/extra-utils' | ||
18 | import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub' | ||
19 | import { activityPubContextify, buildSignedActivity } from '../../../helpers/activitypub' | ||
20 | import { HTTP_SIGNATURE } from '../../../initializers/constants' | ||
21 | import { buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activitypub-http-utils' | ||
22 | 12 | ||
23 | const expect = chai.expect | 13 | const expect = chai.expect |
24 | 14 | ||
25 | function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey: string, privateKey: string) { | 15 | function 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 | ||
34 | function setUpdatedAtOfServer (onServer: ServerInfo, ofServer: ServerInfo, updatedAt: string) { | 24 | function 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 | ||
43 | function getAnnounceWithoutContext (server: ServerInfo) { | 33 | function 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 | ||
58 | describe('Test ActivityPub security', function () { | 48 | describe('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 | }) |