1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-06 03:50:26 +02:00

Add follow tests

This commit is contained in:
Chocobozzz 2017-11-21 13:43:29 +01:00
parent 81de19482b
commit 0f91ae62df
No known key found for this signature in database
GPG key ID: 583A612D890159BE
23 changed files with 736 additions and 522 deletions

View file

@ -4,7 +4,7 @@ import { ActivityPubSignature } from '../../shared'
import { isSignatureVerified, logger } from '../helpers'
import { database as db } from '../initializers'
import { ACTIVITY_PUB } from '../initializers/constants'
import { fetchRemoteAccountAndCreateServer } from '../lib/activitypub/account'
import { fetchRemoteAccount, saveAccountAndServerIfNotExist } from '../lib/activitypub/account'
async function checkSignature (req: Request, res: Response, next: NextFunction) {
const signatureObject: ActivityPubSignature = req.body.signature
@ -15,15 +15,14 @@ async function checkSignature (req: Request, res: Response, next: NextFunction)
// We don't have this account in our database, fetch it on remote
if (!account) {
const accountResult = await fetchRemoteAccountAndCreateServer(signatureObject.creator)
account = await fetchRemoteAccount(signatureObject.creator)
if (!accountResult) {
if (!account) {
return res.sendStatus(403)
}
// Save our new account in database
account = accountResult.account
await account.save()
// Save our new account and its server in database
await saveAccountAndServerIfNotExist(account)
}
const verified = await isSignatureVerified(account, req.body)