oauth2-server/tests/CryptTraitTest.php

56 lines
1.2 KiB
PHP
Raw Normal View History

2016-03-18 01:48:28 +05:30
<?php
namespace LeagueTests\Utils;
2016-03-28 20:12:34 +05:30
use League\OAuth2\Server\CryptKey;
2016-03-18 01:48:28 +05:30
use LeagueTests\Stubs\CryptTraitStub;
class CryptTraitTest extends \PHPUnit_Framework_TestCase
{
/**
* CryptTrait stub
*/
protected $cryptStub;
public function setUp()
{
$this->cryptStub = new CryptTraitStub;
}
public function testEncryptDecrypt()
{
$payload = 'alex loves whisky';
$encrypted = $this->cryptStub->doEncrypt($payload);
$plainText = $this->cryptStub->doDecrypt($encrypted);
$this->assertNotEquals($payload, $encrypted);
$this->assertEquals($payload, $plainText);
}
/**
* @expectedException \LogicException
*/
public function testBadPrivateKey()
{
2016-03-28 20:12:34 +05:30
$this->cryptStub->setPrivateKey(new CryptKey(__DIR__ . '/Stubs/public.key'));
2016-03-18 01:48:28 +05:30
$this->cryptStub->doEncrypt('');
}
/**
* @expectedException \LogicException
*/
public function testBadPublicKey()
{
2016-03-28 20:12:34 +05:30
$this->cryptStub->setPublicKey(new CryptKey(__DIR__ . '/Stubs/private.key'));
2016-03-18 01:48:28 +05:30
$this->cryptStub->doDecrypt('');
}
2016-04-10 20:28:01 +05:30
/**
* @expectedException \LogicException
*/
public function testNonExistentKey()
{
new CryptKey('foo/bar');
}
2016-03-18 01:48:28 +05:30
}