mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-27 07:20:18 +05:30
42 lines
954 B
PHP
42 lines
954 B
PHP
<?php
|
|
|
|
namespace LeagueTests\Utils;
|
|
|
|
use Defuse\Crypto\Key;
|
|
use LeagueTests\Stubs\CryptTraitStub;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class CryptTraitTest extends TestCase
|
|
{
|
|
protected $cryptStub;
|
|
|
|
protected function setUp()
|
|
{
|
|
$this->cryptStub = new CryptTraitStub();
|
|
}
|
|
|
|
public function testEncryptDecryptWithPassword()
|
|
{
|
|
$this->cryptStub->setEncryptionKey(base64_encode(random_bytes(36)));
|
|
|
|
$this->encryptDecrypt();
|
|
}
|
|
|
|
public function testEncryptDecryptWithKey()
|
|
{
|
|
$this->cryptStub->setEncryptionKey(Key::createNewRandomKey());
|
|
|
|
$this->encryptDecrypt();
|
|
}
|
|
|
|
private function encryptDecrypt()
|
|
{
|
|
$payload = 'alex loves whisky';
|
|
$encrypted = $this->cryptStub->doEncrypt($payload);
|
|
$plainText = $this->cryptStub->doDecrypt($encrypted);
|
|
|
|
$this->assertNotEquals($payload, $encrypted);
|
|
$this->assertEquals($payload, $plainText);
|
|
}
|
|
}
|