-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyspamsteg_tests.py
96 lines (77 loc) · 3.28 KB
/
pyspamsteg_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: kyle isom <coder@kyleisom.net>
# license: ISC / public domain dual license
#
# tests for python spam steganography
import pyspamsteg
import unittest
test_ct00 = 'zero one one zero one zero zero zero '
test_ct00 += 'zero one one zero one zero zero one'
test_pt00 = 'hi'
test_ct01 = 'message header\nsecondary message\n\n' + test_ct00
test_pt01 = 'hi'
test_ct02 = 'this is not a valid hidden message'
class PySpamStegTests(unittest.TestCase):
def test_valid_decode(self):
"""
Test to ensure the decoding of messages works. Decoding is the process of
taking the binary-encoded words and transforming them into a character
sequence. No encryption is used here.
"""
self.assertEqual(pyspamsteg.decode(test_ct00), test_pt00)
def test_valid_read(self):
"""
Test case to ensure that a message can be read properly. This implicitly
tests the decode function as well. This tests just the read and decode
functions without testing the cipher suite.
"""
self.assertEqual(pyspamsteg.read(test_ct01), test_pt01)
def test_invalid_read(self):
"""
Test case to ensure proper handling of improperly-formatted messages. Does not
use the cipher suite.
"""
self.assertEqual(pyspamsteg.read(test_ct02), None)
def test_valid_encode(self):
"""
Test case to verify the proper encoding of messages: taking a character
sequence and converting that to binary-encoded words. Does not use encryption.
"""
message = pyspamsteg.encode(test_pt00)
self.assertEqual(pyspamsteg.decode(message), test_pt00)
def test_valid_message_build(self):
"""
Test case for the build function. Build is the opposite of read, and the output
is a properly-formatted message body. Does not use encryption.
"""
message = pyspamsteg.create(test_pt00)
self.assertEqual(pyspamsteg.read(message), test_pt00)
def test_build(self):
"""
Test case to verify proper build and read of a steganograpic message with
PlayFair encryption.
"""
message = 'testing pyspamsteg'
passphrase = 'pyspamsteg'
ct = pyspamsteg.create( message, passphrase )
pt = pyspamsteg.read( ct, passphrase )
self.assertEquals( pt, message )
def test_steg_vector(self):
"""
Test case validating the test vector from the site. Uses PlayFair encryption.
"""
expected_pt = 'Programming Praxis'
passphrase = "President Obama's visit to a Chrysler plant in Toledo, "
passphrase += "Ohio, on Friday was the culmination of a campaign to "
passphrase += "portray the auto bailouts as a brilliant success with "
passphrase += "no unpleasant side effects."
vector = open('tests/spam_example_vector').read()
pyspamsteg.set_charsize( 7 )
pt = pyspamsteg.read( vector, passphrase )
self.assertEquals( pt, expected_pt )
if __name__ == '__main__':
suite = unittest.TestSuite()
loader = unittest.TestLoader()
suite.addTests(loader.loadTestsFromTestCase(PySpamStegTests))
unittest.TextTestRunner(verbosity = 2).run(suite)