aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/requests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils/requests')
-rw-r--r--server/tests/utils/requests/activitypub.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/server/tests/utils/requests/activitypub.ts b/server/tests/utils/requests/activitypub.ts
new file mode 100644
index 000000000..e3e08ce67
--- /dev/null
+++ b/server/tests/utils/requests/activitypub.ts
@@ -0,0 +1,43 @@
1import { doRequest } from '../../../helpers/requests'
2import { HTTP_SIGNATURE } from '../../../initializers'
3import { buildGlobalHeaders } from '../../../lib/job-queue/handlers/utils/activitypub-http-utils'
4import { activityPubContextify } from '../../../helpers/activitypub'
5
6function makeAPRequest (url: string, body: any, httpSignature: any, headers: any) {
7 const options = {
8 method: 'POST',
9 uri: url,
10 json: body,
11 httpSignature,
12 headers
13 }
14
15 return doRequest(options)
16}
17
18async function makeFollowRequest (to: { url: string }, by: { url: string, privateKey }) {
19 const follow = {
20 type: 'Follow',
21 id: by.url + '/toto',
22 actor: by.url,
23 object: to.url
24 }
25
26 const body = activityPubContextify(follow)
27
28 const httpSignature = {
29 algorithm: HTTP_SIGNATURE.ALGORITHM,
30 authorizationHeaderName: HTTP_SIGNATURE.HEADER_NAME,
31 keyId: by.url,
32 key: by.privateKey,
33 headers: HTTP_SIGNATURE.HEADERS_TO_SIGN
34 }
35 const headers = buildGlobalHeaders(body)
36
37 return makeAPRequest(to.url, body, httpSignature, headers)
38}
39
40export {
41 makeAPRequest,
42 makeFollowRequest
43}