mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-25 05:19:53 +00:00
Add a direct unit test for FileHandle.get_encryption_key
This commit is contained in:
parent
cd06f1c902
commit
11e4bcf476
@ -14,6 +14,9 @@ if PY2:
|
|||||||
|
|
||||||
import os, shutil
|
import os, shutil
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from base64 import (
|
||||||
|
b64encode,
|
||||||
|
)
|
||||||
|
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
from twisted.python.failure import Failure
|
from twisted.python.failure import Failure
|
||||||
@ -877,6 +880,34 @@ def is_happy_enough(servertoshnums, h, k):
|
|||||||
return True
|
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,
|
class EncodingParameters(GridTestMixin, unittest.TestCase, SetDEPMixin,
|
||||||
ShouldFailMixin):
|
ShouldFailMixin):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user