mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-01 08:23:03 +05:30
42 lines
960 B
PHP
42 lines
960 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(): void
|
|
{
|
|
$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);
|
|
}
|
|
}
|