Fix POST to Accept Follow Request

This commit is contained in:
Bryan Ashby 2023-01-19 22:31:14 -07:00
parent 51308a5ad3
commit 930308e07f
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
5 changed files with 37 additions and 47 deletions

View File

@ -1,9 +1,6 @@
const { const { messageBodyToHtml, selfUrl, makeUserUrl } = require('./util');
ActivityStreamsContext, const { ActivityStreamsContext, WellKnownActivityTypes } = require('./const');
messageBodyToHtml, const ActivityPubObject = require('./object');
selfUrl,
makeUserUrl,
} = require('./util');
const User = require('../user'); const User = require('../user');
const Actor = require('./actor'); const Actor = require('./actor');
const { Errors } = require('../enig_error'); const { Errors } = require('../enig_error');
@ -14,31 +11,18 @@ const { getOutboxEntries } = require('./db');
const { WellKnownLocations } = require('../servers/content/web'); const { WellKnownLocations } = require('../servers/content/web');
// deps // deps
const { isString, isObject } = require('lodash'); //const { isString, isObject } = require('lodash');
const { v4: UUIDv4 } = require('uuid'); const { v4: UUIDv4 } = require('uuid');
const async = require('async'); const async = require('async');
const _ = require('lodash'); const _ = require('lodash');
module.exports = class Activity { module.exports = class Activity extends ActivityPubObject {
constructor(obj) { constructor(obj) {
this['@context'] = ActivityStreamsContext; super(obj);
Object.assign(this, obj);
} }
static get ActivityTypes() { static get ActivityTypes() {
return [ return WellKnownActivityTypes;
'Create',
'Update',
'Delete',
'Follow',
'Accept',
'Reject',
'Add',
'Remove',
'Like',
'Announce',
'Undo',
];
} }
static fromJsonString(json) { static fromJsonString(json) {
@ -46,21 +30,21 @@ module.exports = class Activity {
return new Activity(parsed); return new Activity(parsed);
} }
isValid() { // isValid() {
if ( // if (
this['@context'] !== ActivityStreamsContext || // this['@context'] !== ActivityStreamsContext ||
!isString(this.id) || // !isString(this.id) ||
!isString(this.actor) || // !isString(this.actor) ||
(!isString(this.object) && !isObject(this.object)) || // (!isString(this.object) && !isObject(this.object)) ||
!Activity.ActivityTypes.includes(this.type) // !Activity.ActivityTypes.includes(this.type)
) { // ) {
return false; // return false;
} // }
// :TODO: Additional validation // // :TODO: Additional validation
return true; // return true;
} // }
// https://www.w3.org/TR/activitypub/#accept-activity-inbox // https://www.w3.org/TR/activitypub/#accept-activity-inbox
static makeAccept(webServer, localActor, followRequest, id = null) { static makeAccept(webServer, localActor, followRequest, id = null) {

View File

@ -9,8 +9,8 @@ const {
makeUserUrl, makeUserUrl,
selfUrl, selfUrl,
isValidLink, isValidLink,
ActivityStreamsContext,
} = require('../activitypub/util'); } = require('../activitypub/util');
const { ActivityStreamsContext } = require('./const');
const Log = require('../logger').log; const Log = require('../logger').log;
const { queryWebFinger } = require('../webfinger'); const { queryWebFinger } = require('../webfinger');
const EnigAssert = require('../enigma_assert'); const EnigAssert = require('../enigma_assert');

View File

@ -1,4 +1,5 @@
const { ActivityStreamsContext, makeUserUrl } = require('./util'); const { makeUserUrl } = require('./util');
const { ActivityStreamsContext } = require('./const');
const { FollowerEntryStatus, getFollowerEntries } = require('./db'); const { FollowerEntryStatus, getFollowerEntries } = require('./db');
module.exports = class Collection { module.exports = class Collection {

View File

@ -49,10 +49,9 @@ function _makeRequest(url, options, cb) {
options.headers['Content-Length'] = options.body.length; options.headers['Content-Length'] = options.body.length;
if (options?.sign?.headers?.includes('digest')) { if (options?.sign?.headers?.includes('digest')) {
options.headers['Digest'] = `SHA-256=${crypto options.headers['Digest'] =
.createHash('sha256') 'SHA-256=' +
.update(options.body) crypto.createHash('sha256').update(options.body).digest('base64');
.digest('base64')}`;
} }
} }
@ -95,5 +94,8 @@ function _makeRequest(url, options, cb) {
return cb(Errors.Timeout('Timeout making HTTP request')); return cb(Errors.Timeout('Timeout making HTTP request'));
}); });
if (options.body) {
req.write(options.body);
}
req.end(); req.end();
} }

View File

@ -53,10 +53,13 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
this.webServer.addRoute({ this.webServer.addRoute({
method: 'GET', method: 'GET',
path: /^\/_enig\/ap\/users\/.+\/outbox$/, path: /^\/_enig\/ap\/users\/.+\/outbox$/,
handler: this._enforceSigningPolicy.bind( handler: (req, resp) => {
this, return this._enforceSigningPolicy(
req,
resp,
this._outboxGetHandler.bind(this) this._outboxGetHandler.bind(this)
), );
},
}); });
this.webServer.addRoute({ this.webServer.addRoute({
@ -259,7 +262,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
} }
const page = url.searchParams.get('page'); const page = url.searchParams.get('page');
Collection.followers(user, page, this.webServe, (err, collection) => { Collection.followers(user, page, this.webServer, (err, collection) => {
if (err) { if (err) {
// :TODO: LOG ME // :TODO: LOG ME
return this.webServer.internalServerError(resp); return this.webServer.internalServerError(resp);