From f5d4a4ca41614c745c8cf7e9d339eabfc5472c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bonhomme?= Date: Tue, 17 May 2016 09:59:12 +0200 Subject: [PATCH] Added tests for exifHeader module. The reveal function of the exifHeader module now returns the result instead of simply printing the clear message. --- stegano/exifHeader.py | 16 +++++----- tests/test_exifHeader.py | 66 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 tests/test_exifHeader.py diff --git a/stegano/exifHeader.py b/stegano/exifHeader.py index 26e59fd..9c349ca 100644 --- a/stegano/exifHeader.py +++ b/stegano/exifHeader.py @@ -21,7 +21,7 @@ __author__ = "Cedric Bonhomme" __version__ = "$Revision: 0.2 $" -__date__ = "$Date: 2016/04/17 $" +__date__ = "$Date: 2016/05/17 $" __license__ = "GPLv3" # Thanks to: http://www.julesberman.info/spec2img.htm @@ -40,13 +40,10 @@ def hide(img, img_enc, copyright="https://github.com/cedricbonhomme/Stegano", \ if secret_file != None: with open(secret_file, "r") as f: secret_file_content = f.read() - text = "\nImage annotation date: " - text = text + str(datetime.date.today()) - text = text + "\nImage description:\n" if secret_file != None: - text = compress(b64encode(text + secret_file_content)) + text = compress(b64encode(secret_file_content)) else: - text = compress(b64encode(text + secret_message)) + text = compress(b64encode(secret_message)) try: shutil.copy(img, img_enc) @@ -73,9 +70,10 @@ def reveal(img): except: print("Impossible to read description.") return - print((b64decode(decompress(g.imageDescription())))) - print(("\nCopyright " + g.copyright())) - #print g.dateTimeOriginal()s + return b64decode(decompress(g.imageDescription())) + #print((b64decode(decompress(g.imageDescription())))) + #print(("\nCopyright " + g.copyright())) + #print g.dateTimeOriginal() if __name__ == "__main__": diff --git a/tests/test_exifHeader.py b/tests/test_exifHeader.py new file mode 100644 index 0000000..66007e6 --- /dev/null +++ b/tests/test_exifHeader.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python +#-*- coding: utf-8 -*- + +# Stéganô - Stéganô is a basic Python Steganography module. +# Copyright (C) 2010-2016 Cédric Bonhomme - https://www.cedricbonhomme.org +# +# For more information : https://github.com/cedricbonhomme/Stegano +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see + +__author__ = "Cedric Bonhomme" +__version__ = "$Revision: 0.1 $" +__date__ = "$Date: 2016/05/17 $" +__license__ = "GPLv3" + +import os +import unittest + +from stegano import exifHeader + +class TestEXIFHeader(unittest.TestCase): + + def test_hide_empty_message(self): + """ + Test hiding the empty string. + """ + secret = exifHeader.hide("./examples/pictures/Elisha-Cuthbert.jpg", + "./image.png", copyright="", secret_message="") + #secret.save(""./image.png"") + + clear_message = exifHeader.reveal("./image.png") + #print(clear_message) + self.assertEqual("", clear_message) + + def test_hide_and_reveal(self): + messages_to_hide = ["a", "foo", "Hello World!", ":Python:"] + + for message in messages_to_hide: + secret = exifHeader.hide("./examples/pictures/Elisha-Cuthbert.jpg", + "./image.png", copyright="", + secret_message=message) + + clear_message = exifHeader.reveal("./image.png") + + self.assertEqual(message, clear_message) + + def tearDown(self): + try: + os.unlink("./image.png") + except: + pass + + +if __name__ == '__main__': + unittest.main()