mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
36
tests/Utils/CryptTraitTest.php
Normal file
36
tests/Utils/CryptTraitTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user