Fixed tests, allow whitespace at the end of a key

This commit is contained in:
Ron Arts 2018-01-03 10:18:32 +01:00
parent 2ec8d148b0
commit 91d9c11fb4
2 changed files with 9 additions and 7 deletions

View File

@ -14,7 +14,7 @@ namespace League\OAuth2\Server;
class CryptKey class CryptKey
{ {
const RSA_KEY_PATTERN = 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 * @var string

View File

@ -21,12 +21,6 @@ class CryptKeyTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('file://' . $keyFile, $key->getKeyPath()); $this->assertEquals('file://' . $keyFile, $key->getKeyPath());
$this->assertEquals('secret', $key->getPassPhrase()); $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() public function testKeyFileCreation()
@ -38,5 +32,13 @@ class CryptKeyTest extends \PHPUnit_Framework_TestCase
'file://' . sys_get_temp_dir() . '/' . sha1($keyContent) . '.key', 'file://' . sys_get_temp_dir() . '/' . sha1($keyContent) . '.key',
$key->getKeyPath() $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()
);
} }
} }