aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/activitypub/helpers.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-14 16:52:22 +0200
committerChocobozzz <chocobozzz@cpy.re>2021-06-15 08:21:12 +0200
commit3d470a530c4a48b2e4f4a9e7d4f223e14f32cea4 (patch)
tree7305399caecbf7380319bd08e21c933de88096dc /server/tests/api/activitypub/helpers.ts
parent79db409a41bd28fd2773626c9a93b5d326a38bc0 (diff)
downloadPeerTube-3d470a530c4a48b2e4f4a9e7d4f223e14f32cea4.tar.gz
PeerTube-3d470a530c4a48b2e4f4a9e7d4f223e14f32cea4.tar.zst
PeerTube-3d470a530c4a48b2e4f4a9e7d4f223e14f32cea4.zip
Faster ci using compiled ts files
Diffstat (limited to 'server/tests/api/activitypub/helpers.ts')
-rw-r--r--server/tests/api/activitypub/helpers.ts37
1 files changed, 19 insertions, 18 deletions
diff --git a/server/tests/api/activitypub/helpers.ts b/server/tests/api/activitypub/helpers.ts
index 60d95b823..66d7631b7 100644
--- a/server/tests/api/activitypub/helpers.ts
+++ b/server/tests/api/activitypub/helpers.ts
@@ -6,13 +6,14 @@ import { buildRequestStub } from '../../../../shared/extra-utils/miscs/stubs'
6import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto' 6import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto'
7import { cloneDeep } from 'lodash' 7import { cloneDeep } from 'lodash'
8import { buildSignedActivity } from '../../../helpers/activitypub' 8import { buildSignedActivity } from '../../../helpers/activitypub'
9import { buildAbsoluteFixturePath } from '@shared/extra-utils'
9 10
10describe('Test activity pub helpers', function () { 11describe('Test activity pub helpers', function () {
11 describe('When checking the Linked Signature', function () { 12 describe('When checking the Linked Signature', function () {
12 13
13 it('Should fail with an invalid Mastodon signature', async function () { 14 it('Should fail with an invalid Mastodon signature', async function () {
14 const body = require('./json/mastodon/create-bad-signature.json') 15 const body = require(buildAbsoluteFixturePath('./ap-json/mastodon/create-bad-signature.json'))
15 const publicKey = require('./json/mastodon/public-key.json').publicKey 16 const publicKey = require(buildAbsoluteFixturePath('./ap-json/mastodon/public-key.json')).publicKey
16 const fromActor = { publicKey, url: 'http://localhost:9002/accounts/peertube' } 17 const fromActor = { publicKey, url: 'http://localhost:9002/accounts/peertube' }
17 18
18 const result = await isJsonLDSignatureVerified(fromActor as any, body) 19 const result = await isJsonLDSignatureVerified(fromActor as any, body)
@@ -21,8 +22,8 @@ describe('Test activity pub helpers', function () {
21 }) 22 })
22 23
23 it('Should fail with an invalid public key', async function () { 24 it('Should fail with an invalid public key', async function () {
24 const body = require('./json/mastodon/create.json') 25 const body = require(buildAbsoluteFixturePath('./ap-json/mastodon/create.json'))
25 const publicKey = require('./json/mastodon/bad-public-key.json').publicKey 26 const publicKey = require(buildAbsoluteFixturePath('./ap-json/mastodon/bad-public-key.json')).publicKey
26 const fromActor = { publicKey, url: 'http://localhost:9002/accounts/peertube' } 27 const fromActor = { publicKey, url: 'http://localhost:9002/accounts/peertube' }
27 28
28 const result = await isJsonLDSignatureVerified(fromActor as any, body) 29 const result = await isJsonLDSignatureVerified(fromActor as any, body)
@@ -31,8 +32,8 @@ describe('Test activity pub helpers', function () {
31 }) 32 })
32 33
33 it('Should succeed with a valid Mastodon signature', async function () { 34 it('Should succeed with a valid Mastodon signature', async function () {
34 const body = require('./json/mastodon/create.json') 35 const body = require(buildAbsoluteFixturePath('./ap-json/mastodon/create.json'))
35 const publicKey = require('./json/mastodon/public-key.json').publicKey 36 const publicKey = require(buildAbsoluteFixturePath('./ap-json/mastodon/public-key.json')).publicKey
36 const fromActor = { publicKey, url: 'http://localhost:9002/accounts/peertube' } 37 const fromActor = { publicKey, url: 'http://localhost:9002/accounts/peertube' }
37 38
38 const result = await isJsonLDSignatureVerified(fromActor as any, body) 39 const result = await isJsonLDSignatureVerified(fromActor as any, body)
@@ -41,8 +42,8 @@ describe('Test activity pub helpers', function () {
41 }) 42 })
42 43
43 it('Should fail with an invalid PeerTube signature', async function () { 44 it('Should fail with an invalid PeerTube signature', async function () {
44 const keys = require('./json/peertube/invalid-keys.json') 45 const keys = require(buildAbsoluteFixturePath('./ap-json/peertube/invalid-keys.json'))
45 const body = require('./json/peertube/announce-without-context.json') 46 const body = require(buildAbsoluteFixturePath('./ap-json/peertube/announce-without-context.json'))
46 47
47 const actorSignature = { url: 'http://localhost:9002/accounts/peertube', privateKey: keys.privateKey } 48 const actorSignature = { url: 'http://localhost:9002/accounts/peertube', privateKey: keys.privateKey }
48 const signedBody = await buildSignedActivity(actorSignature as any, body) 49 const signedBody = await buildSignedActivity(actorSignature as any, body)
@@ -54,8 +55,8 @@ describe('Test activity pub helpers', function () {
54 }) 55 })
55 56
56 it('Should succeed with a valid PeerTube signature', async function () { 57 it('Should succeed with a valid PeerTube signature', async function () {
57 const keys = require('./json/peertube/keys.json') 58 const keys = require(buildAbsoluteFixturePath('./ap-json/peertube/keys.json'))
58 const body = require('./json/peertube/announce-without-context.json') 59 const body = require(buildAbsoluteFixturePath('./ap-json/peertube/announce-without-context.json'))
59 60
60 const actorSignature = { url: 'http://localhost:9002/accounts/peertube', privateKey: keys.privateKey } 61 const actorSignature = { url: 'http://localhost:9002/accounts/peertube', privateKey: keys.privateKey }
61 const signedBody = await buildSignedActivity(actorSignature as any, body) 62 const signedBody = await buildSignedActivity(actorSignature as any, body)
@@ -73,12 +74,12 @@ describe('Test activity pub helpers', function () {
73 req.method = 'POST' 74 req.method = 'POST'
74 req.url = '/accounts/ronan/inbox' 75 req.url = '/accounts/ronan/inbox'
75 76
76 const mastodonObject = cloneDeep(require('./json/mastodon/bad-http-signature.json')) 77 const mastodonObject = cloneDeep(require(buildAbsoluteFixturePath('./ap-json/mastodon/bad-http-signature.json')))
77 req.body = mastodonObject.body 78 req.body = mastodonObject.body
78 req.headers = mastodonObject.headers 79 req.headers = mastodonObject.headers
79 80
80 const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10) 81 const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10)
81 const publicKey = require('./json/mastodon/public-key.json').publicKey 82 const publicKey = require(buildAbsoluteFixturePath('./ap-json/mastodon/public-key.json')).publicKey
82 83
83 const actor = { publicKey } 84 const actor = { publicKey }
84 const verified = isHTTPSignatureVerified(parsed, actor as any) 85 const verified = isHTTPSignatureVerified(parsed, actor as any)
@@ -91,12 +92,12 @@ describe('Test activity pub helpers', function () {
91 req.method = 'POST' 92 req.method = 'POST'
92 req.url = '/accounts/ronan/inbox' 93 req.url = '/accounts/ronan/inbox'
93 94
94 const mastodonObject = cloneDeep(require('./json/mastodon/http-signature.json')) 95 const mastodonObject = cloneDeep(require(buildAbsoluteFixturePath('./ap-json/mastodon/http-signature.json')))
95 req.body = mastodonObject.body 96 req.body = mastodonObject.body
96 req.headers = mastodonObject.headers 97 req.headers = mastodonObject.headers
97 98
98 const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10) 99 const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10)
99 const publicKey = require('./json/mastodon/bad-public-key.json').publicKey 100 const publicKey = require(buildAbsoluteFixturePath('./ap-json/mastodon/bad-public-key.json')).publicKey
100 101
101 const actor = { publicKey } 102 const actor = { publicKey }
102 const verified = isHTTPSignatureVerified(parsed, actor as any) 103 const verified = isHTTPSignatureVerified(parsed, actor as any)
@@ -109,7 +110,7 @@ describe('Test activity pub helpers', function () {
109 req.method = 'POST' 110 req.method = 'POST'
110 req.url = '/accounts/ronan/inbox' 111 req.url = '/accounts/ronan/inbox'
111 112
112 const mastodonObject = cloneDeep(require('./json/mastodon/http-signature.json')) 113 const mastodonObject = cloneDeep(require(buildAbsoluteFixturePath('./ap-json/mastodon/http-signature.json')))
113 req.body = mastodonObject.body 114 req.body = mastodonObject.body
114 req.headers = mastodonObject.headers 115 req.headers = mastodonObject.headers
115 116
@@ -128,7 +129,7 @@ describe('Test activity pub helpers', function () {
128 req.method = 'POST' 129 req.method = 'POST'
129 req.url = '/accounts/ronan/inbox' 130 req.url = '/accounts/ronan/inbox'
130 131
131 const mastodonObject = cloneDeep(require('./json/mastodon/http-signature.json')) 132 const mastodonObject = cloneDeep(require(buildAbsoluteFixturePath('./ap-json/mastodon/http-signature.json')))
132 req.body = mastodonObject.body 133 req.body = mastodonObject.body
133 req.headers = mastodonObject.headers 134 req.headers = mastodonObject.headers
134 req.headers = 'Signature ' + mastodonObject.headers 135 req.headers = 'Signature ' + mastodonObject.headers
@@ -148,12 +149,12 @@ describe('Test activity pub helpers', function () {
148 req.method = 'POST' 149 req.method = 'POST'
149 req.url = '/accounts/ronan/inbox' 150 req.url = '/accounts/ronan/inbox'
150 151
151 const mastodonObject = cloneDeep(require('./json/mastodon/http-signature.json')) 152 const mastodonObject = cloneDeep(require(buildAbsoluteFixturePath('./ap-json/mastodon/http-signature.json')))
152 req.body = mastodonObject.body 153 req.body = mastodonObject.body
153 req.headers = mastodonObject.headers 154 req.headers = mastodonObject.headers
154 155
155 const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10) 156 const parsed = parseHTTPSignature(req, 3600 * 1000 * 365 * 10)
156 const publicKey = require('./json/mastodon/public-key.json').publicKey 157 const publicKey = require(buildAbsoluteFixturePath('./ap-json/mastodon/public-key.json')).publicKey
157 158
158 const actor = { publicKey } 159 const actor = { publicKey }
159 const verified = isHTTPSignatureVerified(parsed, actor as any) 160 const verified = isHTTPSignatureVerified(parsed, actor as any)