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:----b1uSBwzl6xUfraXs7oonMlFCm9OAw5PMghltA+IgdHfNyckHNj2c9SR6MswP4r59e+yPxmDzaXmKrKWy31HWJ3DC9pewWludiVXqm4Qr72E4FF8mugVpak3sRJsX4YSOXLIyMydN8+h5ftJBZRkFhcGgUW5VWSNb3tkVYPunc0DsxQlMO+nZGrfXF3vNsTGm0pF9ipUaNfV1izaHYt9m9FDrq+Rj/56I58Zm13kmeuEVlnZ136PsUyKxVj1sUIceLx72tZUCccMkvruxBKtAWkZLGl5SgNQNY8Lm9Ed1chlDTsES3B/A9WE6sii1k/zw/qUqNab4lmAGeFycX40noaBXnL6DuA5j9ih42YyWFlD/WLCBJUnKSr4g47fNbhsl4at8TZP5s2TlyhrCk1S6xv0WDJ/aS5hLFp+4y2xceGcsV3I+2dwaT9e594pJEKf7SmGo3PXdwpmWTjiCKK+jsdR+8rWPJ5PdN8In8pZTqLeqESfzzOk+v/Xq/nmvi8g4etFs4H5mokD72MXfgHE61wf3RnnGOEayj+uALvX4WA1od15rfzrnjZatpH3LtagzR3PzbIYO+kpLMBHMPf1oEgrmIsMfk/nw+lb+3G+JIo1LInUtHceqQgd1TGCGKJQ9bytqGgqLCzXN/HbCYN/jCI4TaI4byEHZeQAxylIeTbo=----ATTACHMENT:----NjE3ODkwODYzNTMzNDgxNSAyMzE2ODQ1MzUyOTMwMTE5IDUxNjY0NTkwODk3MDg2NDM=