Adds failing message kit serialization test

pull/775/head
Kieran R. Prasch 2019-02-16 11:59:21 -07:00
parent e7da2240eb
commit a1e1e39168
2 changed files with 30 additions and 0 deletions

View File

@ -4,9 +4,12 @@ from base64 import b64encode, b64decode
import maya import maya
import nucypher
from nucypher.characters.lawful import Enrico
from nucypher.crypto.kits import UmbralMessageKit from nucypher.crypto.kits import UmbralMessageKit
from nucypher.crypto.powers import DecryptingPower from nucypher.crypto.powers import DecryptingPower
from nucypher.policy.models import TreasureMap from nucypher.policy.models import TreasureMap
from nucypher.utilities.sandbox.policy import generate_random_label
def test_alice_character_control_create_policy(alice_control_test_client, federated_bob): def test_alice_character_control_create_policy(alice_control_test_client, federated_bob):
@ -227,3 +230,5 @@ def test_character_control_lifecycle(alice_control_test_client,
for plaintext in bob_response_data['result']['plaintext']: for plaintext in bob_response_data['result']['plaintext']:
plaintext_bytes = b64decode(plaintext) plaintext_bytes = b64decode(plaintext)
assert plaintext_bytes == b"I'm bereaved, not a sap!" assert plaintext_bytes == b"I'm bereaved, not a sap!"

View File

@ -17,7 +17,9 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
import pytest import pytest
from bytestring_splitter import BytestringSplitter, BytestringSplittingError from bytestring_splitter import BytestringSplitter, BytestringSplittingError
from nucypher.characters.lawful import Enrico
from nucypher.crypto.api import secure_random from nucypher.crypto.api import secure_random
from nucypher.crypto.kits import UmbralMessageKit
from nucypher.crypto.signing import Signature from nucypher.crypto.signing import Signature
@ -51,3 +53,26 @@ def test_trying_to_extract_too_many_bytes_raises_typeerror():
with pytest.raises(BytestringSplittingError): with pytest.raises(BytestringSplittingError):
rebuilt_signature, rebuilt_bytes = splitter(signature + some_bytes, return_remainder=True) rebuilt_signature, rebuilt_bytes = splitter(signature + some_bytes, return_remainder=True)
def test_message_kit_serialization_via_enrico(enacted_federated_policy, federated_alice):
# Enrico
enrico = Enrico.from_alice(federated_alice, label=enacted_federated_policy.label)
# Plaintext
message = 'this is a message'
plaintext_bytes = bytes(message, encoding='utf-8')
# Create
message_kit, signature = enrico.encrypt_message(message=plaintext_bytes)
# Serialize
message_kit_bytes = bytes(message_kit)
# Deserialize
the_same_message_kit = UmbralMessageKit.from_bytes(message_kit_bytes)
# Confirm
assert message_kit == the_same_message_kit