[ActivityPub] Include recent actor type attribute in its creation

Improve debug logs
This commit is contained in:
Diogo Peralta Cordeiro 2021-12-19 19:45:38 +00:00
parent ed67da89dc
commit 1832397363
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
2 changed files with 16 additions and 11 deletions

View File

@ -63,7 +63,10 @@ class Inbox extends Controller
*/
public function handle(?int $gsactor_id = null): TypeResponse
{
$error = fn(string $m): TypeResponse => new TypeResponse(json_encode(['error' => $m]));
$error = function (string $m, ?Exception $e = null): TypeResponse {
Log::error('ActivityPub Error Answer: ' . ($json = json_encode(['error' => $m, 'exception' => var_export($e, true)])));
return new TypeResponse($json, 400);
};
$path = Router::url('activitypub_inbox', type: Router::ABSOLUTE_PATH);
if (!is_null($gsactor_id)) {
@ -94,7 +97,7 @@ class Inbox extends Controller
}
unset($resource_parts);
} catch (Exception $e) {
return $error('Invalid actor: ' . $e->getMessage());
return $error('Invalid actor.', $e);
}
$activitypub_rsa = ActivitypubRsa::getByActor($actor);
@ -108,7 +111,7 @@ class Inbox extends Controller
if (!isset($headers['signature'])) {
Log::debug('ActivityPub Inbox: HTTP Signature: Missing Signature header.');
return $error('Missing Signature header.', 400);
return $error('Missing Signature header.');
// TODO: support other methods beyond HTTP Signatures
}
@ -117,7 +120,7 @@ class Inbox extends Controller
Log::debug('ActivityPub Inbox: HTTP Signature Data: ' . print_r($signatureData, true));
if (isset($signatureData['error'])) {
Log::debug('ActivityPub Inbox: HTTP Signature: ' . json_encode($signatureData, JSON_PRETTY_PRINT));
return $error(json_encode($signatureData, JSON_PRETTY_PRINT), 400);
return $error(json_encode($signatureData, JSON_PRETTY_PRINT));
}
[$verified, /*$headers*/] = HTTPSignature::verify($actor_public_key, $signatureData, $headers, $path, $body);
@ -127,15 +130,15 @@ class Inbox extends Controller
try {
$res = Explorer::get_remote_user_activity($ap_actor->getUri());
if (is_null($res)) {
return $error('Invalid remote actor.');
return $error('Invalid remote actor (null response).');
}
} catch (Exception) {
return $error('Invalid remote actor.');
} catch (Exception $e) {
return $error('Invalid remote actor.', $e);
}
try {
ActivitypubActor::update_profile($ap_actor, $actor, $activitypub_rsa, $res);
} catch (Exception) {
return $error('Failed to updated remote actor information.');
} catch (Exception $e) {
return $error('Failed to updated remote actor information.', $e);
}
[$verified, /*$headers*/] = HTTPSignature::verify($actor_public_key, $signatureData, $headers, $path, $body);

View File

@ -38,7 +38,7 @@ use App\Core\GSFile;
use App\Core\HTTPClient;
use App\Core\Log;
use App\Core\Router\Router;
use App\Core\Security;
use App\Core\UserRoles;
use App\Entity\Actor as GSActor;
use App\Util\Exception\ServerException;
use App\Util\Formatting;
@ -79,8 +79,10 @@ class Actor extends Model
'nickname' => $person->get('preferredUsername'),
'fullname' => !empty($person->get('name')) ? $person->get('name') : null,
'created' => new DateTime($person->get('published') ?? 'now'),
'bio' => $person->has('summary') ? mb_substr(Security::sanitize($person->get('summary')), 0, 1000) : null,
'bio' => $person->get('summary'),
'is_local' => false,
'type' => GSActor::PERSON,
'roles' => UserRoles::USER,
'modified' => new DateTime(),
];