2017-06-11 21:05:19 +00:00
|
|
|
<?php
|
|
|
|
|
2024-02-19 00:30:12 +00:00
|
|
|
namespace Tests\Wallabag\Helper;
|
2017-06-11 21:05:19 +00:00
|
|
|
|
|
|
|
use Monolog\Handler\TestHandler;
|
2017-07-01 07:52:38 +00:00
|
|
|
use Monolog\Logger;
|
2017-12-16 21:17:42 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2017-07-01 07:52:38 +00:00
|
|
|
use Psr\Log\NullLogger;
|
2024-02-19 00:30:12 +00:00
|
|
|
use Wallabag\Helper\CryptoProxy;
|
2017-06-11 21:05:19 +00:00
|
|
|
|
2017-12-16 21:17:42 +00:00
|
|
|
class CryptoProxyTest extends TestCase
|
2017-06-11 21:05:19 +00:00
|
|
|
{
|
|
|
|
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);
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->assertStringContainsString('Crypto: crypting value', $records[0]['message']);
|
|
|
|
$this->assertStringContainsString('Crypto: decrypting value', $records[1]['message']);
|
2017-06-11 21:05:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDecryptBadValue()
|
|
|
|
{
|
2020-06-15 11:37:50 +00:00
|
|
|
$this->expectException(\RuntimeException::class);
|
|
|
|
$this->expectExceptionMessage('Decrypt fail');
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|