aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/activitypub.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-21 13:43:29 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:52 +0100
commit0f91ae62df8a37194fea84ce1efa9e733d9c1fd8 (patch)
tree1cb0fccadebb629d02632dc8e21fae7ba521c464 /server/middlewares/activitypub.ts
parent81de19482b89342c3dbc098a9f512ef7f1056e45 (diff)
downloadPeerTube-0f91ae62df8a37194fea84ce1efa9e733d9c1fd8.tar.gz
PeerTube-0f91ae62df8a37194fea84ce1efa9e733d9c1fd8.tar.zst
PeerTube-0f91ae62df8a37194fea84ce1efa9e733d9c1fd8.zip
Add follow tests
Diffstat (limited to 'server/middlewares/activitypub.ts')
-rw-r--r--server/middlewares/activitypub.ts11
1 files changed, 5 insertions, 6 deletions
diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts
index 29bec0c97..061b2dddc 100644
--- a/server/middlewares/activitypub.ts
+++ b/server/middlewares/activitypub.ts
@@ -4,7 +4,7 @@ import { ActivityPubSignature } from '../../shared'
4import { isSignatureVerified, logger } from '../helpers' 4import { isSignatureVerified, logger } from '../helpers'
5import { database as db } from '../initializers' 5import { database as db } from '../initializers'
6import { ACTIVITY_PUB } from '../initializers/constants' 6import { ACTIVITY_PUB } from '../initializers/constants'
7import { fetchRemoteAccountAndCreateServer } from '../lib/activitypub/account' 7import { fetchRemoteAccount, saveAccountAndServerIfNotExist } from '../lib/activitypub/account'
8 8
9async function checkSignature (req: Request, res: Response, next: NextFunction) { 9async function checkSignature (req: Request, res: Response, next: NextFunction) {
10 const signatureObject: ActivityPubSignature = req.body.signature 10 const signatureObject: ActivityPubSignature = req.body.signature
@@ -15,15 +15,14 @@ async function checkSignature (req: Request, res: Response, next: NextFunction)
15 15
16 // We don't have this account in our database, fetch it on remote 16 // We don't have this account in our database, fetch it on remote
17 if (!account) { 17 if (!account) {
18 const accountResult = await fetchRemoteAccountAndCreateServer(signatureObject.creator) 18 account = await fetchRemoteAccount(signatureObject.creator)
19 19
20 if (!accountResult) { 20 if (!account) {
21 return res.sendStatus(403) 21 return res.sendStatus(403)
22 } 22 }
23 23
24 // Save our new account in database 24 // Save our new account and its server in database
25 account = accountResult.account 25 await saveAccountAndServerIfNotExist(account)
26 await account.save()
27 } 26 }
28 27
29 const verified = await isSignatureVerified(account, req.body) 28 const verified = await isSignatureVerified(account, req.body)