diff options
Diffstat (limited to 'server/tests/api/activitypub')
-rw-r--r-- | server/tests/api/activitypub/client.ts | 11 | ||||
-rw-r--r-- | server/tests/api/activitypub/fetch.ts | 17 | ||||
-rw-r--r-- | server/tests/api/activitypub/refresher.ts | 46 | ||||
-rw-r--r-- | server/tests/api/activitypub/security.ts | 106 |
4 files changed, 104 insertions, 76 deletions
diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts index edf588c16..34c6be49b 100644 --- a/server/tests/api/activitypub/client.ts +++ b/server/tests/api/activitypub/client.ts | |||
@@ -3,6 +3,7 @@ | |||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { | 5 | import { |
6 | cleanupTests, | ||
6 | doubleFollow, | 7 | doubleFollow, |
7 | flushAndRunMultipleServers, | 8 | flushAndRunMultipleServers, |
8 | flushTests, | 9 | flushTests, |
@@ -39,7 +40,7 @@ describe('Test activitypub', function () { | |||
39 | const object = res.body | 40 | const object = res.body |
40 | 41 | ||
41 | expect(object.type).to.equal('Person') | 42 | expect(object.type).to.equal('Person') |
42 | expect(object.id).to.equal('http://localhost:9001/accounts/root') | 43 | expect(object.id).to.equal('http://localhost:' + servers[0].port + '/accounts/root') |
43 | expect(object.name).to.equal('root') | 44 | expect(object.name).to.equal('root') |
44 | expect(object.preferredUsername).to.equal('root') | 45 | expect(object.preferredUsername).to.equal('root') |
45 | }) | 46 | }) |
@@ -49,17 +50,17 @@ describe('Test activitypub', function () { | |||
49 | const object = res.body | 50 | const object = res.body |
50 | 51 | ||
51 | expect(object.type).to.equal('Video') | 52 | expect(object.type).to.equal('Video') |
52 | expect(object.id).to.equal('http://localhost:9001/videos/watch/' + videoUUID) | 53 | expect(object.id).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + videoUUID) |
53 | expect(object.name).to.equal('video') | 54 | expect(object.name).to.equal('video') |
54 | }) | 55 | }) |
55 | 56 | ||
56 | it('Should redirect to the origin video object', async function () { | 57 | it('Should redirect to the origin video object', async function () { |
57 | const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + videoUUID, 302) | 58 | const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + videoUUID, 302) |
58 | 59 | ||
59 | expect(res.header.location).to.equal('http://localhost:9001/videos/watch/' + videoUUID) | 60 | expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + videoUUID) |
60 | }) | 61 | }) |
61 | 62 | ||
62 | after(function () { | 63 | after(async function () { |
63 | killallServers(servers) | 64 | await cleanupTests(servers) |
64 | }) | 65 | }) |
65 | }) | 66 | }) |
diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index 7240bb0fb..3a1c0d321 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts | |||
@@ -3,6 +3,7 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | 4 | ||
5 | import { | 5 | import { |
6 | cleanupTests, | ||
6 | closeAllSequelize, | 7 | closeAllSequelize, |
7 | createUser, | 8 | createUser, |
8 | doubleFollow, | 9 | doubleFollow, |
@@ -48,8 +49,16 @@ describe('Test ActivityPub fetcher', function () { | |||
48 | const badVideoUUID = res.body.video.uuid | 49 | const badVideoUUID = res.body.video.uuid |
49 | await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' }) | 50 | await uploadVideo(servers[0].url, userAccessToken, { name: 'video user' }) |
50 | 51 | ||
51 | await setActorField(1, 'http://localhost:9001/accounts/user1', 'url', 'http://localhost:9002/accounts/user1') | 52 | { |
52 | await setVideoField(1, badVideoUUID, 'url', 'http://localhost:9003/videos/watch/' + badVideoUUID) | 53 | const to = 'http://localhost:' + servers[0].port + '/accounts/user1' |
54 | const value = 'http://localhost:' + servers[1].port + '/accounts/user1' | ||
55 | await setActorField(servers[0].internalServerNumber, to, 'url', value) | ||
56 | } | ||
57 | |||
58 | { | ||
59 | const value = 'http://localhost:' + servers[2].port + '/videos/watch/' + badVideoUUID | ||
60 | await setVideoField(servers[0].internalServerNumber, badVideoUUID, 'url', value) | ||
61 | } | ||
53 | }) | 62 | }) |
54 | 63 | ||
55 | it('Should add only the video with a valid actor URL', async function () { | 64 | it('Should add only the video with a valid actor URL', async function () { |
@@ -78,7 +87,9 @@ describe('Test ActivityPub fetcher', function () { | |||
78 | }) | 87 | }) |
79 | 88 | ||
80 | after(async function () { | 89 | after(async function () { |
81 | killallServers(servers) | 90 | this.timeout(10000) |
91 | |||
92 | await cleanupTests(servers) | ||
82 | 93 | ||
83 | await closeAllSequelize(servers) | 94 | await closeAllSequelize(servers) |
84 | }) | 95 | }) |
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index 9be9aa495..921ee874c 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.ts | |||
@@ -2,13 +2,14 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { | 4 | import { |
5 | cleanupTests, closeAllSequelize, | ||
5 | createVideoPlaylist, | 6 | createVideoPlaylist, |
6 | doubleFollow, | 7 | doubleFollow, |
7 | flushAndRunMultipleServers, | 8 | flushAndRunMultipleServers, |
8 | generateUserAccessToken, | 9 | generateUserAccessToken, |
9 | getVideo, | 10 | getVideo, |
10 | getVideoPlaylist, | 11 | getVideoPlaylist, |
11 | killallServers, rateVideo, | 12 | killallServers, |
12 | reRunServer, | 13 | reRunServer, |
13 | ServerInfo, | 14 | ServerInfo, |
14 | setAccessTokensToServers, | 15 | setAccessTokensToServers, |
@@ -48,26 +49,26 @@ describe('Test AP refresher', function () { | |||
48 | } | 49 | } |
49 | 50 | ||
50 | { | 51 | { |
51 | const a1 = await generateUserAccessToken(servers[1], 'user1') | 52 | const a1 = await generateUserAccessToken(servers[ 1 ], 'user1') |
52 | await uploadVideo(servers[1].url, a1, { name: 'video4' }) | 53 | await uploadVideo(servers[ 1 ].url, a1, { name: 'video4' }) |
53 | 54 | ||
54 | const a2 = await generateUserAccessToken(servers[1], 'user2') | 55 | const a2 = await generateUserAccessToken(servers[ 1 ], 'user2') |
55 | await uploadVideo(servers[1].url, a2, { name: 'video5' }) | 56 | await uploadVideo(servers[ 1 ].url, a2, { name: 'video5' }) |
56 | } | 57 | } |
57 | 58 | ||
58 | { | 59 | { |
59 | const playlistAttrs = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } | 60 | const playlistAttrs = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[ 1 ].videoChannel.id } |
60 | const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs }) | 61 | const res = await createVideoPlaylist({ url: servers[ 1 ].url, token: servers[ 1 ].accessToken, playlistAttrs }) |
61 | playlistUUID1 = res.body.videoPlaylist.uuid | 62 | playlistUUID1 = res.body.videoPlaylist.uuid |
62 | } | 63 | } |
63 | 64 | ||
64 | { | 65 | { |
65 | const playlistAttrs = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].videoChannel.id } | 66 | const playlistAttrs = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[ 1 ].videoChannel.id } |
66 | const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs }) | 67 | const res = await createVideoPlaylist({ url: servers[ 1 ].url, token: servers[ 1 ].accessToken, playlistAttrs }) |
67 | playlistUUID2 = res.body.videoPlaylist.uuid | 68 | playlistUUID2 = res.body.videoPlaylist.uuid |
68 | } | 69 | } |
69 | 70 | ||
70 | await doubleFollow(servers[0], servers[1]) | 71 | await doubleFollow(servers[ 0 ], servers[ 1 ]) |
71 | }) | 72 | }) |
72 | 73 | ||
73 | describe('Videos refresher', function () { | 74 | describe('Videos refresher', function () { |
@@ -78,7 +79,7 @@ describe('Test AP refresher', function () { | |||
78 | await wait(10000) | 79 | await wait(10000) |
79 | 80 | ||
80 | // Change UUID so the remote server returns a 404 | 81 | // Change UUID so the remote server returns a 404 |
81 | await setVideoField(2, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') | 82 | await setVideoField(servers[ 1 ].internalServerNumber, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f') |
82 | 83 | ||
83 | await getVideo(servers[ 0 ].url, videoUUID1) | 84 | await getVideo(servers[ 0 ].url, videoUUID1) |
84 | await getVideo(servers[ 0 ].url, videoUUID2) | 85 | await getVideo(servers[ 0 ].url, videoUUID2) |
@@ -94,7 +95,7 @@ describe('Test AP refresher', function () { | |||
94 | 95 | ||
95 | killallServers([ servers[ 1 ] ]) | 96 | killallServers([ servers[ 1 ] ]) |
96 | 97 | ||
97 | await setVideoField(2, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') | 98 | await setVideoField(servers[ 1 ].internalServerNumber, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e') |
98 | 99 | ||
99 | // Video will need a refresh | 100 | // Video will need a refresh |
100 | await wait(10000) | 101 | await wait(10000) |
@@ -121,15 +122,16 @@ describe('Test AP refresher', function () { | |||
121 | await wait(10000) | 122 | await wait(10000) |
122 | 123 | ||
123 | // Change actor name so the remote server returns a 404 | 124 | // Change actor name so the remote server returns a 404 |
124 | await setActorField(2, 'http://localhost:9002/accounts/user2', 'preferredUsername', 'toto') | 125 | const to = 'http://localhost:' + servers[ 1 ].port + '/accounts/user2' |
126 | await setActorField(servers[ 1 ].internalServerNumber, to, 'preferredUsername', 'toto') | ||
125 | 127 | ||
126 | await getAccount(servers[ 0 ].url, 'user1@localhost:9002') | 128 | await getAccount(servers[ 0 ].url, 'user1@localhost:' + servers[ 1 ].port) |
127 | await getAccount(servers[ 0 ].url, 'user2@localhost:9002') | 129 | await getAccount(servers[ 0 ].url, 'user2@localhost:' + servers[ 1 ].port) |
128 | 130 | ||
129 | await waitJobs(servers) | 131 | await waitJobs(servers) |
130 | 132 | ||
131 | await getAccount(servers[ 0 ].url, 'user1@localhost:9002', 200) | 133 | await getAccount(servers[ 0 ].url, 'user1@localhost:' + servers[ 1 ].port, 200) |
132 | await getAccount(servers[ 0 ].url, 'user2@localhost:9002', 404) | 134 | await getAccount(servers[ 0 ].url, 'user2@localhost:' + servers[ 1 ].port, 404) |
133 | }) | 135 | }) |
134 | }) | 136 | }) |
135 | 137 | ||
@@ -141,7 +143,7 @@ describe('Test AP refresher', function () { | |||
141 | await wait(10000) | 143 | await wait(10000) |
142 | 144 | ||
143 | // Change UUID so the remote server returns a 404 | 145 | // Change UUID so the remote server returns a 404 |
144 | await setPlaylistField(2, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') | 146 | await setPlaylistField(servers[ 1 ].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e') |
145 | 147 | ||
146 | await getVideoPlaylist(servers[ 0 ].url, playlistUUID1) | 148 | await getVideoPlaylist(servers[ 0 ].url, playlistUUID1) |
147 | await getVideoPlaylist(servers[ 0 ].url, playlistUUID2) | 149 | await getVideoPlaylist(servers[ 0 ].url, playlistUUID2) |
@@ -153,7 +155,11 @@ describe('Test AP refresher', function () { | |||
153 | }) | 155 | }) |
154 | }) | 156 | }) |
155 | 157 | ||
156 | after(function () { | 158 | after(async function () { |
157 | killallServers(servers) | 159 | this.timeout(10000) |
160 | |||
161 | await cleanupTests(servers) | ||
162 | |||
163 | await closeAllSequelize(servers) | ||
158 | }) | 164 | }) |
159 | }) | 165 | }) |
diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts index 11e6859bf..dc960c5c3 100644 --- a/server/tests/api/activitypub/security.ts +++ b/server/tests/api/activitypub/security.ts | |||
@@ -3,9 +3,9 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | 4 | ||
5 | import { | 5 | import { |
6 | cleanupTests, | ||
6 | closeAllSequelize, | 7 | closeAllSequelize, |
7 | flushAndRunMultipleServers, | 8 | flushAndRunMultipleServers, |
8 | flushTests, | ||
9 | killallServers, | 9 | killallServers, |
10 | ServerInfo, | 10 | ServerInfo, |
11 | setActorField | 11 | setActorField |
@@ -18,18 +18,26 @@ import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-u | |||
18 | 18 | ||
19 | const expect = chai.expect | 19 | const expect = chai.expect |
20 | 20 | ||
21 | function setKeysOfServer2 (serverNumber: number, publicKey: string, privateKey: string) { | 21 | function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey: string, privateKey: string) { |
22 | return Promise.all([ | 22 | return Promise.all([ |
23 | setActorField(serverNumber, 'http://localhost:9002/accounts/peertube', 'publicKey', publicKey), | 23 | setActorField(onServer.internalServerNumber, 'http://localhost:' + ofServer.port + '/accounts/peertube', 'publicKey', publicKey), |
24 | setActorField(serverNumber, 'http://localhost:9002/accounts/peertube', 'privateKey', privateKey) | 24 | setActorField(onServer.internalServerNumber, 'http://localhost:' + ofServer.port + '/accounts/peertube', 'privateKey', privateKey) |
25 | ]) | 25 | ]) |
26 | } | 26 | } |
27 | 27 | ||
28 | function setKeysOfServer3 (serverNumber: number, publicKey: string, privateKey: string) { | 28 | function getAnnounceWithoutContext (server2: ServerInfo) { |
29 | return Promise.all([ | 29 | const json = require('./json/peertube/announce-without-context.json') |
30 | setActorField(serverNumber, 'http://localhost:9003/accounts/peertube', 'publicKey', publicKey), | 30 | const result: typeof json = {} |
31 | setActorField(serverNumber, 'http://localhost:9003/accounts/peertube', 'privateKey', privateKey) | 31 | |
32 | ]) | 32 | for (const key of Object.keys(json)) { |
33 | if (Array.isArray(json[key])) { | ||
34 | result[key] = json[key].map(v => v.replace(':9002', `:${server2.port}`)) | ||
35 | } else { | ||
36 | result[ key ] = json[ key ].replace(':9002', `:${server2.port}`) | ||
37 | } | ||
38 | } | ||
39 | |||
40 | return result | ||
33 | } | 41 | } |
34 | 42 | ||
35 | describe('Test ActivityPub security', function () { | 43 | describe('Test ActivityPub security', function () { |
@@ -38,13 +46,13 @@ describe('Test ActivityPub security', function () { | |||
38 | 46 | ||
39 | const keys = require('./json/peertube/keys.json') | 47 | const keys = require('./json/peertube/keys.json') |
40 | const invalidKeys = require('./json/peertube/invalid-keys.json') | 48 | const invalidKeys = require('./json/peertube/invalid-keys.json') |
41 | const baseHttpSignature = { | 49 | const baseHttpSignature = () => ({ |
42 | algorithm: HTTP_SIGNATURE.ALGORITHM, | 50 | algorithm: HTTP_SIGNATURE.ALGORITHM, |
43 | authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME, | 51 | authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME, |
44 | keyId: 'acct:peertube@localhost:9002', | 52 | keyId: 'acct:peertube@localhost:' + servers[1].port, |
45 | key: keys.privateKey, | 53 | key: keys.privateKey, |
46 | headers: HTTP_SIGNATURE.HEADERS_TO_SIGN | 54 | headers: HTTP_SIGNATURE.HEADERS_TO_SIGN |
47 | } | 55 | }) |
48 | 56 | ||
49 | // --------------------------------------------------------------- | 57 | // --------------------------------------------------------------- |
50 | 58 | ||
@@ -55,56 +63,56 @@ describe('Test ActivityPub security', function () { | |||
55 | 63 | ||
56 | url = servers[0].url + '/inbox' | 64 | url = servers[0].url + '/inbox' |
57 | 65 | ||
58 | await setKeysOfServer2(1, keys.publicKey, keys.privateKey) | 66 | await setKeysOfServer(servers[0], servers[1], keys.publicKey, keys.privateKey) |
59 | 67 | ||
60 | const to = { url: 'http://localhost:9001/accounts/peertube' } | 68 | const to = { url: 'http://localhost:' + servers[0].port + '/accounts/peertube' } |
61 | const by = { url: 'http://localhost:9002/accounts/peertube', privateKey: keys.privateKey } | 69 | const by = { url: 'http://localhost:' + servers[1].port + '/accounts/peertube', privateKey: keys.privateKey } |
62 | await makeFollowRequest(to, by) | 70 | await makeFollowRequest(to, by) |
63 | }) | 71 | }) |
64 | 72 | ||
65 | describe('When checking HTTP signature', function () { | 73 | describe('When checking HTTP signature', function () { |
66 | 74 | ||
67 | it('Should fail with an invalid digest', async function () { | 75 | it('Should fail with an invalid digest', async function () { |
68 | const body = activityPubContextify(require('./json/peertube/announce-without-context.json')) | 76 | const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) |
69 | const headers = { | 77 | const headers = { |
70 | Digest: buildDigest({ hello: 'coucou' }) | 78 | Digest: buildDigest({ hello: 'coucou' }) |
71 | } | 79 | } |
72 | 80 | ||
73 | const { response } = await makePOSTAPRequest(url, body, baseHttpSignature, headers) | 81 | const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) |
74 | 82 | ||
75 | expect(response.statusCode).to.equal(403) | 83 | expect(response.statusCode).to.equal(403) |
76 | }) | 84 | }) |
77 | 85 | ||
78 | it('Should fail with an invalid date', async function () { | 86 | it('Should fail with an invalid date', async function () { |
79 | const body = activityPubContextify(require('./json/peertube/announce-without-context.json')) | 87 | const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) |
80 | const headers = buildGlobalHeaders(body) | 88 | const headers = buildGlobalHeaders(body) |
81 | headers['date'] = 'Wed, 21 Oct 2015 07:28:00 GMT' | 89 | headers['date'] = 'Wed, 21 Oct 2015 07:28:00 GMT' |
82 | 90 | ||
83 | const { response } = await makePOSTAPRequest(url, body, baseHttpSignature, headers) | 91 | const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) |
84 | 92 | ||
85 | expect(response.statusCode).to.equal(403) | 93 | expect(response.statusCode).to.equal(403) |
86 | }) | 94 | }) |
87 | 95 | ||
88 | it('Should fail with bad keys', async function () { | 96 | it('Should fail with bad keys', async function () { |
89 | await setKeysOfServer2(1, invalidKeys.publicKey, invalidKeys.privateKey) | 97 | await setKeysOfServer(servers[0], servers[1], invalidKeys.publicKey, invalidKeys.privateKey) |
90 | await setKeysOfServer2(2, invalidKeys.publicKey, invalidKeys.privateKey) | 98 | await setKeysOfServer(servers[1], servers[1], invalidKeys.publicKey, invalidKeys.privateKey) |
91 | 99 | ||
92 | const body = activityPubContextify(require('./json/peertube/announce-without-context.json')) | 100 | const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) |
93 | const headers = buildGlobalHeaders(body) | 101 | const headers = buildGlobalHeaders(body) |
94 | 102 | ||
95 | const { response } = await makePOSTAPRequest(url, body, baseHttpSignature, headers) | 103 | const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) |
96 | 104 | ||
97 | expect(response.statusCode).to.equal(403) | 105 | expect(response.statusCode).to.equal(403) |
98 | }) | 106 | }) |
99 | 107 | ||
100 | it('Should succeed with a valid HTTP signature', async function () { | 108 | it('Should succeed with a valid HTTP signature', async function () { |
101 | await setKeysOfServer2(1, keys.publicKey, keys.privateKey) | 109 | await setKeysOfServer(servers[0], servers[1], keys.publicKey, keys.privateKey) |
102 | await setKeysOfServer2(2, keys.publicKey, keys.privateKey) | 110 | await setKeysOfServer(servers[1], servers[1], keys.publicKey, keys.privateKey) |
103 | 111 | ||
104 | const body = activityPubContextify(require('./json/peertube/announce-without-context.json')) | 112 | const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) |
105 | const headers = buildGlobalHeaders(body) | 113 | const headers = buildGlobalHeaders(body) |
106 | 114 | ||
107 | const { response } = await makePOSTAPRequest(url, body, baseHttpSignature, headers) | 115 | const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) |
108 | 116 | ||
109 | expect(response.statusCode).to.equal(204) | 117 | expect(response.statusCode).to.equal(204) |
110 | }) | 118 | }) |
@@ -112,28 +120,28 @@ describe('Test ActivityPub security', function () { | |||
112 | 120 | ||
113 | describe('When checking Linked Data Signature', function () { | 121 | describe('When checking Linked Data Signature', function () { |
114 | before(async () => { | 122 | before(async () => { |
115 | await setKeysOfServer3(3, keys.publicKey, keys.privateKey) | 123 | await setKeysOfServer(servers[2], servers[2], keys.publicKey, keys.privateKey) |
116 | 124 | ||
117 | const to = { url: 'http://localhost:9001/accounts/peertube' } | 125 | const to = { url: 'http://localhost:' + servers[0].port + '/accounts/peertube' } |
118 | const by = { url: 'http://localhost:9003/accounts/peertube', privateKey: keys.privateKey } | 126 | const by = { url: 'http://localhost:' + servers[2].port + '/accounts/peertube', privateKey: keys.privateKey } |
119 | await makeFollowRequest(to, by) | 127 | await makeFollowRequest(to, by) |
120 | }) | 128 | }) |
121 | 129 | ||
122 | it('Should fail with bad keys', async function () { | 130 | it('Should fail with bad keys', async function () { |
123 | this.timeout(10000) | 131 | this.timeout(10000) |
124 | 132 | ||
125 | await setKeysOfServer3(1, invalidKeys.publicKey, invalidKeys.privateKey) | 133 | await setKeysOfServer(servers[0], servers[2], invalidKeys.publicKey, invalidKeys.privateKey) |
126 | await setKeysOfServer3(3, invalidKeys.publicKey, invalidKeys.privateKey) | 134 | await setKeysOfServer(servers[2], servers[2], invalidKeys.publicKey, invalidKeys.privateKey) |
127 | 135 | ||
128 | const body = require('./json/peertube/announce-without-context.json') | 136 | const body = getAnnounceWithoutContext(servers[1]) |
129 | body.actor = 'http://localhost:9003/accounts/peertube' | 137 | body.actor = 'http://localhost:' + servers[2].port + '/accounts/peertube' |
130 | 138 | ||
131 | const signer: any = { privateKey: invalidKeys.privateKey, url: 'http://localhost:9003/accounts/peertube' } | 139 | const signer: any = { privateKey: invalidKeys.privateKey, url: 'http://localhost:' + servers[2].port + '/accounts/peertube' } |
132 | const signedBody = await buildSignedActivity(signer, body) | 140 | const signedBody = await buildSignedActivity(signer, body) |
133 | 141 | ||
134 | const headers = buildGlobalHeaders(signedBody) | 142 | const headers = buildGlobalHeaders(signedBody) |
135 | 143 | ||
136 | const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature, headers) | 144 | const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) |
137 | 145 | ||
138 | expect(response.statusCode).to.equal(403) | 146 | expect(response.statusCode).to.equal(403) |
139 | }) | 147 | }) |
@@ -141,20 +149,20 @@ describe('Test ActivityPub security', function () { | |||
141 | it('Should fail with an altered body', async function () { | 149 | it('Should fail with an altered body', async function () { |
142 | this.timeout(10000) | 150 | this.timeout(10000) |
143 | 151 | ||
144 | await setKeysOfServer3(1, keys.publicKey, keys.privateKey) | 152 | await setKeysOfServer(servers[0], servers[2], keys.publicKey, keys.privateKey) |
145 | await setKeysOfServer3(3, keys.publicKey, keys.privateKey) | 153 | await setKeysOfServer(servers[0], servers[2], keys.publicKey, keys.privateKey) |
146 | 154 | ||
147 | const body = require('./json/peertube/announce-without-context.json') | 155 | const body = getAnnounceWithoutContext(servers[1]) |
148 | body.actor = 'http://localhost:9003/accounts/peertube' | 156 | body.actor = 'http://localhost:' + servers[2].port + '/accounts/peertube' |
149 | 157 | ||
150 | const signer: any = { privateKey: keys.privateKey, url: 'http://localhost:9003/accounts/peertube' } | 158 | const signer: any = { privateKey: keys.privateKey, url: 'http://localhost:' + servers[2].port + '/accounts/peertube' } |
151 | const signedBody = await buildSignedActivity(signer, body) | 159 | const signedBody = await buildSignedActivity(signer, body) |
152 | 160 | ||
153 | signedBody.actor = 'http://localhost:9003/account/peertube' | 161 | signedBody.actor = 'http://localhost:' + servers[2].port + '/account/peertube' |
154 | 162 | ||
155 | const headers = buildGlobalHeaders(signedBody) | 163 | const headers = buildGlobalHeaders(signedBody) |
156 | 164 | ||
157 | const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature, headers) | 165 | const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) |
158 | 166 | ||
159 | expect(response.statusCode).to.equal(403) | 167 | expect(response.statusCode).to.equal(403) |
160 | }) | 168 | }) |
@@ -162,22 +170,24 @@ describe('Test ActivityPub security', function () { | |||
162 | it('Should succeed with a valid signature', async function () { | 170 | it('Should succeed with a valid signature', async function () { |
163 | this.timeout(10000) | 171 | this.timeout(10000) |
164 | 172 | ||
165 | const body = require('./json/peertube/announce-without-context.json') | 173 | const body = getAnnounceWithoutContext(servers[1]) |
166 | body.actor = 'http://localhost:9003/accounts/peertube' | 174 | body.actor = 'http://localhost:' + servers[2].port + '/accounts/peertube' |
167 | 175 | ||
168 | const signer: any = { privateKey: keys.privateKey, url: 'http://localhost:9003/accounts/peertube' } | 176 | const signer: any = { privateKey: keys.privateKey, url: 'http://localhost:' + servers[2].port + '/accounts/peertube' } |
169 | const signedBody = await buildSignedActivity(signer, body) | 177 | const signedBody = await buildSignedActivity(signer, body) |
170 | 178 | ||
171 | const headers = buildGlobalHeaders(signedBody) | 179 | const headers = buildGlobalHeaders(signedBody) |
172 | 180 | ||
173 | const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature, headers) | 181 | const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) |
174 | 182 | ||
175 | expect(response.statusCode).to.equal(204) | 183 | expect(response.statusCode).to.equal(204) |
176 | }) | 184 | }) |
177 | }) | 185 | }) |
178 | 186 | ||
179 | after(async function () { | 187 | after(async function () { |
180 | killallServers(servers) | 188 | this.timeout(10000) |
189 | |||
190 | await cleanupTests(servers) | ||
181 | 191 | ||
182 | await closeAllSequelize(servers) | 192 | await closeAllSequelize(servers) |
183 | }) | 193 | }) |