add some integration tests

This commit is contained in:
meejah 2018-11-28 01:06:53 -07:00
parent 43b446bacf
commit 85142acf97
2 changed files with 82 additions and 1 deletions

View File

@ -0,0 +1,62 @@
import sys
import time
import json
import shutil
from os import mkdir, unlink, listdir, utime
from os.path import join, exists, getmtime
from allmydata.util import keyutil
from allmydata.util import base32
import util
import pytest
@pytest.inlineCallbacks
def test_create_certificate(reactor):
gm_config = yield util.run_tahoe(
reactor, "grid-manager", "--config", "-", "create",
)
privkey_bytes = json.loads(gm_config)['private_key'].encode('ascii')
privkey, pubkey_bytes = keyutil.parse_privkey(privkey_bytes)
pubkey = keyutil.parse_pubkey(pubkey_bytes)
gm_config = yield util.run_tahoe(
reactor, "grid-manager", "--config", "-", "add",
"alice", "pub-v0-kzug3ut2m7ziihf3ndpqlquuxeie4foyl36wn54myqc4wmiwe4ga",
stdin=gm_config,
)
alice_cert_bytes = yield util.run_tahoe(
reactor, "grid-manager", "--config", "-", "sign", "alice",
stdin=gm_config,
)
alice_cert = json.loads(alice_cert_bytes)
# confirm that alice's certificate is made by the Grid Manager
assert pubkey.verify(
base32.a2b(alice_cert['signature'].encode('ascii')),
alice_cert['certificate'].encode('ascii'),
)
@pytest.inlineCallbacks
def test_remove_client(reactor):
gm_config = yield util.run_tahoe(
reactor, "grid-manager", "--config", "-", "create",
)
gm_config = yield util.run_tahoe(
reactor, "grid-manager", "--config", "-", "add",
"alice", "pub-v0-kzug3ut2m7ziihf3ndpqlquuxeie4foyl36wn54myqc4wmiwe4ga",
stdin=gm_config,
)
assert json.loads(gm_config)['storage_servers'].has_key("alice")
gm_config = yield util.run_tahoe(
reactor, "grid-manager", "--config", "-", "remove",
"alice",
stdin=gm_config,
)
# there are no storage servers left at all now
assert not json.loads(gm_config).has_key('storage_servers')

View File

@ -37,9 +37,15 @@ class _CollectOutputProtocol(ProcessProtocol):
self.output, and callback's on done with all of it after the
process exits (for any reason).
"""
def __init__(self):
def __init__(self, stdin=None):
self.done = Deferred()
self.output = StringIO()
self._stdin = stdin
def connectionMade(self):
if self._stdin is not None:
self.transport.write(self._stdin)
self.transport.closeStdin()
def processEnded(self, reason):
if not self.done.called:
@ -126,6 +132,19 @@ def _cleanup_twistd_process(twistd_process, exited):
pass
def run_tahoe(reactor, *args, **kwargs):
stdin = kwargs.get('stdin', None)
protocol = _CollectOutputProtocol(stdin=stdin)
process = reactor.spawnProcess(
protocol,
sys.executable,
(sys.executable, '-m', 'allmydata.scripts.runner') + args
)
process.exited = protocol.done
return protocol.done
def _run_node(reactor, node_dir, request, magic_text):
if magic_text is None:
magic_text = "client running"