From 3a0c9e97dd5afb07d6cfe1183c274ac07770e49a Mon Sep 17 00:00:00 2001 From: mle Date: Sun, 11 Nov 2018 19:22:15 +0100 Subject: [PATCH] test: + HaliteAdapterTest --- test/HaliteAdapterTest.php | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 test/HaliteAdapterTest.php diff --git a/test/HaliteAdapterTest.php b/test/HaliteAdapterTest.php new file mode 100644 index 0000000..713634b --- /dev/null +++ b/test/HaliteAdapterTest.php @@ -0,0 +1,68 @@ +assertNotEquals($priv1->getEncodedForm(), $priv2->getEncodedForm()); + + $pub1 = HaliteSigningPublicKey::fromPrivateKey($priv1); + $pub2 = HaliteSigningPublicKey::fromPrivateKey($priv2); + $this->assertNotEquals($pub1->getEncodedForm(), $pub2->getEncodedForm()); + + $pub11 = HaliteSigningPublicKey::fromPrivateKey($priv1); + $this->assertEquals ($pub1->getEncodedForm(), $pub11->getEncodedForm()); + + return $priv1; + } + + /** + * @depends testKeyGeneration + */ + public function testKeyEncoding(HaliteSigningPrivateKey $priv): void + { + $priv2 = new HaliteSigningPrivateKey($priv->getEncodedForm()); + $this->assertEquals($priv->getEncodedForm(), $priv2->getEncodedForm()); + + $pub = HaliteSigningPublicKey::fromPrivateKey($priv); + $pub2 = new HaliteSigningPublicKey($pub->getEncodedForm()); + $this->assertEquals($pub->getEncodedForm(), $pub2->getEncodedForm()); + } + + /** + * @dataProvider invalidKeyMaterial + * @depends testKeyEncoding + */ + public function testInvalidKeyEncoding(string $invalidKeyMaterial): void + { + $this->assertException([CryptoErrorException::class, InvalidArgumentException::class], function() use($invalidKeyMaterial) { + new HaliteSigningPrivateKey($invalidKeyMaterial); + }); + $this->assertException([CryptoErrorException::class, InvalidArgumentException::class], function() use($invalidKeyMaterial) { + new HaliteSigningPublicKey($invalidKeyMaterial); + }); + } + + // There's no need to test the other adapter methods any further + // because the PublicKeyMethodTest will make heavy use of them. + // Halite itself is well-tested. + +}