From f78c80d7aa6cec11afdafb5b289df3981ac128d1 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 6 Feb 2008 20:03:35 -0700 Subject: [PATCH] test_upload.py: add test to exercise CHK hashing variations --- src/allmydata/test/test_upload.py | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/allmydata/test/test_upload.py b/src/allmydata/test/test_upload.py index 1e135811..a1892311 100644 --- a/src/allmydata/test/test_upload.py +++ b/src/allmydata/test/test_upload.py @@ -8,6 +8,8 @@ from cStringIO import StringIO from allmydata import upload, encode, uri from allmydata.interfaces import IFileURI from allmydata.util.assertutil import precondition +from allmydata.util.deferredutil import DeferredListShouldSucceed +from allmydata.util import idlib from foolscap import eventual MiB = 1024*1024 @@ -440,6 +442,44 @@ class PeerSelection(unittest.TestCase): d.addCallback(_check) return d +class StorageIndex(unittest.TestCase): + def test_params_must_matter(self): + DATA = "I am some data" + u = upload.Data(DATA) + eu = upload.EncryptAnUploadable(u) + d1 = eu.get_storage_index() + + # CHK means the same data should encrypt the same way + u = upload.Data(DATA) + eu = upload.EncryptAnUploadable(u) + d1a = eu.get_storage_index() + + # but if we change the encoding parameters, it should be different + u = upload.Data(DATA) + u.encoding_param_k = u.default_encoding_param_k + 1 + eu = upload.EncryptAnUploadable(u) + d2 = eu.get_storage_index() + + # and if we use a random key, it should be different than the CHK + u = upload.Data(DATA, contenthashkey=False) + eu = upload.EncryptAnUploadable(u) + d3 = eu.get_storage_index() + # and different from another instance + u = upload.Data(DATA, contenthashkey=False) + eu = upload.EncryptAnUploadable(u) + d4 = eu.get_storage_index() + + d = DeferredListShouldSucceed([d1,d1a,d2,d3,d4]) + def _done(res): + si1, si1a, si2, si3, si4 = res + self.failUnlessEqual(si1, si1a) + self.failIfEqual(si1, si2) + self.failIfEqual(si1, si3) + self.failIfEqual(si1, si4) + self.failIfEqual(si3, si4) + d.addCallback(_done) + return d + # TODO: # upload with exactly 75 peers (shares_of_happiness) -- 2.45.2