From 906424c1b6fd884bf2081bfe6dd0b1f9651c2801 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 11 Jun 2017 23:05:19 +0200 Subject: Crypt site credential password --- .../CoreBundle/Controller/EntryControllerTest.php | 2 +- .../GrabySiteConfigBuilderTest.php | 3 +- .../Wallabag/CoreBundle/Helper/CryptoProxyTest.php | 40 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php (limited to 'tests/Wallabag/CoreBundle') diff --git a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php index 104f60f1..80380685 100644 --- a/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/EntryControllerTest.php @@ -1341,7 +1341,7 @@ class EntryControllerTest extends WallabagCoreTestCase $credential = new SiteCredential($user); $credential->setHost('monde-diplomatique.fr'); $credential->setUsername('foo'); - $credential->setPassword('bar'); + $credential->setPassword($client->getContainer()->get('wallabag_core.helper.crypto_proxy')->crypt('bar')); $em->persist($credential); $em->flush(); diff --git a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php index 1e1e8989..b0c81e7b 100644 --- a/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php +++ b/tests/Wallabag/CoreBundle/GuzzleSiteAuthenticator/GrabySiteConfigBuilderTest.php @@ -6,12 +6,11 @@ use Monolog\Handler\TestHandler; use Monolog\Logger; use BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig; use Graby\SiteConfig\SiteConfig as GrabySiteConfig; -use PHPUnit_Framework_TestCase; use Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; -class GrabySiteConfigBuilderTest extends PHPUnit_Framework_TestCase +class GrabySiteConfigBuilderTest extends \PHPUnit_Framework_TestCase { /** @var \Wallabag\CoreBundle\GuzzleSiteAuthenticator\GrabySiteConfigBuilder */ protected $builder; diff --git a/tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php b/tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php new file mode 100644 index 00000000..cede8696 --- /dev/null +++ b/tests/Wallabag/CoreBundle/Helper/CryptoProxyTest.php @@ -0,0 +1,40 @@ +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']); + } + + /** + * @expectedException RuntimeException + * @expectedExceptionMessage Decrypt fail + * + * @return [type] [description] + */ + public function testDecryptBadValue() + { + $crypto = new CryptoProxy(sys_get_temp_dir().'/'.uniqid('', true).'.txt', new NullLogger()); + $crypto->decrypt('badvalue'); + } +} -- cgit v1.2.3