-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix sealbox binding use correct config key (#26)
In the provider an incorrect config key was used for the recipientPubKey of the sealbox. Fixed it and added test.
- Loading branch information
1 parent
3ea975d
commit 0da5533
Showing
3 changed files
with
66 additions
and
1 deletion.
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,25 @@ | ||
<?php | ||
|
||
namespace MinVWS\Crypto\Laravel\Tests; | ||
|
||
use MinVWS\Crypto\Laravel\SealboxCryptoInterface; | ||
use MinVWS\Crypto\Laravel\Service\Sealbox\SealboxService; | ||
|
||
class ProviderTest extends TestCase | ||
{ | ||
public function testSealboxIsRegisteredCorrectly(): void | ||
{ | ||
$this->assertInstanceOf( | ||
SealboxService::class, | ||
$this->app->make(SealboxCryptoInterface::class) | ||
); | ||
} | ||
|
||
public function testDefaultSealboxCanEncryptAndDecrypt(): void | ||
{ | ||
$sealbox = $this->app->make(SealboxCryptoInterface::class); | ||
|
||
$encrypted = $sealbox->encrypt('foobar'); | ||
$this->assertEquals('foobar', $sealbox->decrypt($encrypted)); | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace MinVWS\Crypto\Laravel\Tests; | ||
|
||
use MinVWS\Crypto\Laravel\CryptoServiceProvider; | ||
use Orchestra\Testbench\TestCase as OrchestraTestCase; | ||
|
||
abstract class TestCase extends OrchestraTestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
// additional setup | ||
} | ||
|
||
protected function getPackageProviders($app): array | ||
{ | ||
return [ | ||
CryptoServiceProvider::class, | ||
]; | ||
} | ||
|
||
protected function getEnvironmentSetUp($app): void | ||
{ | ||
// Set sealbox keys | ||
[$publicKey, $secretKey] = $this->generateSodiumKeys(); | ||
config()->set('crypto.sealbox.recipient_public_key', $publicKey); | ||
config()->set('crypto.sealbox.private_key', $secretKey); | ||
} | ||
|
||
protected function generateSodiumKeys(): array | ||
{ | ||
$keypair = sodium_crypto_box_keypair(); | ||
|
||
return [ | ||
base64_encode(sodium_crypto_box_publickey($keypair)), | ||
base64_encode(sodium_crypto_box_secretkey($keypair)), | ||
]; | ||
} | ||
} |