oauth2-server/tests/Utils/CryptTraitTest.php
2018-02-28 20:01:01 +00:00

37 lines
958 B
PHP

<?php
namespace LeagueTests\Utils;
use Defuse\Crypto\Key;
use LeagueTests\Stubs\CryptTraitStub;
use PHPUnit\Framework\TestCase;
class CryptTraitTest extends TestCase
{
public function testEncryptDecryptWithPassword()
{
$cryptStub = new CryptTraitStub();
$cryptStub->setEncryptionKey(base64_encode(random_bytes(36)));
return $this->encryptDecrypt($cryptStub);
}
public function testEncryptDecryptWithKey()
{
$cryptStub = new CryptTraitStub();
$cryptStub->setEncryptionKey(Key::createNewRandomKey());
return $this->encryptDecrypt($cryptStub);
}
protected function encryptDecrypt(CryptTraitStub $cryptStub)
{
$payload = 'alex loves whisky';
$encrypted = $cryptStub->doEncrypt($payload);
$plainText = $cryptStub->doDecrypt($encrypted);
$this->assertNotEquals($payload, $encrypted);
$this->assertEquals($payload, $plainText);
}
}