Skip to content

Commit b851ead

Browse files
committed
Further License verification; work toward cleanly detecting failure
1 parent 6095474 commit b851ead

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ else
4141
endif
4242

4343
# To see all pytest output, uncomment --capture=no, ...
44-
PYTESTOPTS = --capture=no --log-cli-level=WARNING
44+
PYTESTOPTS = --capture=no --log-cli-level=INFO
4545

4646
PY3TEST = $(PY3) -m pytest $(PYTESTOPTS)
4747

slip39/invoice/payments_test.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
import logging
23
import os
34
import subprocess
@@ -118,7 +119,9 @@ def test_grants( tmp_path ):
118119

119120
# We'll be loading an existing Client Agent keypair, so restrict it from registering a new one.
120121
# It must try to load the Author's License (using the author.service as the basename), and then
121-
# attempt to sign and save an instance of it with the client Keypair.
122+
# attempt to sign and save an instance of it with the client Keypair. For this, we need access
123+
# to an Agent Keypair suitable for signing (access to decrypted private key); so we'll need the
124+
# credentials.
122125
machine_id_path = test.with_suffix( '' ) / "payments_test.machine-id"
123126
reloader = reload(
124127
author = author,
@@ -173,3 +176,29 @@ def test_grants( tmp_path ):
173176
"some-capability":10
174177
}
175178
}"""
179+
# TODO: confirm appropriate payment before issuing self-signed license.
180+
181+
# Now that we've got the self-signed License from Author, self-signed by Client, we can verify
182+
# the authenticity of the License without access to the private keys; only the public keys.
183+
ls = subprocess.run(
184+
[ 'ls', '-l', str( here ) ], stdout=subprocess.PIPE,
185+
)
186+
log.info( f"Test directory (post self-signed issuance):\n{ls.stdout.decode( 'UTF-8' )}\n\n" )
187+
188+
assert len( licenses ) == 1
189+
constraints = licenses[0].verify(
190+
author_pubkey = client.pubkey,
191+
confirm = False,
192+
machine_id_path = machine_id_path,
193+
)
194+
log.info( f"Verified self-signed License:\n{constraints}\n\n" )
195+
assert not constraints
196+
197+
# Later, we restore from backup and our Machine ID changes...
198+
assert len( licenses ) == 1
199+
with pytest.raises( licensing.LicenseIncompatibility ) as excinfo:
200+
constraints = licenses[0].verify(
201+
author_pubkey = client.pubkey,
202+
confirm = False,
203+
)
204+
assert "specifies Machine ID 00010203-0405-4607-8809-0a0b0c0d0e0f; found" in str( excinfo.value )

0 commit comments

Comments
 (0)