]> git-server-git.apps.pok.os.sepia.ceph.com Git - s3-tests.git/commitdiff
S3 Fuzzer: Added binary mode to random data generator
authorKyle Marsh <kyle.marsh@dreamhost.com>
Wed, 10 Aug 2011 21:39:25 +0000 (14:39 -0700)
committerKyle Marsh <kyle.marsh@dreamhost.com>
Mon, 12 Sep 2011 19:53:18 +0000 (12:53 -0700)
s3tests/functional/test_fuzzer.py
s3tests/fuzz_headers.py

index 089d52b7db4c4a40a6da6d6e9bd155ae3c32a5de..dabdbee86e7d7b81fa699c7006651d54e29637c0 100644 (file)
@@ -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():
index 91356f81254cfbd542fb1d646555749f2fec5cde..64245ec3940e658b9ad35e69c537fc6933ea074e 100644 (file)
@@ -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