Skip to content

Commit

Permalink
Add nosetests based test suite.
Browse files Browse the repository at this point in the history
Covers everything except for flow, which is due for refactoring.
  • Loading branch information
iksteen committed Mar 21, 2015
1 parent 92605de commit 96329fa
Show file tree
Hide file tree
Showing 7 changed files with 626 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import pwny


def setup():
pwny.target.assume(pwny.Target(arch=pwny.Architecture.x86))
50 changes: 50 additions & 0 deletions tests/test_asm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from nose.tools import raises
import pwny


SOURCE = 'mov al, [0xced]'
RESULT_BIN_32 = b'\xa0\xed\x0c\x00\x00'
RESULT_BIN_64 = b'\x8a\x04%\xed\x0c\x00\x00'
RESULT_ITH_32 = b':05000000A0ED0C000062\n:00000001FF\n'
RESULT_ITH_64 = b':070000008A0425ED0C00004D\n:00000001FF\n'


def test_asm():
if pwny.target.bits == 32:
assert pwny.asm(SOURCE) == RESULT_BIN_32
else:
assert pwny.asm(SOURCE) == RESULT_BIN_64


def test_asm_with_bits():
assert pwny.asm(SOURCE, bits=32) == RESULT_BIN_32
assert pwny.asm(SOURCE, bits=64) == RESULT_BIN_64


def test_asm_with_target():
target_32 = pwny.Target(arch=pwny.Architecture.x86)
target_64 = pwny.Target(arch=pwny.Architecture.x86_64)
assert pwny.asm(SOURCE, target=target_32) == RESULT_BIN_32
assert pwny.asm(SOURCE, target=target_64) == RESULT_BIN_64


def test_asm_with_bits_and_target():
target_32 = pwny.Target(arch=pwny.Architecture.x86)
target_64 = pwny.Target(arch=pwny.Architecture.x86_64)
assert pwny.asm(SOURCE, bits=32, target=target_64) == RESULT_BIN_32
assert pwny.asm(SOURCE, bits=64, target=target_32) == RESULT_BIN_64


def test_asm_with_format():
assert pwny.asm(SOURCE, fmt=pwny.asm.Format.ith, bits=32) == RESULT_ITH_32
assert pwny.asm(SOURCE, fmt=pwny.asm.Format.ith, bits=64) == RESULT_ITH_64


@raises(ValueError)
def test_asm_invalid_format():
pwny.asm(SOURCE, fmt='ced')


@raises(SyntaxError)
def test_asm_syntax_error():
pwny.asm('mov ced, 3')
38 changes: 38 additions & 0 deletions tests/test_codec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pwny


def test_xor_int():
assert pwny.xor(61, b'fooo') == b'[RRR'


def test_xor_str():
assert pwny.xor(b'abcd', b'fooo') == b'\x07\r\x0c\x0b'
assert pwny.xor(b'abcd', b'fooofooo') == b'\x07\r\x0c\x0b\x07\r\x0c\x0b'


def test_rot13():
assert pwny.rot13('whax') == 'junk'


def test_caesar():
assert pwny.caesar(1, 'abcXYZ') == 'bcdYZA'


def test_enhex():
assert pwny.enhex(b'ABCD') == '41424344'


def test_dehex():
assert pwny.dehex('41424344') == b'ABCD'


def test_enb64():
assert pwny.enb64(b'ABCD') == 'QUJDRA=='


def test_deb64():
assert pwny.deb64('QUJDRA==') == b'ABCD'


def test_frequency():
assert pwny.frequency('ABCD') == {'A': 1, 'B': 1, 'C': 1, 'D': 1}
Loading

0 comments on commit 96329fa

Please sign in to comment.