Merge pull request #969 from LeastAuthority/3593.get_encryption_key-test

Add FileHandle.get_encryption_key test

Fixes: ticket:3593
This commit is contained in:
Jean-Paul Calderone 2021-02-07 07:41:44 -05:00 committed by GitHub
commit ab57746a85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

0
newsfragments/3593.minor Normal file
View File

View File

@ -888,6 +888,34 @@ def is_happy_enough(servertoshnums, h, k):
return True
class FileHandleTests(unittest.TestCase):
"""
Tests for ``FileHandle``.
"""
def test_get_encryption_key_convergent(self):
"""
When ``FileHandle`` is initialized with a convergence secret,
``FileHandle.get_encryption_key`` returns a deterministic result that
is a function of that secret.
"""
secret = b"\x42" * 16
handle = upload.FileHandle(BytesIO(b"hello world"), secret)
handle.set_default_encoding_parameters({
"k": 3,
"happy": 5,
"n": 10,
# Remember this is the *max* segment size. In reality, the data
# size is much smaller so the actual segment size incorporated
# into the encryption key is also smaller.
"max_segment_size": 128 * 1024,
})
self.assertEqual(
b64encode(self.successResultOf(handle.get_encryption_key())),
b"oBcuR/wKdCgCV2GKKXqiNg==",
)
class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
ShouldFailMixin):