Added unit tests for OpenSSL lib
This commit is contained in:
parent
cd0f7b26ea
commit
70ca5239f5
35
tests/unit/OpenSSL/OpenSSLTest.php
Normal file
35
tests/unit/OpenSSL/OpenSSLTest.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Appwrite\Tests;
|
||||||
|
|
||||||
|
use OpenSSL\OpenSSL;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class OpenSSLTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Cron
|
||||||
|
*/
|
||||||
|
protected $object = null;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEncryptionAndDecryption()
|
||||||
|
{
|
||||||
|
$key = 'my-secret-key';
|
||||||
|
$iv = '';
|
||||||
|
$method = OpenSSL::CIPHER_AES_128_GCM;
|
||||||
|
$iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength($method));
|
||||||
|
$tag = null;
|
||||||
|
$secret = 'my secret data';
|
||||||
|
$data = OpenSSL::encrypt($secret, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag);
|
||||||
|
|
||||||
|
$this->assertEquals(OpenSSL::decrypt($data, $method, $key, 0, $iv, $tag), $secret);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue