Update encrypt Tests

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5820 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2019-12-09 14:03:00 +00:00
parent 2aa98558b9
commit 47b3179f1d

View File

@@ -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");
}
}