From 47b3179f1dee5754bc12342b321382f00753b880 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Mon, 9 Dec 2019 14:03:00 +0000 Subject: [PATCH] Update encrypt Tests git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5820 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- Tests/encryptTest.php | 98 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/Tests/encryptTest.php b/Tests/encryptTest.php index 8e660c3..25cd1fe 100644 --- a/Tests/encryptTest.php +++ b/Tests/encryptTest.php @@ -39,4 +39,102 @@ class encryptTest extends PHPUnit_Framework_TestCase $res = strpos ($token, "Text"); $this->assertSame ($res, false); } + + /** Encrypt : Invalid Cipher method + */ + public function testInvalidCypher1 () + { + $this->expectException ("Exception", + "Invalid cipher provided to encrypt method : doesn't exists in OpenSSL", + 500); + $encrypt = new encrypt (); + $payload = "TextToEncode"; + $token = $encrypt->encrypt ($payload, "123456789012345678901234", "TOTO"); + } + + /** Encrypt : Invalid Payload to encrypt + */ + public function testInvalidPayload () + { + $this->expectException ("Exception", + "Invalid payload provided to encrypt method : Not a string", + 500); + $encrypt = new encrypt (); + $payload = array ("Invalid"); + $token = $encrypt->encrypt ($payload, "123456789012345678901234"); + } + + /** Encrypt : Invalid Cipher Key to encrypt + */ + public function testInvalidCipherKey () + { + $this->expectException ("Exception", + "Invalid cipherKey provided to encrypt method : ". + "length different of 24 chars", 500); + $encrypt = new encrypt (); + $payload = "Payload"; + $token = $encrypt->encrypt ($payload, "124"); + } + + /** Decrypt : invalid cipher text + */ + public function testDecryptInvalidCipherKey () + { + $this->expectException ("Exception", + "Invalid cipherKey provided to decrypt method : ". + "length different of 24 chars", 500); + $encrypt = new encrypt (); + $token = $encrypt->decrypt ("zfz", "124"); + } + + /** Decrypt : empty cipher string + */ + public function testDecryptEmptyCipherString () + { + $this->expectException ("Exception", + "Invalid ciphertext provided to decrypt method : empty string", 500); + $encrypt = new encrypt (); + $token = $encrypt->decrypt ("", "124"); + } + + /** Decrypt : Not a string cypher + */ + public function testDecryptNotStringCipherString () + { + $this->expectException ("Exception", + "Invalid ciphertext provided to decrypt method : not a string", 500); + $encrypt = new encrypt (); + $token = $encrypt->decrypt (array (), "124"); + } + + /** Decrypt : Not a string cypher key + */ + public function testDecryptNotStringCipherKey () + { + $this->expectException ("Exception", + "Invalid cipherkey provided to decrypt method : not a string", 500); + $encrypt = new encrypt (); + $token = $encrypt->decrypt ("1224", array ()); + } + + /** Decrypt : Not a cipher method string + */ + public function testDecryptNotStringCipherMethod () + { + $this->expectException ("Exception", + "Invalid cipherMethod provided to decrypt method : not a string", 500); + $encrypt = new encrypt (); + $token = $encrypt->decrypt ("1224", "1234", array ()); + } + + /** Decrypt : Not a known cipher method + */ + public function testDecryptUnknownCipherMethod () + { + $this->expectException ("Exception", + "Invalid cipherMethod provided to decrypt method : ". + "doesn't exists in OpenSSL", 500); + $encrypt = new encrypt (); + $token = $encrypt->decrypt ("1224", "1234", "unknown"); + } }