mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-30 02:33:14 +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);
|
|
}
|
|
}
|