-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix encryption migration and test coverage (#158)
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Feature\Service\Encrypter; | ||
|
||
use App\Service\Encrypter\AES256ECB; | ||
use Spiral\Encrypter\Exception\EncrypterException; | ||
use Tests\Fixtures; | ||
use Tests\TestCase; | ||
|
||
class AES256ECBTest extends TestCase | ||
{ | ||
public function testEncryptDecrypt(): void | ||
{ | ||
$key = Fixtures::string(); | ||
$message = Fixtures::string(256); | ||
|
||
$encrypter = new AES256ECB(); | ||
$encrypted = $encrypter->encrypt($message, $key); | ||
|
||
$this->assertNotEmpty($encrypted); | ||
$this->assertNotEquals($message, $encrypted); | ||
$this->assertEquals($message, $encrypter->decrypt($encrypted, $key)); | ||
} | ||
|
||
public function testDecryptError(): void | ||
{ | ||
$key = Fixtures::string(); | ||
$message = Fixtures::string(256); | ||
|
||
$encrypter = new AES256ECB(); | ||
$encrypted = $encrypter->encrypt($message, $key); | ||
|
||
$this->expectException(EncrypterException::class); | ||
|
||
$this->assertEquals($message, $encrypter->decrypt($encrypted, $key . Fixtures::string(1))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Feature\Service\Encrypter; | ||
|
||
use App\Service\Encrypter\AES256GCM; | ||
use Spiral\Encrypter\Exception\EncrypterException; | ||
use Tests\Fixtures; | ||
use Tests\TestCase; | ||
|
||
class AES256GCMTest extends TestCase | ||
{ | ||
public function testEncryptDecrypt(): void | ||
{ | ||
$key = Fixtures::string(); | ||
$message = Fixtures::string(256); | ||
|
||
$encrypter = new AES256GCM(); | ||
$encrypted = $encrypter->encrypt($message, $key); | ||
|
||
$this->assertNotEmpty($encrypted); | ||
$this->assertNotEquals($message, $encrypted); | ||
$this->assertEquals($message, $encrypter->decrypt($encrypted, $key)); | ||
} | ||
|
||
public function testDecryptError(): void | ||
{ | ||
$key = Fixtures::string(); | ||
$message = Fixtures::string(256); | ||
|
||
$encrypter = new AES256GCM(); | ||
$encrypted = $encrypter->encrypt($message, $key); | ||
|
||
$this->expectException(EncrypterException::class); | ||
|
||
$this->assertEquals($message, $encrypter->decrypt($encrypted, $key . Fixtures::string(1))); | ||
} | ||
} |