oauth2-server/tests/Utils/CryptKeyTest.php

55 lines
1.4 KiB
PHP
Raw Normal View History

2016-07-19 20:45:36 +05:30
<?php
namespace LeagueTests\Utils;
use League\OAuth2\Server\CryptKey;
use PHPUnit\Framework\TestCase;
2016-07-19 20:45:36 +05:30
class CryptKeyTest extends TestCase
2016-07-19 20:45:36 +05:30
{
public function testNoFile()
{
$this->expectException(\LogicException::class);
2016-07-19 20:45:36 +05:30
new CryptKey('undefined file');
}
public function testKeyCreation()
{
$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()
{
$keyContent = file_get_contents(__DIR__ . '/../Stubs/public.key');
2019-07-01 23:47:43 +05:30
if (!is_string($keyContent)) {
$this->fail('The public key stub is not a string');
}
2016-07-19 20:45:36 +05:30
$key = new CryptKey($keyContent);
$this->assertEquals(
'file://' . sys_get_temp_dir() . '/' . sha1($keyContent) . '.key',
$key->getKeyPath()
);
$keyContent = file_get_contents(__DIR__ . '/../Stubs/private.key.crlf');
2019-07-01 23:47:43 +05:30
if (!is_string($keyContent)) {
$this->fail('The private key (crlf) stub is not a string');
}
$key = new CryptKey($keyContent);
$this->assertEquals(
'file://' . sys_get_temp_dir() . '/' . sha1($keyContent) . '.key',
$key->getKeyPath()
);
2016-07-19 20:45:36 +05:30
}
}