2017-06-11 21:05:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Wallabag\CoreBundle\Helper;
|
|
|
|
|
|
|
|
use Monolog\Handler\TestHandler;
|
2017-07-01 07:52:38 +00:00
|
|
|
use Monolog\Logger;
|
|
|
|
use Psr\Log\NullLogger;
|
2017-06-11 21:05:19 +00:00
|
|
|
use Wallabag\CoreBundle\Helper\CryptoProxy;
|
|
|
|
|
|
|
|
class CryptoProxyTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testCrypto()
|
|
|
|
{
|
|
|
|
$logHandler = new TestHandler();
|
|
|
|
$logger = new Logger('test', [$logHandler]);
|
|
|
|
|
2017-07-01 07:52:38 +00:00
|
|
|
$crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', $logger);
|
2017-06-11 21:05:19 +00:00
|
|
|
$crypted = $crypto->crypt('test');
|
|
|
|
$decrypted = $crypto->decrypt($crypted);
|
|
|
|
|
|
|
|
$this->assertSame('test', $decrypted);
|
|
|
|
|
|
|
|
$records = $logHandler->getRecords();
|
|
|
|
$this->assertCount(2, $records);
|
|
|
|
$this->assertContains('Crypto: crypting value', $records[0]['message']);
|
|
|
|
$this->assertContains('Crypto: decrypting value', $records[1]['message']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-07-01 07:52:38 +00:00
|
|
|
* @expectedException \RuntimeException
|
2017-06-11 21:05:19 +00:00
|
|
|
* @expectedExceptionMessage Decrypt fail
|
|
|
|
*
|
|
|
|
* @return [type] [description]
|
|
|
|
*/
|
|
|
|
public function testDecryptBadValue()
|
|
|
|
{
|
2017-07-01 07:52:38 +00:00
|
|
|
$crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', new NullLogger());
|
2017-06-11 21:05:19 +00:00
|
|
|
$crypto->decrypt('badvalue');
|
|
|
|
}
|
|
|
|
}
|