From: Kyle Marsh Date: Wed, 10 Aug 2011 21:39:25 +0000 (-0700) Subject: S3 Fuzzer: Added binary mode to random data generator X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4737652fc1b08c1442e7c7792ee71bfe5aeee441;p=s3-tests.git S3 Fuzzer: Added binary mode to random data generator --- diff --git a/s3tests/functional/test_fuzzer.py b/s3tests/functional/test_fuzzer.py index 089d52b7..dabdbee8 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 91356f81..64245ec3 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