diff --git a/src/Activities/ValidationHandler.php b/src/Activities/ValidationHandler.php index 2042ebb..f5d57fa 100644 --- a/src/Activities/ValidationHandler.php +++ b/src/Activities/ValidationHandler.php @@ -28,25 +28,31 @@ class ValidationHandler implements EventSubscriberInterface public function verifyInboxActivity( InboxActivityEvent $event ) { $activity = $event->getActivity(); - $this->requireFields( $activity, array( 'type', 'id', 'actor' ) ); - if ( in_array( $activity['type'], self::OBJECT_REQUIRED_TYPES ) ) { - $this->requireFields( $activity, array( 'object' ) ); + $requiredFields = array( 'type', 'id', 'actor' ); + if ( array_key_exists( 'type', $activity ) && + in_array( $activity['type'], self::OBJECT_REQUIRED_TYPES ) ) { + $requiredFields[] = 'object'; } - if ( in_array( $activity['type'], self::TARGET_REQUIRED_TYPES ) ) { - $this->requireFields( $activity, array( 'target' ) ); + if ( array_key_exists( 'type', $activity ) && + in_array( $activity['type'], self::TARGET_REQUIRED_TYPES ) ) { + $requiredFields[] = 'target'; } + $this->requireFields( $activity, $requiredFields ); } public function verifyOutboxActivity( OutboxActivityEvent $event ) { $activity = $event->getActivity(); - $this->requireFields( $activity, array( 'type' ) ); - if ( in_array( $activity['type'], self::OBJECT_REQUIRED_TYPES ) ) { - $this->requireFields( $activity, array( 'object' ) ); + $requiredFields = array( 'type', 'actor' ); + if ( array_key_exists( 'type', $activity ) && + in_array( $activity['type'], self::OBJECT_REQUIRED_TYPES ) ) { + $requiredFields[] = 'object'; } - if ( in_array( $activity['type'], self::TARGET_REQUIRED_TYPES ) ) { - $this->requireFields( $activity, array( 'target' ) ); + if ( array_key_exists( 'type', $activity ) && + in_array( $activity['type'], self::TARGET_REQUIRED_TYPES ) ) { + $requiredFields[] = 'target'; } + $this->requireFields( $activity, $requiredFields ); } private function requireFields( array $activity, array $fields ) diff --git a/test/Activities/ValidationHandlerTest.php b/test/Activities/ValidationHandlerTest.php index c5265a5..a494c80 100644 --- a/test/Activities/ValidationHandlerTest.php +++ b/test/Activities/ValidationHandlerTest.php @@ -52,7 +52,7 @@ class ValidationHandlerTest extends TestCase Request::create( 'https://example.com' ) ), 'expectedException' => BadRequestHttpException::class, - 'expectedExceptionMessage' => 'Missing activity fields: type', + 'expectedExceptionMessage' => 'Missing activity fields: type,actor', ), array( 'id' => 'inboxPassesValidActivity', @@ -79,6 +79,7 @@ class ValidationHandlerTest extends TestCase 'event' => new OutboxActivityEvent( array( 'type' => 'Create', + 'actor' => 'https://example.com/actor/1', 'object' => array( 'type' => 'Note', ), @@ -96,6 +97,7 @@ class ValidationHandlerTest extends TestCase 'event' => new OutboxActivityEvent( array( 'type' => 'Create', + 'actor' => 'https://example.com/actor/1', ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actor/1', @@ -144,9 +146,10 @@ class ValidationHandlerTest extends TestCase 'event' => new OutboxActivityEvent( array( 'type' => 'Remove', + 'actor' => 'https://example.com/actor/1', ), TestActivityPubObject::fromArray( array( - 'id' => 'https://notexample.com/actor/1', + 'id' => 'https://example.com/actor/1', 'type' => 'Person', ) ), Request::create( 'https://example.com' )