2016-07-19 20:45:36 +05:30
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace LeagueTests\Utils;
|
|
|
|
|
|
|
|
use League\OAuth2\Server\CryptKey;
|
2017-11-08 23:37:07 +05:30
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-07-19 20:45:36 +05:30
|
|
|
|
2017-11-08 23:37:07 +05:30
|
|
|
class CryptKeyTest extends TestCase
|
2016-07-19 20:45:36 +05:30
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @expectedException \LogicException
|
|
|
|
*/
|
|
|
|
public function testNoFile()
|
|
|
|
{
|
|
|
|
new CryptKey('undefined file');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testKeyCreation()
|
|
|
|
{
|
2018-02-12 03:44:34 +05:30
|
|
|
$keyFile = __DIR__ . '/../Stubs/public.key';
|
2016-07-19 20:45:36 +05:30
|
|
|
$key = new CryptKey($keyFile, 'secret');
|
|
|
|
|
|
|
|
$this->assertEquals('file://' . $keyFile, $key->getKeyPath());
|
|
|
|
$this->assertEquals('secret', $key->getPassPhrase());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testKeyFileCreation()
|
|
|
|
{
|
2018-02-12 03:44:34 +05:30
|
|
|
$keyContent = file_get_contents(__DIR__ . '/../Stubs/public.key');
|
2016-07-19 20:45:36 +05:30
|
|
|
$key = new CryptKey($keyContent);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
'file://' . sys_get_temp_dir() . '/' . sha1($keyContent) . '.key',
|
|
|
|
$key->getKeyPath()
|
|
|
|
);
|
2018-01-03 14:48:32 +05:30
|
|
|
|
2018-02-12 03:44:34 +05:30
|
|
|
$keyContent = file_get_contents(__DIR__ . '/../Stubs/private.key.crlf');
|
2018-01-03 14:48:32 +05:30
|
|
|
$key = new CryptKey($keyContent);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
'file://' . sys_get_temp_dir() . '/' . sha1($keyContent) . '.key',
|
|
|
|
$key->getKeyPath()
|
|
|
|
);
|
2016-07-19 20:45:36 +05:30
|
|
|
}
|
|
|
|
}
|