2016-02-12 23:38:13 +05:30
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace LeagueTests\Utils;
|
|
|
|
|
|
|
|
use League\OAuth2\Server\Utils\KeyCrypt;
|
|
|
|
|
|
|
|
class KeyCryptTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testEncryptDecrypt()
|
|
|
|
{
|
|
|
|
$payload = 'alex loves whisky';
|
2016-02-22 13:30:50 +05:30
|
|
|
$encrypted = KeyCrypt::encrypt($payload, 'file://' . __DIR__ . '/private.key');
|
|
|
|
$plainText = KeyCrypt::decrypt($encrypted, 'file://' . __DIR__ . '/public.key');
|
2016-02-12 23:38:13 +05:30
|
|
|
|
|
|
|
$this->assertNotEquals($payload, $encrypted);
|
|
|
|
$this->assertEquals($payload, $plainText);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \LogicException
|
|
|
|
*/
|
|
|
|
public function testBadPrivateKey()
|
|
|
|
{
|
2016-02-22 13:30:50 +05:30
|
|
|
KeyCrypt::encrypt('', 'file://' . __DIR__ . '/public.key');
|
2016-02-12 23:38:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \LogicException
|
|
|
|
*/
|
|
|
|
public function testBadPublicKey()
|
|
|
|
{
|
2016-02-22 13:30:50 +05:30
|
|
|
KeyCrypt::decrypt('', 'file://' . __DIR__ . '/private.key');
|
2016-02-12 23:38:13 +05:30
|
|
|
}
|
|
|
|
}
|