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:----u+XMTPUIa3/vES1TnwXGuYhQbRt4bf27D6HAdgvKk0ptH8Df7WbysvQIVk9acOQwkHjHwoZxckwclIatjKtIWgLxnm34fCz5urgQzxyoku/hvLLXxtsqqGPzqLtjxBDpayHZt6CtYTfOqakCn3C0SxvVar61BgYavpGUXALKq1WKHuvkeJV7Q/FTPt2NQQnkGqYzvTg0yqudYIpG1GB9xQAzX1rlReiC87n4OM3pwqnham+J+/OWg5CZwBLNLO+S61++AVlwvXN/8e2pv1K+xBB8dBHJF0TSzwsilwffxmWDPGiAuB9viwrZonDsl6PkZNdbZzz3Wp7CdbgPhkhRY2O36+0bd04FYz/pjTeE8s2efStC4gfuhTfksNJD9Mi5qnaqYoRhcevOzWKUTRHh8E/iAoK4xfN+UqCJE/fWinUWzz545UHnV9wm5L3aX/iOwWm0kvAYWDGy/KjPgA0HTrMwJ28dZxOaiQz7qFQuQiFuZY6v/QhEFlNUOfbaYFQH/hn1JHAuVH7eLVHTcJWvtw+Yix3bnlZdLD18ia591NcqXBPaOso8BP4CAMhhgbRRRP0Up6Fg3Avkr/Tg+jCLq3QcG3gOHYGWfhuvXvy6Rvxd4X68f6+7FM0nMGVCkrDWbOU3B2uf3vErlW3L2VgvQcrkd5dkO7jOjwdQOP0LyfA=----ATTACHMENT:----MzI1MjgxODkwOTM0NDM4OCA1NjUxMDU2ODQyMTk5OCA2MDY1NDI5NTU5NTQyNjY1