From c43955573bd9c278a0d1ff28544eefb68fb4f2a4 Mon Sep 17 00:00:00 2001 From: meejah Date: Sun, 4 Oct 2020 20:40:26 -0600 Subject: [PATCH] more gridmanager tests --- integration/test_grid_manager.py | 36 +++++++++++++++++++++++- integration/test_servers_of_happiness.py | 3 +- integration/util.py | 5 +++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/integration/test_grid_manager.py b/integration/test_grid_manager.py index dca403d1d..d701172f4 100644 --- a/integration/test_grid_manager.py +++ b/integration/test_grid_manager.py @@ -5,6 +5,11 @@ import shutil from os import mkdir, unlink, listdir, utime from os.path import join, exists, getmtime +from cryptography.hazmat.primitives.serialization import ( + Encoding, + PublicFormat, +) + from allmydata.crypto import ed25519 from allmydata.util import base32 from allmydata.util import configutil @@ -177,4 +182,33 @@ def test_reject_storage_server(reactor, request, temp_dir, flog_gatherer, port_a ) assert False, "Should get a failure" except util.ProcessFailed as e: - assert 'UploadUnhappinessError' in e.output.getvalue() + assert 'UploadUnhappinessError' in e.output + + +@pytest_twisted.inlineCallbacks +def test_identity(reactor, request, temp_dir): + """ + Dump public key to CLI + """ + gm_config = join(temp_dir, "test_identity") + yield util.run_tahoe( + reactor, request, "grid-manager", "--config", gm_config, "create", + ) + + # ask the CLI for the grid-manager pubkey + pubkey = yield util.run_tahoe( + reactor, request, "grid-manager", "--config", gm_config, "public-identity", + ) + alleged_pubkey = ed25519.verifying_key_from_string(pubkey.strip()) + + # load the grid-manager pubkey "ourselves" + with open(join(gm_config, "config.json"), "r") as f: + real_config = json.load(f) + real_privkey, real_pubkey = ed25519.signing_keypair_from_string( + real_config["private_key"].encode("ascii"), + ) + + # confirm the CLI told us the correct thing + alleged_bytes = alleged_pubkey.public_bytes(Encoding.Raw, PublicFormat.Raw) + real_bytes = real_pubkey.public_bytes(Encoding.Raw, PublicFormat.Raw) + assert alleged_bytes == real_bytes, "Keys don't match" diff --git a/integration/test_servers_of_happiness.py b/integration/test_servers_of_happiness.py index fd8f75e39..dd0b3e32f 100644 --- a/integration/test_servers_of_happiness.py +++ b/integration/test_servers_of_happiness.py @@ -42,5 +42,4 @@ def test_upload_immutable(reactor, temp_dir, introducer_furl, flog_gatherer, sto except util.ProcessFailed as e: assert "UploadUnhappinessError" in e.output.getvalue() - output = proto.output.getvalue() - assert "shares could be placed on only" in output + assert "shares could be placed on only" in proto.output diff --git a/integration/util.py b/integration/util.py index 72689d387..5cad59c12 100644 --- a/integration/util.py +++ b/integration/util.py @@ -49,6 +49,9 @@ class ProcessFailed(Exception): self.reason = reason self.output = output + def __str__(self): + return ":\n{}".format(self.reason, self.output) + class _CollectOutputProtocol(ProcessProtocol): """ @@ -72,7 +75,7 @@ class _CollectOutputProtocol(ProcessProtocol): def processExited(self, reason): if not isinstance(reason.value, ProcessDone): - self.done.errback(ProcessFailed(reason, self.output)) + self.done.errback(ProcessFailed(reason, self.output.getvalue())) def outReceived(self, data): self.output.write(data)