mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
Introduce RSA test class
The "@expectedException UnexpectedValueException" was just wrong here.
This commit is contained in:
parent
d8ed59814f
commit
46d8124908
49
test/php/library/Icinga/Crypt/RSATest.php
Normal file
49
test/php/library/Icinga/Crypt/RSATest.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// Icinga Web 2 | (c) 2020 Icinga Development Team | GPLv2+
|
||||
|
||||
namespace Tests\Icinga\Crypt;
|
||||
|
||||
use Icinga\Crypt\RSA;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use InvalidArgumentException;
|
||||
use UnexpectedValueException;
|
||||
|
||||
class RSATest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
function testLoadKeyThrowsExceptionIfMoreThanTwoKeysGiven()
|
||||
{
|
||||
(new RSA())->loadKey('one', 'two', 'three');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException UnexpectedValueException
|
||||
*/
|
||||
function testGetPublicKeyThrowsExceptionIfNoPublicKeySet()
|
||||
{
|
||||
(new RSA())->getPublicKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException UnexpectedValueException
|
||||
*/
|
||||
function testGetPrivateKeyThrowsExceptionIfNoPrivateKeySet()
|
||||
{
|
||||
(new RSA())->getPrivateKey();
|
||||
}
|
||||
|
||||
function testLoadKeyAutomaticallyDetectsThePublicAndPrivateKey()
|
||||
{
|
||||
list($privateKey, $publicKey) = RSA::keygen();
|
||||
|
||||
$rsa = (new RSA())->loadKey($publicKey, $privateKey);
|
||||
$this->assertSame($privateKey, $rsa->getPrivateKey());
|
||||
$this->assertSame($publicKey, $rsa->getPublicKey());
|
||||
|
||||
$rsa = (new RSA())->loadKey($privateKey, $publicKey);
|
||||
$this->assertSame($privateKey, $rsa->getPrivateKey());
|
||||
$this->assertSame($publicKey, $rsa->getPublicKey());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user