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:----opQi9Jhocofl26CjtRfgcNH4RpZJq9FfjGAgy0Yik3TdRNSgL0qKndv4jG7nrjQKzadO2PPParDgyK6hOkiQ+AUIAL+mBfSpx9kKiz/bJKxbYOBaUBgv5ND9wc9g6Cl5VFFmrp8xSz39EQ9h2ECDy5XjTOf0VO+Cnk/oPdAYU+k1SrVkqw3l9EbkpOsITTFqZLRPO2h0ieI9nFROOL+RaCHR/7w7/Tcg0kKaiIvCVbKYa9DKVauxW2Lg6sQ01fywRpNmWmiuFzB2o9u164l120Fj/3SJDrP5l4xBrujenw9wBeRS7WE8F8a7suXRbkaaDeN9we6u2094uSrUbGvxF2o7/NoVm3FyEE3SHkfW9gN6WLxRmzpII1LI3vm/WxGqx6ZnVr345n1Yg6CsDjI/NUqzsBm/Y8jFJPPpxjrQBfnVINc9JWdBs9ViDYINeZgLKmZLGiwLEVOSMeWMZDUtw1TaEoYGW1dI8JCQmGVYKgyMYBVh6eB9TzOK5Xg2oUaUissrkRRG7X/rVycJFKLwRvoUZ+NGQ65qXyIrSTi6J15wBOxmJfLgssQWpuun1VDoKWen5LE83Ruftxo39i0GOftRimIQW9K5Y4xCs8R/lK0/tUKsbtRWeC6plYU/14UA4PqyKkcMMWkV7SRyWce9QeCygn03Ub7/fVV7dbvto1k=----ATTACHMENT:----MTQ2MDcxNjM1OTA4Mzg5IDk5OTA0NDg1NTcyOTk3NjkgODIwNTc2MDIxNjE5NDM2Ng==