diff options
author | Chocobozzz <me@florianbigard.com> | 2021-03-10 11:17:20 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-03-24 18:18:40 +0100 |
commit | e7053b1d9d7f77d0375155b38d3e845f2163ecd8 (patch) | |
tree | b52375913c9b0352f5c765c40122cbbbc54bad13 /server/tests/api | |
parent | 266131e0ca2f2622bbb15299212f00b1efa36867 (diff) | |
download | PeerTube-e7053b1d9d7f77d0375155b38d3e845f2163ecd8.tar.gz PeerTube-e7053b1d9d7f77d0375155b38d3e845f2163ecd8.tar.zst PeerTube-e7053b1d9d7f77d0375155b38d3e845f2163ecd8.zip |
Fix AP security tests
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/activitypub/security.ts | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts index 9745052a3..364b53e0f 100644 --- a/server/tests/api/activitypub/security.ts +++ b/server/tests/api/activitypub/security.ts | |||
@@ -8,6 +8,8 @@ import { | |||
8 | cleanupTests, | 8 | cleanupTests, |
9 | closeAllSequelize, | 9 | closeAllSequelize, |
10 | flushAndRunMultipleServers, | 10 | flushAndRunMultipleServers, |
11 | killallServers, | ||
12 | reRunServer, | ||
11 | ServerInfo, | 13 | ServerInfo, |
12 | setActorField, | 14 | setActorField, |
13 | wait | 15 | wait |
@@ -20,21 +22,32 @@ import { buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activi | |||
20 | const expect = chai.expect | 22 | const expect = chai.expect |
21 | 23 | ||
22 | function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey: string, privateKey: string) { | 24 | function setKeysOfServer (onServer: ServerInfo, ofServer: ServerInfo, publicKey: string, privateKey: string) { |
25 | const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' | ||
26 | |||
27 | return Promise.all([ | ||
28 | setActorField(onServer.internalServerNumber, url, 'publicKey', publicKey), | ||
29 | setActorField(onServer.internalServerNumber, url, 'privateKey', privateKey) | ||
30 | ]) | ||
31 | } | ||
32 | |||
33 | function setUpdatedAtOfServer (onServer: ServerInfo, ofServer: ServerInfo, updatedAt: string) { | ||
34 | const url = 'http://localhost:' + ofServer.port + '/accounts/peertube' | ||
35 | |||
23 | return Promise.all([ | 36 | return Promise.all([ |
24 | setActorField(onServer.internalServerNumber, 'http://localhost:' + ofServer.port + '/accounts/peertube', 'publicKey', publicKey), | 37 | setActorField(onServer.internalServerNumber, url, 'createdAt', updatedAt), |
25 | setActorField(onServer.internalServerNumber, 'http://localhost:' + ofServer.port + '/accounts/peertube', 'privateKey', privateKey) | 38 | setActorField(onServer.internalServerNumber, url, 'updatedAt', updatedAt) |
26 | ]) | 39 | ]) |
27 | } | 40 | } |
28 | 41 | ||
29 | function getAnnounceWithoutContext (server2: ServerInfo) { | 42 | function getAnnounceWithoutContext (server: ServerInfo) { |
30 | const json = require('./json/peertube/announce-without-context.json') | 43 | const json = require('./json/peertube/announce-without-context.json') |
31 | const result: typeof json = {} | 44 | const result: typeof json = {} |
32 | 45 | ||
33 | for (const key of Object.keys(json)) { | 46 | for (const key of Object.keys(json)) { |
34 | if (Array.isArray(json[key])) { | 47 | if (Array.isArray(json[key])) { |
35 | result[key] = json[key].map(v => v.replace(':9002', `:${server2.port}`)) | 48 | result[key] = json[key].map(v => v.replace(':9002', `:${server.port}`)) |
36 | } else { | 49 | } else { |
37 | result[key] = json[key].replace(':9002', `:${server2.port}`) | 50 | result[key] = json[key].replace(':9002', `:${server.port}`) |
38 | } | 51 | } |
39 | } | 52 | } |
40 | 53 | ||
@@ -64,7 +77,8 @@ describe('Test ActivityPub security', function () { | |||
64 | 77 | ||
65 | url = servers[0].url + '/inbox' | 78 | url = servers[0].url + '/inbox' |
66 | 79 | ||
67 | await setKeysOfServer(servers[0], servers[1], keys.publicKey, keys.privateKey) | 80 | await setKeysOfServer(servers[0], servers[1], keys.publicKey, null) |
81 | await setKeysOfServer(servers[1], servers[1], keys.publicKey, keys.privateKey) | ||
68 | 82 | ||
69 | const to = { url: 'http://localhost:' + servers[0].port + '/accounts/peertube' } | 83 | const to = { url: 'http://localhost:' + servers[0].port + '/accounts/peertube' } |
70 | const by = { url: 'http://localhost:' + servers[1].port + '/accounts/peertube', privateKey: keys.privateKey } | 84 | const by = { url: 'http://localhost:' + servers[1].port + '/accounts/peertube', privateKey: keys.privateKey } |
@@ -152,12 +166,14 @@ describe('Test ActivityPub security', function () { | |||
152 | it('Should refresh the actor keys', async function () { | 166 | it('Should refresh the actor keys', async function () { |
153 | this.timeout(20000) | 167 | this.timeout(20000) |
154 | 168 | ||
155 | // Wait refresh invalidation | ||
156 | await wait(10000) | ||
157 | |||
158 | // Update keys of server 2 to invalid keys | 169 | // Update keys of server 2 to invalid keys |
159 | // Server 1 should refresh the actor and fail | 170 | // Server 1 should refresh the actor and fail |
160 | await setKeysOfServer(servers[1], servers[1], invalidKeys.publicKey, invalidKeys.privateKey) | 171 | await setKeysOfServer(servers[1], servers[1], invalidKeys.publicKey, invalidKeys.privateKey) |
172 | await setUpdatedAtOfServer(servers[0], servers[1], '2015-07-17 22:00:00+00') | ||
173 | |||
174 | // Invalid peertube actor cache | ||
175 | killallServers([ servers[1] ]) | ||
176 | await reRunServer(servers[1]) | ||
161 | 177 | ||
162 | const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) | 178 | const body = activityPubContextify(getAnnounceWithoutContext(servers[1])) |
163 | const headers = buildGlobalHeaders(body) | 179 | const headers = buildGlobalHeaders(body) |
@@ -166,6 +182,7 @@ describe('Test ActivityPub security', function () { | |||
166 | await makePOSTAPRequest(url, body, baseHttpSignature(), headers) | 182 | await makePOSTAPRequest(url, body, baseHttpSignature(), headers) |
167 | expect(true, 'Did not throw').to.be.false | 183 | expect(true, 'Did not throw').to.be.false |
168 | } catch (err) { | 184 | } catch (err) { |
185 | console.error(err) | ||
169 | expect(err.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) | 186 | expect(err.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) |
170 | } | 187 | } |
171 | }) | 188 | }) |