diff --git a/s3tests/functional/test_fuzzer.py b/s3tests/functional/test_fuzzer.py index 089d52b..dabdbee 100644 --- a/s3tests/functional/test_fuzzer.py +++ b/s3tests/functional/test_fuzzer.py @@ -101,7 +101,13 @@ def test_SpecialVariables_dict(): tester = SpecialVariables(testdict, prng) eq(tester['foo'], 'bar') - eq(tester['random 10-15 printable'], '[/pNI$;92@') #FIXME: how should I test pseudorandom content? + eq(tester['random 10-15 printable'], '[/pNI$;92@') + +def test_SpecialVariables_binary(): + prng = random.Random(1) + tester = SpecialVariables({}, prng) + + eq(tester['random 10-15 binary'], '\xdfj\xf1\xd80>a\xcd\xc4\xbb') def test_assemble_decision(): graph = build_graph() @@ -154,7 +160,7 @@ def test_expand_decision(): eq(request['key1'], 'value1') eq(request['indirect_key1'], 'value1') eq(request['path'], '/my-readable-bucket') - eq(request['randkey'], 'value-NI$;92@H/0I') #FIXME: again, how to handle the pseudorandom content? + eq(request['randkey'], 'value-NI$;92@H/0I') assert_raises(KeyError, lambda x: decision[x], 'key3') def test_weighted_choices(): diff --git a/s3tests/fuzz_headers.py b/s3tests/fuzz_headers.py index 91356f8..64245ec 100644 --- a/s3tests/fuzz_headers.py +++ b/s3tests/fuzz_headers.py @@ -7,6 +7,7 @@ import traceback import itertools import random import string +import struct import yaml import sys @@ -82,6 +83,7 @@ def expand_key(decision, key): class SpecialVariables(dict): charsets = { + 'binary': 'binary', 'printable': string.printable, 'punctuation': string.punctuation, 'whitespace': string.whitespace @@ -116,7 +118,13 @@ class SpecialVariables(dict): charset = self.charsets['printable'] length = self.prng.randint(size_min, size_max) - return ''.join([self.prng.choice(charset) for _ in xrange(length)]) # Won't scale nicely + if charset is 'binary': + num_bytes = length + 8 + tmplist = [self.prng.getrandbits(64) for _ in xrange(num_bytes / 8)] + tmpstring = struct.pack((num_bytes / 8) * 'Q', *tmplist) + return tmpstring[0:length] + else: + return ''.join([self.prng.choice(charset) for _ in xrange(length)]) # Won't scale nicely; won't do binary