diff --git a/test/php/library/Icinga/Crypt/RSATest.php b/test/php/library/Icinga/Crypt/RSATest.php new file mode 100644 index 000000000..5c3c6b3d0 --- /dev/null +++ b/test/php/library/Icinga/Crypt/RSATest.php @@ -0,0 +1,49 @@ +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()); + } +}