Test hook
This commit is contained in:
parent
02eeee95ac
commit
9ad0cabd04
|
@ -41,7 +41,7 @@ module.exports = class Activity {
|
|||
];
|
||||
}
|
||||
|
||||
static fromJson(json) {
|
||||
static fromJsonString(json) {
|
||||
const parsed = JSON.parse(json);
|
||||
return new Activity(parsed);
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ module.exports = class Activity {
|
|||
id = id || Activity._makeFullId(webServer, 'accept');
|
||||
|
||||
return new Activity({
|
||||
id,
|
||||
type: 'Accept',
|
||||
actor: localActor,
|
||||
object: followRequest, // previous request Activity
|
||||
|
|
|
@ -124,7 +124,7 @@ module.exports = class Actor {
|
|||
|
||||
https.get(url, { headers }, res => {
|
||||
if (res.statusCode !== 200) {
|
||||
return cb(Errors.Invalid(`Bad HTTP status code: ${req.statusCode}`));
|
||||
return cb(Errors.Invalid(`Bad HTTP status code: ${res.statusCode}`));
|
||||
}
|
||||
|
||||
const contentType = res.headers['content-type'];
|
||||
|
@ -144,7 +144,7 @@ module.exports = class Actor {
|
|||
res.on('end', () => {
|
||||
let actor;
|
||||
try {
|
||||
actor = Actor.fromJson(body);
|
||||
actor = Actor.fromJsonString(body);
|
||||
} catch (e) {
|
||||
return cb(e);
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ module.exports = class Actor {
|
|||
});
|
||||
}
|
||||
|
||||
static fromJson(json) {
|
||||
static fromJsonString(json) {
|
||||
const parsed = JSON.parse(json);
|
||||
return new Actor(parsed);
|
||||
}
|
||||
|
|
|
@ -4,14 +4,11 @@ const {
|
|||
getUserProfileTemplatedBody,
|
||||
DefaultProfileTemplate,
|
||||
accountFromSelfUrl,
|
||||
ActivityStreamsContext,
|
||||
makeUserUrl,
|
||||
} = require('../../../activitypub/util');
|
||||
const Config = require('../../../config').get;
|
||||
const Activity = require('../../../activitypub/activity');
|
||||
const ActivityPubSettings = require('../../../activitypub/settings');
|
||||
const Actor = require('../../../activitypub/actor');
|
||||
const { getOutboxEntries } = require('../../../activitypub/db');
|
||||
|
||||
// deps
|
||||
const _ = require('lodash');
|
||||
|
@ -40,7 +37,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
|||
|
||||
this.webServer.addRoute({
|
||||
method: 'GET',
|
||||
path: /^\/_enig\/ap\/users\/[^\/]+$/,
|
||||
path: /^\/_enig\/ap\/users\/[^/]+$/,
|
||||
handler: this._selfUrlRequestHandler.bind(this),
|
||||
});
|
||||
|
||||
|
@ -120,7 +117,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
|||
req.on('end', () => {
|
||||
let activity;
|
||||
try {
|
||||
activity = Activity.fromJson(Buffer.concat(body).toString());
|
||||
activity = Activity.fromJsonString(Buffer.concat(body).toString());
|
||||
} catch (e) {
|
||||
this.log.error(
|
||||
{ error: e.message, url: req.url, method: req.method },
|
||||
|
@ -180,27 +177,6 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
|||
return this.webServer.resourceNotFound(resp);
|
||||
}
|
||||
|
||||
// // we return a OrderedCollection response if this request
|
||||
// // is not explicitly for a page of the collection
|
||||
// const wantPage = url.searchParams.get('page') === 'true';
|
||||
// if (!wantPage) {
|
||||
// const outboxUrl = makeUserUrl(this.webServer, user, '/ap/users/') + '/outbox';
|
||||
// const body = JSON.stringify({
|
||||
// '@context': ActivityStreamsContext,
|
||||
// id: outboxUrl,
|
||||
// type: 'OrderedCollection',
|
||||
// first: `${outboxUrl}?page=true`,
|
||||
// });
|
||||
|
||||
// const headers = {
|
||||
// 'Content-Type': 'application/activity+json',
|
||||
// 'Content-Length': body.length,
|
||||
// };
|
||||
|
||||
// resp.writeHead(200, headers);
|
||||
// return resp.end(body);
|
||||
// }
|
||||
|
||||
Activity.fromOutboxEntries(user, this.webServer, (err, activity) => {
|
||||
if (err) {
|
||||
// :TODO: LOG ME
|
||||
|
@ -288,7 +264,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
|||
this.log.warn(
|
||||
{
|
||||
actor: activity.actor,
|
||||
keyId,
|
||||
keyId: signature.keyId,
|
||||
signature: req.headers['signature'] || '',
|
||||
},
|
||||
'Invalid signature supplied for Follow request'
|
||||
|
@ -364,6 +340,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
|||
|
||||
_authorizeInteractionHandler(req, resp) {
|
||||
console.log(req);
|
||||
console.log(resp);
|
||||
}
|
||||
|
||||
_selfAsActorHandler(user, req, resp) {
|
||||
|
|
|
@ -4,7 +4,6 @@ const Message = require('./message');
|
|||
const { getJson } = require('./http_util');
|
||||
|
||||
// deps
|
||||
const https = require('https');
|
||||
|
||||
exports.queryWebFinger = queryWebFinger;
|
||||
|
||||
|
@ -15,12 +14,12 @@ function queryWebFinger(account, cb) {
|
|||
addrInfo.flavor !== Message.AddressFlavor.ActivityPub &&
|
||||
addrInfo.flavor !== Message.AddressFlavor.Email
|
||||
) {
|
||||
return cb(Errors.Invalid(`Cannot WebFinger "${accountName}"; Missing domain`));
|
||||
return cb(Errors.Invalid(`Cannot WebFinger "${account.remote}"; Missing domain`));
|
||||
}
|
||||
|
||||
const domain = addrInfo.remote.slice(addrInfo.remote.lastIndexOf('@') + 1);
|
||||
if (!domain) {
|
||||
return cb(Errors.Invalid(`Cannot WebFinger "${accountName}"; Missing domain`));
|
||||
return cb(Errors.Invalid(`Cannot WebFinger "${account.remote}"; Missing domain`));
|
||||
}
|
||||
|
||||
const resource = encodeURIComponent(`acct:${account.slice(1)}`); // we need drop the initial '@' prefix
|
||||
|
|
Loading…
Reference in New Issue