]>
Commit | Line | Data |
---|---|---|
906424c1 JB |
1 | <?php |
2 | ||
3 | namespace Tests\Wallabag\CoreBundle\Helper; | |
4 | ||
906424c1 | 5 | use Monolog\Handler\TestHandler; |
f808b016 | 6 | use Monolog\Logger; |
bd91bd5c | 7 | use PHPUnit\Framework\TestCase; |
f808b016 | 8 | use Psr\Log\NullLogger; |
906424c1 JB |
9 | use Wallabag\CoreBundle\Helper\CryptoProxy; |
10 | ||
bd91bd5c | 11 | class CryptoProxyTest extends TestCase |
906424c1 JB |
12 | { |
13 | public function testCrypto() | |
14 | { | |
15 | $logHandler = new TestHandler(); | |
16 | $logger = new Logger('test', [$logHandler]); | |
17 | ||
f808b016 | 18 | $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', $logger); |
906424c1 JB |
19 | $crypted = $crypto->crypt('test'); |
20 | $decrypted = $crypto->decrypt($crypted); | |
21 | ||
22 | $this->assertSame('test', $decrypted); | |
23 | ||
24 | $records = $logHandler->getRecords(); | |
25 | $this->assertCount(2, $records); | |
26 | $this->assertContains('Crypto: crypting value', $records[0]['message']); | |
27 | $this->assertContains('Crypto: decrypting value', $records[1]['message']); | |
28 | } | |
29 | ||
30 | /** | |
f808b016 | 31 | * @expectedException \RuntimeException |
906424c1 JB |
32 | * @expectedExceptionMessage Decrypt fail |
33 | * | |
34 | * @return [type] [description] | |
35 | */ | |
36 | public function testDecryptBadValue() | |
37 | { | |
f808b016 | 38 | $crypto = new CryptoProxy(sys_get_temp_dir() . '/' . uniqid('', true) . '.txt', new NullLogger()); |
906424c1 JB |
39 | $crypto->decrypt('badvalue'); |
40 | } | |
41 | } |