Add a tool for matching the node key in the announcement

And use it in the recently added test
This commit is contained in:
Jean-Paul Calderone 2019-06-14 15:48:28 -04:00
parent 212f96dfe7
commit 25287870ee
2 changed files with 34 additions and 4 deletions

View File

@ -2,7 +2,10 @@
Testtools-style matchers useful to the Tahoe-LAFS test suite.
"""
import attr
from testtools.matchers import (
Mismatch,
AfterPreprocessing,
MatchesStructure,
MatchesDict,
@ -17,9 +20,37 @@ from foolscap.furl import (
from allmydata.util import (
base32,
)
from allmydata.node import (
read_config,
)
from allmydata.crypto import (
ed25519,
error,
)
@attr.s
class MatchesNodePublicKey(object):
"""
Match an object representing the node's private key.
To verify, the private key is loaded from the node's private config
directory at the time the match is checked.
"""
basedir = attr.ib()
def match(self, other):
config = read_config(self.basedir, u"tub.port")
privkey_bytes = config.get_private_config("node.privkey")
private_key = ed25519.signing_keypair_from_string(privkey_bytes)[0]
signature = ed25519.sign_data(private_key, b"")
other_public_key = ed25519.verifying_key_from_signing_key(other)
try:
ed25519.verify_signature(other_public_key, signature, b"")
except error.BadSignature:
return Mismatch("The signature did not verify.")
def matches_anonymous_storage_announcement():
def matches_anonymous_storage_announcement(basedir):
"""
Match an anonymous storage announcement.
"""
@ -30,8 +61,7 @@ def matches_anonymous_storage_announcement():
"anonymous-storage-FURL": matches_furl(),
"permutation-seed-base32": matches_base32(),
}),
# Not sure what kind of assertion to make against the key
signing_key=Always(),
signing_key=MatchesNodePublicKey(basedir),
)

View File

@ -1122,7 +1122,7 @@ introducer.furl = pb://abcde@nowhere/fake
# Match the following list (of one element) ...
MatchesListwise([
# The only element in the list ...
matches_anonymous_storage_announcement(),
matches_anonymous_storage_announcement(self.basedir),
]),
)),
)