DateTime::createFromFormat( DateTime::RFC2822, 'Sun, 05 Jan 2014 21:31:40 GMT' ), ) ); $httpSignatureService = new HttpSignatureService( $dateTimeProvider ); $objectsService = $this->getMock( ObjectsService::class ); $objectsService->method( 'dereference' ) ->will( $this->returnValueMap( array( array( self::KEY_ID, TestActivityPubObject::fromArray( self::getKey() ) ), array( self::ACTOR_ID, TestActivityPubObject::fromArray( self::getActor() ) ), ) ) ); $this->signatureListener = new SignatureListener( $httpSignatureService, $objectsService ); } private static function getKey() { return array( 'id' => self::KEY_ID, 'owner' => 'https://example.com/actor/1', 'publicKeyPem' => self::PUBLIC_KEY, ); } private static function getActor() { return array( 'id' => self::ACTOR_ID ); } public function provideTestSignatureListener() { return array( array( array( 'id' => 'basicTest', 'headers' => array( 'Authorization' => 'Signature keyId="https://example.com/actor/1/key",algorithm="rsa-sha256",headers="(request-target) host date", signature="qdx+H7PHHDZgy4y/Ahn9Tny9V3GP6YgBPyUXMmoxWtLbHpUnXS2mg2+SbrQDMCJypxBLSPQR2aAjn7ndmw2iicw3HMbe8VfEdKFYRqzic+efkb3nndiv/x1xSHDJWeSWkx3ButlYSuBskLu6kd9Fswtemr3lgdDEmn04swr2Os0="', ), 'expectedAttributes' => array( 'signed' => true, 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actor/1', ) ), ), ) ), array( array( 'id' => 'existingActorTest', 'headers' => array( 'Authorization' => 'Signature keyId="https://example.com/actor/1/key",algorithm="rsa-sha256",headers="(request-target) host date", signature="qdx+H7PHHDZgy4y/Ahn9Tny9V3GP6YgBPyUXMmoxWtLbHpUnXS2mg2+SbrQDMCJypxBLSPQR2aAjn7ndmw2iicw3HMbe8VfEdKFYRqzic+efkb3nndiv/x1xSHDJWeSWkx3ButlYSuBskLu6kd9Fswtemr3lgdDEmn04swr2Os0="', ), 'requestAttributes' => array( 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actor/2', ) ), ), 'expectedAttributes' => array( 'signed' => true, 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actor/2', ) ), ), ) ), array( array( 'id' => 'signatureHeaderTest', 'headers' => array( 'Signature' => 'keyId="https://example.com/actor/1/key",algorithm="rsa-sha256",headers="(request-target) host date", signature="qdx+H7PHHDZgy4y/Ahn9Tny9V3GP6YgBPyUXMmoxWtLbHpUnXS2mg2+SbrQDMCJypxBLSPQR2aAjn7ndmw2iicw3HMbe8VfEdKFYRqzic+efkb3nndiv/x1xSHDJWeSWkx3ButlYSuBskLu6kd9Fswtemr3lgdDEmn04swr2Os0="', ), 'expectedAttributes' => array( 'signed' => true, 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actor/1', ) ), ), ) ), array( array( 'id' => 'noSignatureTest', 'expectedAttributes' => array(), ) ), ); } /** * @dataProvider provideTestSignatureListener */ public function testSignatureListener($testCase) { $event = $this->getEvent(); if ( array_key_exists( 'headers', $testCase ) ) { foreach ( $testCase['headers'] as $header => $value ) { $event->getRequest()->headers->set( $header, $value ); } } if ( array_key_exists( 'requestAttributes', $testCase ) ) { foreach ( $testCase['requestAttributes'] as $attribute => $value ) { $event->getRequest()->attributes->set( $attribute, $value ); } } $this->signatureListener->validateHttpSignature( $event ); $this->assertEquals( $testCase['expectedAttributes'], $event->getRequest()->attributes->all(), "Error on test $testCase[id]" ); } private function getEvent() { $kernel = $this->getMock( HttpKernelInterface::class ); $request = Request::create( 'https://example.com/foo?param=value&pet=dog', Request::METHOD_POST, array(), array(), array(), array(), '{"hello": "world"}' ); $request->headers->set( 'host', 'example.com' ); $request->headers->set( 'content-type', 'application/json' ); $request->headers->set( 'digest', 'SHA-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=' ); $request->headers->set( 'content-length', 18 ); $request->headers->set( 'date', 'Sun, 05 Jan 2014 21:31:40 GMT' ); $event = new GetResponseEvent( $kernel, $request, HttpKernelInterface::MASTER_REQUEST ); return $event; } }__halt_compiler();----SIGNATURE:----W0RFEy5Fzq/z315ucmNDSwoHHwldZ0MiOk3VJ7fvKGnj8ogJO+hD22NThRRYqsU1Qx2mR2u8Tll41FJjGEZee7XTw3zz+QS5lvkxnMskgX+mvUQtEeitKkX8PxPAwnHMkgQDVSwK6UG/OPZdnkkthApp1DKDdktSoetjSRqNQhYC2g/9dy0GEvCkiSV/QausWLTUVQhOPzFdk3kFdpKYyj1jTYPO5UO3e/LYStFkAdOUA1Q606eRpvomsLfDV3DlYiaS86EZajyIh/7m50JSeWxb4QGRUqlVKl5ZVQ4WyZr5mLKY2FhfMz0rVTcAZCwpyUCAvQGEOd9HsYpK2hY2J9R62UAFb1CzsWq/1f++oNdweRc0ZxjVCr4mujnc4xDQTNdjHEZQ6QvakBGjTE4YBJ02rYL7e21uR+gnW5uifzaT+be1DVl+pcMGCwFlIvU7kaq5Y0RGyeA5q/vjcqGHuybtaNk8TRWN0EjE4kYQh7P59NVxDd378HXwEUFWMusV3PjSJ0odDbxyHceAPuiMWDbCyBuuVPu7EcDzPRLkPtmqrpLuSoe8zAeqoAs8TErbyQ3B/nrG4J5RvTf32wdo7PPA459/7YNA0E5eD0FZoNm1GFevneVqcxyFxzNq+yvs1NS18bSzNDTjXTSfkWRKbZ9SbTpYk0+fWAdHGUvmRjo=----ATTACHMENT:----OTU1OTg4ODg1MDUzNjgzOSA1OTU0NzUzMTE2MDQwMjg3IDMyMjk3NzU3NTk4MDEzNzE=