From: Brian Warner Date: Thu, 7 Feb 2008 03:03:35 +0000 (-0700) Subject: test_upload.py: add test to exercise CHK hashing variations X-Git-Tag: allmydata-tahoe-0.8.0~112 X-Git-Url: https://git.rkrishnan.org/vdrive/components/com_hotproperty/css/?a=commitdiff_plain;h=f78c80d7aa6cec11afdafb5b289df3981ac128d1;p=tahoe-lafs%2Ftahoe-lafs.git test_upload.py: add test to exercise CHK hashing variations --- 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)