From 91d9c11fb4b4874796e9367f52d5217a33f1178a Mon Sep 17 00:00:00 2001 From: Ron Arts Date: Wed, 3 Jan 2018 10:18:32 +0100 Subject: [PATCH] Fixed tests, allow whitespace at the end of a key --- src/CryptKey.php | 2 +- tests/CryptKeyTest.php | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/CryptKey.php b/src/CryptKey.php index 9ec9202f..935461cc 100644 --- a/src/CryptKey.php +++ b/src/CryptKey.php @@ -14,7 +14,7 @@ namespace League\OAuth2\Server; class CryptKey { const RSA_KEY_PATTERN = - '/^(-----BEGIN (RSA )?(PUBLIC|PRIVATE) KEY-----).+(-----END (RSA )?(PUBLIC|PRIVATE) KEY-----)$/s'; + '/^(-----BEGIN (RSA )?(PUBLIC|PRIVATE) KEY-----).+(-----END (RSA )?(PUBLIC|PRIVATE) KEY-----)\s*$/s'; /** * @var string diff --git a/tests/CryptKeyTest.php b/tests/CryptKeyTest.php index ce3c8081..2a0b71ab 100644 --- a/tests/CryptKeyTest.php +++ b/tests/CryptKeyTest.php @@ -21,12 +21,6 @@ class CryptKeyTest extends \PHPUnit_Framework_TestCase $this->assertEquals('file://' . $keyFile, $key->getKeyPath()); $this->assertEquals('secret', $key->getPassPhrase()); - - $keyFile = __DIR__ . '/Stubs/private.key.crlf'; - $key = new CryptKey($keyFile, 'secret'); - - $this->assertEquals('file://' . $keyFile, $key->getKeyPath()); - $this->assertEquals('secret', $key->getPassPhrase()); } public function testKeyFileCreation() @@ -38,5 +32,13 @@ class CryptKeyTest extends \PHPUnit_Framework_TestCase 'file://' . sys_get_temp_dir() . '/' . sha1($keyContent) . '.key', $key->getKeyPath() ); + + $keyContent = file_get_contents(__DIR__ . '/Stubs/private.key.crlf'); + $key = new CryptKey($keyContent); + + $this->assertEquals( + 'file://' . sys_get_temp_dir() . '/' . sha1($keyContent) . '.key', + $key->getKeyPath() + ); } }