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);
|
const parsed = JSON.parse(json);
|
||||||
return new Activity(parsed);
|
return new Activity(parsed);
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,7 @@ module.exports = class Activity {
|
||||||
id = id || Activity._makeFullId(webServer, 'accept');
|
id = id || Activity._makeFullId(webServer, 'accept');
|
||||||
|
|
||||||
return new Activity({
|
return new Activity({
|
||||||
|
id,
|
||||||
type: 'Accept',
|
type: 'Accept',
|
||||||
actor: localActor,
|
actor: localActor,
|
||||||
object: followRequest, // previous request Activity
|
object: followRequest, // previous request Activity
|
||||||
|
|
|
@ -124,7 +124,7 @@ module.exports = class Actor {
|
||||||
|
|
||||||
https.get(url, { headers }, res => {
|
https.get(url, { headers }, res => {
|
||||||
if (res.statusCode !== 200) {
|
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'];
|
const contentType = res.headers['content-type'];
|
||||||
|
@ -144,7 +144,7 @@ module.exports = class Actor {
|
||||||
res.on('end', () => {
|
res.on('end', () => {
|
||||||
let actor;
|
let actor;
|
||||||
try {
|
try {
|
||||||
actor = Actor.fromJson(body);
|
actor = Actor.fromJsonString(body);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return cb(e);
|
return cb(e);
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ module.exports = class Actor {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(json) {
|
static fromJsonString(json) {
|
||||||
const parsed = JSON.parse(json);
|
const parsed = JSON.parse(json);
|
||||||
return new Actor(parsed);
|
return new Actor(parsed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,11 @@ const {
|
||||||
getUserProfileTemplatedBody,
|
getUserProfileTemplatedBody,
|
||||||
DefaultProfileTemplate,
|
DefaultProfileTemplate,
|
||||||
accountFromSelfUrl,
|
accountFromSelfUrl,
|
||||||
ActivityStreamsContext,
|
|
||||||
makeUserUrl,
|
|
||||||
} = require('../../../activitypub/util');
|
} = require('../../../activitypub/util');
|
||||||
const Config = require('../../../config').get;
|
const Config = require('../../../config').get;
|
||||||
const Activity = require('../../../activitypub/activity');
|
const Activity = require('../../../activitypub/activity');
|
||||||
const ActivityPubSettings = require('../../../activitypub/settings');
|
const ActivityPubSettings = require('../../../activitypub/settings');
|
||||||
const Actor = require('../../../activitypub/actor');
|
const Actor = require('../../../activitypub/actor');
|
||||||
const { getOutboxEntries } = require('../../../activitypub/db');
|
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
@ -40,7 +37,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
||||||
|
|
||||||
this.webServer.addRoute({
|
this.webServer.addRoute({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: /^\/_enig\/ap\/users\/[^\/]+$/,
|
path: /^\/_enig\/ap\/users\/[^/]+$/,
|
||||||
handler: this._selfUrlRequestHandler.bind(this),
|
handler: this._selfUrlRequestHandler.bind(this),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -120,7 +117,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
||||||
req.on('end', () => {
|
req.on('end', () => {
|
||||||
let activity;
|
let activity;
|
||||||
try {
|
try {
|
||||||
activity = Activity.fromJson(Buffer.concat(body).toString());
|
activity = Activity.fromJsonString(Buffer.concat(body).toString());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.log.error(
|
this.log.error(
|
||||||
{ error: e.message, url: req.url, method: req.method },
|
{ error: e.message, url: req.url, method: req.method },
|
||||||
|
@ -180,27 +177,6 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
||||||
return this.webServer.resourceNotFound(resp);
|
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) => {
|
Activity.fromOutboxEntries(user, this.webServer, (err, activity) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
// :TODO: LOG ME
|
// :TODO: LOG ME
|
||||||
|
@ -288,7 +264,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
||||||
this.log.warn(
|
this.log.warn(
|
||||||
{
|
{
|
||||||
actor: activity.actor,
|
actor: activity.actor,
|
||||||
keyId,
|
keyId: signature.keyId,
|
||||||
signature: req.headers['signature'] || '',
|
signature: req.headers['signature'] || '',
|
||||||
},
|
},
|
||||||
'Invalid signature supplied for Follow request'
|
'Invalid signature supplied for Follow request'
|
||||||
|
@ -364,6 +340,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
|
||||||
|
|
||||||
_authorizeInteractionHandler(req, resp) {
|
_authorizeInteractionHandler(req, resp) {
|
||||||
console.log(req);
|
console.log(req);
|
||||||
|
console.log(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
_selfAsActorHandler(user, req, resp) {
|
_selfAsActorHandler(user, req, resp) {
|
||||||
|
|
|
@ -4,7 +4,6 @@ const Message = require('./message');
|
||||||
const { getJson } = require('./http_util');
|
const { getJson } = require('./http_util');
|
||||||
|
|
||||||
// deps
|
// deps
|
||||||
const https = require('https');
|
|
||||||
|
|
||||||
exports.queryWebFinger = queryWebFinger;
|
exports.queryWebFinger = queryWebFinger;
|
||||||
|
|
||||||
|
@ -15,12 +14,12 @@ function queryWebFinger(account, cb) {
|
||||||
addrInfo.flavor !== Message.AddressFlavor.ActivityPub &&
|
addrInfo.flavor !== Message.AddressFlavor.ActivityPub &&
|
||||||
addrInfo.flavor !== Message.AddressFlavor.Email
|
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);
|
const domain = addrInfo.remote.slice(addrInfo.remote.lastIndexOf('@') + 1);
|
||||||
if (!domain) {
|
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
|
const resource = encodeURIComponent(`acct:${account.slice(1)}`); // we need drop the initial '@' prefix
|
||||||
|
|
Loading…
Reference in New Issue