From 5d986bc7ab1a49a9118605ba0a84fca2eeab01d5 Mon Sep 17 00:00:00 2001 From: Liam Dennehy Date: Wed, 14 Aug 2019 14:36:17 +0200 Subject: [PATCH 1/8] SignatureParametersParser: Better function name --- src/SignatureParametersParser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SignatureParametersParser.php b/src/SignatureParametersParser.php index 13280d2..c43d3bb 100644 --- a/src/SignatureParametersParser.php +++ b/src/SignatureParametersParser.php @@ -91,7 +91,7 @@ private function pair($segment) */ private function validate($result) { - $this->validateAllKeysArePresent($result); + $this->validateRequiredKeysArePresent($result); } /** @@ -99,7 +99,7 @@ private function validate($result) * * @throws SignatureParseException */ - private function validateAllKeysArePresent($result) + private function validateRequiredKeysArePresent($result) { // Regexp in pair() ensures no unwanted keys exist. // Ensure that all mandatory keys exist. From 6c2305c18511e5b4db32853e33957fc602ecc57a Mon Sep 17 00:00:00 2001 From: Liam Dennehy Date: Wed, 14 Aug 2019 14:36:31 +0200 Subject: [PATCH 2/8] Add tests for verifier context mode - Permit input for minimum headers present - Permit header parameters to be queried - Permit keys to be added to KeyStore (e.g. keyId lookup and provide from external source --- tests/VerifierContextTest.php | 338 ++++++++++++++++++++++++++++++++++ 1 file changed, 338 insertions(+) create mode 100644 tests/VerifierContextTest.php diff --git a/tests/VerifierContextTest.php b/tests/VerifierContextTest.php new file mode 100644 index 0000000..bf471f4 --- /dev/null +++ b/tests/VerifierContextTest.php @@ -0,0 +1,338 @@ +setUpVerifier(); + $this->setUpSignedMessage(); + $this->setUpAuthorizedMessage(); + $this->setUpSignedAndAuthorizedMessage(); + } + + private function setUpVerifier() + { + // $keyStore = new KeyStore(['pda' => 'secret']); + $this->verifierCompleteContext = new Context([ + 'keys' => ['pda' => 'secret'], + 'headers' => ['(request-target)', 'date'], + ]); + $this->verifierEmptyContext = new Context([ + ]); + } + + private function setUpSignedMessage() + { + $signatureLine = sprintf( + 'keyId="%s",algorithm="%s",headers="%s",signature="%s"', + 'pda', + 'hmac-sha256', + '(request-target) date', + 'cS2VvndvReuTLy52Ggi4j6UaDqGm9hMb4z0xJZ6adqU=' + ); + + $this->signedMessage = new Request('GET', '/path?query=123', [ + 'Date' => self::DATE, + 'Signature' => $signatureLine, + 'Authorization' => 'Bearer abc123', + ]); + + $signatureLineNoHeaders = sprintf( + 'keyId="%s",algorithm="%s",signature="%s"', + 'pda', + 'hmac-sha256', + 'cS2VvndvReuTLy52Ggi4j6UaDqGm9hMb4z0xJZ6adqU=' + ); + + $this->signedMessageNoHeaders = new Request('GET', '/path?query=123', [ + 'Date' => self::DATE, + 'Signature' => $signatureLineNoHeaders, + 'Authorization' => 'Bearer abc123', + ]); + } + + private function setUpAuthorizedMessage() + { + $authorizationHeader = sprintf( + 'Signature keyId="%s",algorithm="%s",headers="%s",signature="%s"', + 'pda', + 'hmac-sha256', + '(request-target) date', + 'cS2VvndvReuTLy52Ggi4j6UaDqGm9hMb4z0xJZ6adqU=' + ); + + $this->authorizedMessage = new Request('GET', '/path?query=123', [ + 'Date' => self::DATE, + 'Authorization' => $authorizationHeader, + 'Signature' => 'My Lawyer signed this', + ]); + } + + private function setUpSignedAndAuthorizedMessage() + { + $authorizationHeader = sprintf( + 'Signature keyId="%s",algorithm="%s",headers="%s",signature="%s"', + 'pda', + 'hmac-sha256', + '(request-target) date', + 'cS2VvndvReuTLy52Ggi4j6UaDqGm9hMb4z0xJZ6adqU=' + ); + $signatureHeader = sprintf( + 'keyId="%s",algorithm="%s",headers="%s",signature="%s"', + 'pda', + 'hmac-sha256', + '(request-target) date', + 'cS2VvndvReuTLy52Ggi4j6UaDqGm9hMb4z0xJZ6adqU=' + ); + + $this->signedAndAuthorizedMessage = new Request('GET', '/path?query=123', [ + 'Date' => self::DATE, + 'Authorization' => $authorizationHeader, + 'Signature' => $signatureHeader, + ]); + } + + public function testVerifySignedMessage() + { + $verifier = $this->verifierCompleteContext->verifier(); + $this->assertTrue($verifier->isSigned($this->signedMessage)); + $this->assertEquals( + "Signed with SigningString 'KHJlcXVlc3QtdGFyZ2V0KTogZ2V0IC9wYXRoP3F1ZXJ5PTEyMwpkYXRlOiBGcmksIDAxIEF1ZyAyMDE0IDEzOjQ0OjMyIC0wNzAw'", + $verifier->getStatus()[0] + ); + $verifier->isSigned($this->signedMessage); + $this->assertEquals( + 1, + sizeof($verifier->getStatus()) + ); + } + + public function testVerifyAuthorizedMessage() + { + $verifier = $this->verifierCompleteContext->verifier(); + $this->assertTrue($verifier->isAuthorized($this->authorizedMessage)); + $this->assertEquals( + "Authorized with SigningString 'KHJlcXVlc3QtdGFyZ2V0KTogZ2V0IC9wYXRoP3F1ZXJ5PTEyMwpkYXRlOiBGcmksIDAxIEF1ZyAyMDE0IDEzOjQ0OjMyIC0wNzAw'", + $verifier->getStatus()[0] + ); + $verifier->isAuthorized($this->authorizedMessage); + $this->assertEquals( + 1, + sizeof($verifier->getStatus()) + ); + } + + public function testProvidedParameters() + { + $verifier = $this->verifierCompleteContext->verifier(); + $this->assertEquals( + ['(request-target)', 'date'], + $verifier->getSignatureHeaders($this->signedMessage, 'headers') + ); + $verifier = $this->verifierCompleteContext->verifier(); + $this->assertEquals( + ['date'], + $verifier->getSignatureHeaders($this->signedMessageNoHeaders, 'headers') + ); + } + + // TODO: Add keys to a verifier based on provided keyId + // public function testMinimumHeaders() + // { + // $verifier = $this->verifierEmptyContext->verifier(); + // $verifier = $verifier->withKeys(['keyId' => 'keyvalue']); + // $this->assertTrue($verifier->isSigned($this->signedMessage)); + // + // } + + // // TODO: Decide on compatibility for isValid() for 99designs/http-signatures-php compat + // // public function testLegacyIsValid() + // // { + // // error_reporting(error_reporting() & ~E_USER_DEPRECATED); + // // $this->assertTrue($this->verifier->isValid($this->signedAndAuthorizedMessage)); + // // error_reporting(error_reporting() | E_USER_DEPRECATED); + // // } + // + // // /** + // // * @expectedException \PHPUnit_Framework_Error + // // */ + // // public function testLegacyIsValidEmitsDeprecatedWarning() + // // { + // // $this->assertTrue($this->verifier->isValid($this->signedAndAuthorizedMessage)); + // // } + // + // public function testRejectOnlySignatureHeaderAsAuthorized() + // { + // $this->assertFalse( + // $this->verifier->isAuthorized($this->signedMessage) + // ); + // $this->assertEquals( + // 'Authorization header not found', + // $this->verifier->getStatus()[0] + // ); + // $this->verifier->isAuthorized($this->signedMessage); + // $this->assertEquals( + // 1, + // sizeof($this->verifier->getStatus()) + // ); + // } + // + // public function testRejectOnlyAuthorizationHeaderAsSigned() + // { + // $this->assertFalse( + // $this->verifier->isSigned($this->authorizedMessage) + // ); + // $this->assertEquals( + // 'Signature header malformed', + // $this->verifier->getStatus()[0] + // ); + // $this->verifier->isSigned($this->authorizedMessage); + // $this->assertEquals( + // 1, + // sizeof($this->verifier->getStatus()) + // ); + // } + // + // public function testRejectTamperedRequestMethod() + // { + // $message = $this->signedMessage->withMethod('POST'); + // $this->assertFalse($this->verifier->isSigned($message)); + // $this->assertEquals( + // 'Invalid signature', + // $this->verifier->getStatus()[0] + // ); + // $this->verifier->isSigned($message); + // $this->assertEquals( + // 1, + // sizeof($this->verifier->getStatus()) + // ); + // } + // + // public function testRejectTamperedDate() + // { + // $message = $this->signedMessage->withHeader('Date', self::DATE_DIFFERENT); + // $this->assertFalse($this->verifier->isSigned($message)); + // $this->assertEquals( + // 'Invalid signature', + // $this->verifier->getStatus()[0] + // ); + // } + // + // public function testRejectTamperedSignature() + // { + // $message = $this->signedMessage->withHeader( + // 'Signature', + // preg_replace('/signature="/', 'signature="x', $this->signedMessage->getHeader('Signature')[0]) + // ); + // $this->assertFalse($this->verifier->isSigned($message)); + // $this->assertEquals( + // 'Invalid signature', + // $this->verifier->getStatus()[0] + // ); + // } + // + // public function testRejectMessageWithoutSignatureHeader() + // { + // $message = $this->signedMessage->withoutHeader('Signature'); + // $this->assertFalse($this->verifier->isSigned($message)); + // $this->assertEquals( + // 'Signature header not found', + // $this->verifier->getStatus()[0] + // ); + // $this->verifier->isSigned($message); + // $this->assertEquals( + // 1, + // sizeof($this->verifier->getStatus()) + // ); + // } + // + // public function testRejectMessageWithGarbageSignatureHeader() + // { + // $message = $this->signedMessage->withHeader('Signature', 'not="a",valid="signature"'); + // $this->assertFalse($this->verifier->isSigned($message)); + // $this->assertEquals( + // 'Signature header malformed', + // $this->verifier->getStatus()[0] + // ); + // $this->verifier->isSigned($message); + // $this->assertEquals( + // 1, + // sizeof($this->verifier->getStatus()) + // ); + // } + // + // public function testRejectMessageWithPartialSignatureHeader() + // { + // $message = $this->signedMessage->withHeader('Signature', 'keyId="aa",algorithm="bb"'); + // $this->assertFalse($this->verifier->isSigned($message)); + // $this->assertEquals( + // 'Signature header malformed', + // $this->verifier->getStatus()[0] + // ); + // } + // + // public function testRejectsMessageWithUnknownKeyId() + // { + // $keyStore = new KeyStore(['nope' => 'secret']); + // $verifier = new Verifier($keyStore); + // $this->assertFalse($verifier->isSigned($this->signedMessage)); + // $this->assertEquals( + // "Cannot locate key for supplied keyId 'pda'", + // $verifier->getStatus()[0] + // ); + // $verifier->isSigned($this->signedMessage); + // $this->assertEquals( + // 1, + // sizeof($verifier->getStatus()) + // ); + // } + // + // public function testRejectsMessageMissingSignedHeaders() + // { + // $message = $this->signedMessage->withoutHeader('Date'); + // $this->assertFalse($this->verifier->isSigned($message)); + // $this->assertEquals( + // "Header 'date' not in message", + // $this->verifier->getStatus()[0] + // ); + // } + // + // public function testGetSigningString() + // { + // $this->assertTrue($this->verifier->isSigned($this->signedMessage)); + // $this->assertEquals( + // "Signed with SigningString 'KHJlcXVlc3QtdGFyZ2V0KTogZ2V0IC9wYXRoP3F1ZXJ5PTEyMwpkYXRlOiBGcmksIDAxIEF1ZyAyMDE0IDEzOjQ0OjMyIC0wNzAw'", + // $this->verifier->getStatus()[0] + // ); + // } +} From fb85314d4eaa1e52a3c561449bebb3855845e894 Mon Sep 17 00:00:00 2001 From: Liam Dennehy Date: Wed, 14 Aug 2019 14:37:43 +0200 Subject: [PATCH 3/8] Verification: Don't presume KeyStore exists, permit minimum headers spec --- src/Verification.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Verification.php b/src/Verification.php index 70cbe52..844f20e 100644 --- a/src/Verification.php +++ b/src/Verification.php @@ -22,7 +22,7 @@ class Verification * @param RequestInterface $message * @param KeyStoreInterface $keyStore */ - public function __construct($message, KeyStoreInterface $keyStore, $header) + public function __construct($message, KeyStoreInterface $keyStore = null, $header, $headers = []) { $this->message = $message; $this->keyStore = $keyStore; From ae057a7c4efa6195f73052128d1a2bbea8046b28 Mon Sep 17 00:00:00 2001 From: Liam Dennehy Date: Wed, 14 Aug 2019 14:38:07 +0200 Subject: [PATCH 4/8] Verifier: Get (Signature) Parameters from messages --- src/Verifier.php | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Verifier.php b/src/Verifier.php index 4180ac2..3c5a220 100644 --- a/src/Verifier.php +++ b/src/Verifier.php @@ -17,9 +17,12 @@ class Verifier /** * @param KeyStoreInterface $keyStore */ - public function __construct(KeyStoreInterface $keyStore) + public function __construct(KeyStoreInterface $keyStore = null, $minimumHeaders = []) { + // if ( $keyStore ) { $this->keyStore = $keyStore; + // }; + $this->minimumHeaders = $minimumHeaders; $this->status = []; } @@ -30,6 +33,11 @@ public function __construct(KeyStoreInterface $keyStore) */ public function isSigned($message) { + if (is_null($this->keyStore)) { + $this->status[] = 'No keys provided, cannot verify'; + + return false; + } $this->status = []; try { $verification = new Verification($message, $this->keyStore, 'Signature'); @@ -184,4 +192,36 @@ public function getStatus() { return $this->status; } + + public function getSignatureParameters($message) + { + $signatureLine = $message->getHeader('Signature')[0]; + $signatureParametersParser = new SignatureParametersParser( + $signatureLine + ); + + return $signatureParametersParser->parse(); + } + + public function getSignatureHeaders($message, $parameter) + { + $parameters = $this->getSignatureParameters($message); + if (!isset($parameters['headers'])) { + return ['date']; + } + $headers = explode(' ', $parameters['headers']); + + return $headers; + } + + public function withMinimumHeaders(array $minimumHeaders) + { + $this->minimumHeaders = $minimumHeaders; + } + + public function withKeys($keys = []) + { + return $this; + // TODO: Add keys to keystore + } } From 8cee5ee3bc5b7aa197d6adf5fc8a96388c3aaa74 Mon Sep 17 00:00:00 2001 From: Liam Dennehy Date: Wed, 14 Aug 2019 14:38:31 +0200 Subject: [PATCH 5/8] Context: Permit context to be intialised without keys --- src/Context.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Context.php b/src/Context.php index 5dd73e9..299ad86 100644 --- a/src/Context.php +++ b/src/Context.php @@ -104,6 +104,9 @@ private function headerList() private function keyStore() { if (empty($this->keyStore)) { + if (is_null($this->keys)) { + return null; + } $this->keyStore = new KeyStore($this->keys); } From 1824124f2e207a4d316d847acee5ea9f6d572003 Mon Sep 17 00:00:00 2001 From: Liam Dennehy Date: Sat, 17 Aug 2019 13:13:07 +0200 Subject: [PATCH 6/8] Emit keyId and Inject keys to context --- src/Context.php | 14 ++- src/KeyStore.php | 22 +++- src/Verifier.php | 17 ++- tests/VerifierContextTest.php | 188 ++++------------------------------ 4 files changed, 65 insertions(+), 176 deletions(-) diff --git a/src/Context.php b/src/Context.php index 299ad86..e7d84ee 100644 --- a/src/Context.php +++ b/src/Context.php @@ -21,7 +21,7 @@ class Context * * @throws Exception */ - public function __construct($args) + public function __construct($args = null) { if (isset($args['keys']) && isset($args['keyStore'])) { throw new Exception(__CLASS__.' accepts keys or keyStore but not both'); @@ -125,4 +125,16 @@ private function algorithm() { return $this->algorithm; } + + public function addKeys($keys) + { + foreach ($keys as $keyId => $keyValue) { + $newKey = new Key($keyId, $keyValue); + $newKeys[$keyId] = $keyValue; + } + if (empty($this->keyStore)) { + $this->keyStore = new KeyStore(); + } + $this->keyStore = $this->keyStore->withKeys($newKeys); + } } diff --git a/src/KeyStore.php b/src/KeyStore.php index bedff36..68ebb6b 100644 --- a/src/KeyStore.php +++ b/src/KeyStore.php @@ -10,11 +10,13 @@ class KeyStore implements KeyStoreInterface /** * @param array $keys */ - public function __construct($keys) + public function __construct($keys = null) { $this->keys = []; - foreach ($keys as $id => $key) { - $this->keys[$id] = new Key($id, $key); + if (!empty($keys)) { + foreach ($keys as $id => $key) { + $this->keys[$id] = new Key($id, $key); + } } } @@ -33,4 +35,18 @@ public function fetch($keyId) throw new KeyStoreException("Key '$keyId' not found"); } } + + public function withKeys($keys) + { + foreach ($keys as $keyId => $value) { + $this->keys[$keyId] = new Key($keyId, $value); + } + + return $this; + } + + public function getCount() + { + return sizeof($this->keys); + } } diff --git a/src/Verifier.php b/src/Verifier.php index 3c5a220..76e7b5c 100644 --- a/src/Verifier.php +++ b/src/Verifier.php @@ -91,6 +91,11 @@ public function isSigned($message) */ public function isAuthorized($message) { + if (is_null($this->keyStore)) { + $this->status[] = 'No keys provided, cannot verify'; + + return false; + } $this->status = []; try { $verification = new Verification($message, $this->keyStore, 'Authorization'); @@ -203,6 +208,11 @@ public function getSignatureParameters($message) return $signatureParametersParser->parse(); } + public function getSignatureKeyId($message) + { + return $this->getSignatureParameters($message)['keyId']; + } + public function getSignatureHeaders($message, $parameter) { $parameters = $this->getSignatureParameters($message); @@ -214,14 +224,13 @@ public function getSignatureHeaders($message, $parameter) return $headers; } - public function withMinimumHeaders(array $minimumHeaders) + public function setMinimumHeaders(array $minimumHeaders) { $this->minimumHeaders = $minimumHeaders; } - public function withKeys($keys = []) + public function getMinimumHeaders() { - return $this; - // TODO: Add keys to keystore + return $this->minimumHeaders; } } diff --git a/tests/VerifierContextTest.php b/tests/VerifierContextTest.php index bf471f4..62b3cec 100644 --- a/tests/VerifierContextTest.php +++ b/tests/VerifierContextTest.php @@ -166,173 +166,25 @@ public function testProvidedParameters() ); } - // TODO: Add keys to a verifier based on provided keyId - // public function testMinimumHeaders() - // { - // $verifier = $this->verifierEmptyContext->verifier(); - // $verifier = $verifier->withKeys(['keyId' => 'keyvalue']); - // $this->assertTrue($verifier->isSigned($this->signedMessage)); - // - // } + public function testVerifyInjectKey() + { + $dummyKey = ['abc' => 'notsosecret']; + $usefulKey = ['pda' => 'secret']; + $context = new Context(['keys' => $dummyKey]); + $verifier = $context->verifier(); + $this->assertFalse($verifier->isSigned($this->signedMessage)); + $this->assertEquals( + "Cannot locate key for supplied keyId 'pda'", + $verifier->getStatus()[0] + ); + $requiredKeyId = $verifier->getSignatureKeyId($this->signedMessage); + $this->assertEquals( + 'pda', + $requiredKeyId + ); + $context->addKeys($usefulKey); + $verifier = $context->verifier(); + $this->assertTrue($verifier->isSigned($this->signedMessage)); + } - // // TODO: Decide on compatibility for isValid() for 99designs/http-signatures-php compat - // // public function testLegacyIsValid() - // // { - // // error_reporting(error_reporting() & ~E_USER_DEPRECATED); - // // $this->assertTrue($this->verifier->isValid($this->signedAndAuthorizedMessage)); - // // error_reporting(error_reporting() | E_USER_DEPRECATED); - // // } - // - // // /** - // // * @expectedException \PHPUnit_Framework_Error - // // */ - // // public function testLegacyIsValidEmitsDeprecatedWarning() - // // { - // // $this->assertTrue($this->verifier->isValid($this->signedAndAuthorizedMessage)); - // // } - // - // public function testRejectOnlySignatureHeaderAsAuthorized() - // { - // $this->assertFalse( - // $this->verifier->isAuthorized($this->signedMessage) - // ); - // $this->assertEquals( - // 'Authorization header not found', - // $this->verifier->getStatus()[0] - // ); - // $this->verifier->isAuthorized($this->signedMessage); - // $this->assertEquals( - // 1, - // sizeof($this->verifier->getStatus()) - // ); - // } - // - // public function testRejectOnlyAuthorizationHeaderAsSigned() - // { - // $this->assertFalse( - // $this->verifier->isSigned($this->authorizedMessage) - // ); - // $this->assertEquals( - // 'Signature header malformed', - // $this->verifier->getStatus()[0] - // ); - // $this->verifier->isSigned($this->authorizedMessage); - // $this->assertEquals( - // 1, - // sizeof($this->verifier->getStatus()) - // ); - // } - // - // public function testRejectTamperedRequestMethod() - // { - // $message = $this->signedMessage->withMethod('POST'); - // $this->assertFalse($this->verifier->isSigned($message)); - // $this->assertEquals( - // 'Invalid signature', - // $this->verifier->getStatus()[0] - // ); - // $this->verifier->isSigned($message); - // $this->assertEquals( - // 1, - // sizeof($this->verifier->getStatus()) - // ); - // } - // - // public function testRejectTamperedDate() - // { - // $message = $this->signedMessage->withHeader('Date', self::DATE_DIFFERENT); - // $this->assertFalse($this->verifier->isSigned($message)); - // $this->assertEquals( - // 'Invalid signature', - // $this->verifier->getStatus()[0] - // ); - // } - // - // public function testRejectTamperedSignature() - // { - // $message = $this->signedMessage->withHeader( - // 'Signature', - // preg_replace('/signature="/', 'signature="x', $this->signedMessage->getHeader('Signature')[0]) - // ); - // $this->assertFalse($this->verifier->isSigned($message)); - // $this->assertEquals( - // 'Invalid signature', - // $this->verifier->getStatus()[0] - // ); - // } - // - // public function testRejectMessageWithoutSignatureHeader() - // { - // $message = $this->signedMessage->withoutHeader('Signature'); - // $this->assertFalse($this->verifier->isSigned($message)); - // $this->assertEquals( - // 'Signature header not found', - // $this->verifier->getStatus()[0] - // ); - // $this->verifier->isSigned($message); - // $this->assertEquals( - // 1, - // sizeof($this->verifier->getStatus()) - // ); - // } - // - // public function testRejectMessageWithGarbageSignatureHeader() - // { - // $message = $this->signedMessage->withHeader('Signature', 'not="a",valid="signature"'); - // $this->assertFalse($this->verifier->isSigned($message)); - // $this->assertEquals( - // 'Signature header malformed', - // $this->verifier->getStatus()[0] - // ); - // $this->verifier->isSigned($message); - // $this->assertEquals( - // 1, - // sizeof($this->verifier->getStatus()) - // ); - // } - // - // public function testRejectMessageWithPartialSignatureHeader() - // { - // $message = $this->signedMessage->withHeader('Signature', 'keyId="aa",algorithm="bb"'); - // $this->assertFalse($this->verifier->isSigned($message)); - // $this->assertEquals( - // 'Signature header malformed', - // $this->verifier->getStatus()[0] - // ); - // } - // - // public function testRejectsMessageWithUnknownKeyId() - // { - // $keyStore = new KeyStore(['nope' => 'secret']); - // $verifier = new Verifier($keyStore); - // $this->assertFalse($verifier->isSigned($this->signedMessage)); - // $this->assertEquals( - // "Cannot locate key for supplied keyId 'pda'", - // $verifier->getStatus()[0] - // ); - // $verifier->isSigned($this->signedMessage); - // $this->assertEquals( - // 1, - // sizeof($verifier->getStatus()) - // ); - // } - // - // public function testRejectsMessageMissingSignedHeaders() - // { - // $message = $this->signedMessage->withoutHeader('Date'); - // $this->assertFalse($this->verifier->isSigned($message)); - // $this->assertEquals( - // "Header 'date' not in message", - // $this->verifier->getStatus()[0] - // ); - // } - // - // public function testGetSigningString() - // { - // $this->assertTrue($this->verifier->isSigned($this->signedMessage)); - // $this->assertEquals( - // "Signed with SigningString 'KHJlcXVlc3QtdGFyZ2V0KTogZ2V0IC9wYXRoP3F1ZXJ5PTEyMwpkYXRlOiBGcmksIDAxIEF1ZyAyMDE0IDEzOjQ0OjMyIC0wNzAw'", - // $this->verifier->getStatus()[0] - // ); - // } } From ea19b988dcb06c8792f7095055e4463db932b3cc Mon Sep 17 00:00:00 2001 From: Liam Dennehy Date: Sat, 17 Aug 2019 13:20:58 +0200 Subject: [PATCH 7/8] cs fix --- tests/VerifierContextTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/VerifierContextTest.php b/tests/VerifierContextTest.php index 62b3cec..e3adb41 100644 --- a/tests/VerifierContextTest.php +++ b/tests/VerifierContextTest.php @@ -186,5 +186,4 @@ public function testVerifyInjectKey() $verifier = $context->verifier(); $this->assertTrue($verifier->isSigned($this->signedMessage)); } - } From 6cd50aa9da16463a33f49d8823a47d5a4ef27bb0 Mon Sep 17 00:00:00 2001 From: Liam Dennehy Date: Sat, 17 Aug 2019 13:23:22 +0200 Subject: [PATCH 8/8] KeyStoreTest - Inject additional keys --- tests/KeyStoreTest.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/KeyStoreTest.php b/tests/KeyStoreTest.php index 4adf6b7..3c2130a 100644 --- a/tests/KeyStoreTest.php +++ b/tests/KeyStoreTest.php @@ -7,6 +7,35 @@ class KeyStoreTest extends TestCase { + public function testKeyStore() + { + $ks = new KeyStore(['testkey' => 'abc123']); + $this->assertEquals( + 'abc123', + $ks->fetch('testkey')->getSigningKey() + ); + $this->assertEquals( + 'secret', + $ks->fetch('testkey')->getType() + ); + $ks = $ks->withKeys([ + 'testkey2' => 'def456', + 'testkey3' => 'foo-bar', + ]); + $this->assertEquals( + 3, + $ks->getCount() + ); + $this->assertEquals( + 'abc123', + $ks->fetch('testkey')->getSigningKey() + ); + $this->assertEquals( + 'secret', + $ks->fetch('testkey2')->getType() + ); + } + public function testFetchFail() { $ks = new KeyStore(['id' => 'secret']);