From e4efcb36225ad17c114a1db4bcaf1f3c9126e075 Mon Sep 17 00:00:00 2001 From: Lagovas Date: Thu, 18 Jan 2018 13:33:39 +0200 Subject: [PATCH] test that length of encrypted data == length of raw data (#282) * test that length of encrypted data == length of raw data * fix test for php --- tests/phpthemis/scell_test.php | 2 ++ tests/pythemis/test_scell.py | 2 ++ tests/themis/themis_secure_cell.c | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/tests/phpthemis/scell_test.php b/tests/phpthemis/scell_test.php index 9092cf523..b01309511 100644 --- a/tests/phpthemis/scell_test.php +++ b/tests/phpthemis/scell_test.php @@ -100,6 +100,7 @@ public function testTokenProtectWithContext($key, $message, $context, $iscorrect $this->setExpectedException('Exception'); } $encrypted_message = phpthemis_scell_token_protect_encrypt($key, $message, $context); + $this->assertEquals(strlen($encrypted_message["encrypted_message"]), strlen($message)); $decrypted_message = phpthemis_scell_token_protect_decrypt($key, $encrypted_message['encrypted_message'], $encrypted_message['token'], $context); $this->assertEquals($decrypted_message, $message); } @@ -165,6 +166,7 @@ public function testTokenProtectWithoutContext($key, $message, $iscorrect){ $this->setExpectedException('Exception'); } $encrypted_message = phpthemis_scell_token_protect_encrypt($key, $message); + $this->assertEquals(strlen($encrypted_message["encrypted_message"]), strlen($message)); $decrypted_message = phpthemis_scell_token_protect_decrypt($key, $encrypted_message['encrypted_message'], $encrypted_message['token']); $this->assertEquals($decrypted_message, $message); } diff --git a/tests/pythemis/test_scell.py b/tests/pythemis/test_scell.py index b8d8c4cc6..d34bbe91e 100644 --- a/tests/pythemis/test_scell.py +++ b/tests/pythemis/test_scell.py @@ -101,6 +101,7 @@ def test_encrypt_decrypt(self): scell2 = SCellTokenProtect(self.key) scell3 = SCellTokenProtect(self.incorrect_key) encrypted, token = scell1.encrypt(self.data) + self.assertEqual(len(self.data), len(encrypted)) self.assertEqual(self.data, scell2.decrypt(encrypted, token)) with self.assertRaises(ThemisError): @@ -114,6 +115,7 @@ def test_encrypt_decrypt_context(self): scell2 = SCellTokenProtect(self.key) scell3 = SCellTokenProtect(self.incorrect_key) encrypted, token = scell1.encrypt(self.data, self.context) + self.assertEqual(len(self.data), len(encrypted)) self.assertEqual(self.data, scell2.decrypt(encrypted, token, self.context)) diff --git a/tests/themis/themis_secure_cell.c b/tests/themis/themis_secure_cell.c index a4ffd60af..3c3176548 100644 --- a/tests/themis/themis_secure_cell.c +++ b/tests/themis/themis_secure_cell.c @@ -87,6 +87,10 @@ static int secure_cell_token_protect(){ testsuite_fail_if(true, "themis_secure_cell_encrypt_token_protect (encrypted_message_length determination) fail"); return -1; } + if(encrypted_message_length != sizeof(message)){ + testsuite_fail_if(true, "themis_secure_cell_encrypt_token_protect (encrypted_message_length != message length) fail"); + return -1; + } encrypted_message=malloc(encrypted_message_length); if(encrypted_message==NULL){ testsuite_fail_if(true, "encrypted_message malloc fail"); @@ -105,6 +109,12 @@ static int secure_cell_token_protect(){ free(context); return -3; } + if(encrypted_message_length != sizeof(message)){ + testsuite_fail_if(true, "themis_secure_cell_encrypt_token_protect (encrypted_message_length != message length) fail"); + free(encrypted_message); + free(context); + return -3; + } uint8_t* decrypted_message; size_t decrypted_message_length=0;