|
| 1 | +import pytest |
1 | 2 | import logging |
2 | 3 | import os |
3 | 4 | import subprocess |
@@ -118,7 +119,9 @@ def test_grants( tmp_path ): |
118 | 119 |
|
119 | 120 | # We'll be loading an existing Client Agent keypair, so restrict it from registering a new one. |
120 | 121 | # 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. |
122 | 125 | machine_id_path = test.with_suffix( '' ) / "payments_test.machine-id" |
123 | 126 | reloader = reload( |
124 | 127 | author = author, |
@@ -173,3 +176,29 @@ def test_grants( tmp_path ): |
173 | 176 | "some-capability":10 |
174 | 177 | } |
175 | 178 | }""" |
| 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