2021-05-13 13:27:13 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
2018-08-07 00:47:51 +00:00
|
|
|
import pytest_twisted
|
2018-07-27 03:02:57 +00:00
|
|
|
import requests
|
|
|
|
from cryptography.hazmat.primitives import serialization
|
2018-08-07 00:47:51 +00:00
|
|
|
from twisted.internet import threads
|
|
|
|
|
2018-09-12 11:58:13 +00:00
|
|
|
from nucypher.characters.lawful import Ursula
|
2018-07-27 03:02:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest_twisted.inlineCallbacks
|
2023-05-24 15:55:23 +00:00
|
|
|
def test_nodes_connect_via_tls_and_verify(
|
|
|
|
lonely_ursula_maker, test_registry_source_manager
|
|
|
|
):
|
2020-06-26 02:29:03 +00:00
|
|
|
node = lonely_ursula_maker(quantity=1).pop()
|
2018-07-27 03:02:57 +00:00
|
|
|
node_deployer = node.get_deployer()
|
|
|
|
|
|
|
|
node_deployer.addServices()
|
|
|
|
node_deployer.catalogServers(node_deployer.hendrix)
|
|
|
|
node_deployer.start()
|
|
|
|
|
|
|
|
cert = node_deployer.cert.to_cryptography()
|
|
|
|
cert_bytes = cert.public_bytes(serialization.Encoding.PEM)
|
|
|
|
|
|
|
|
def check_node_with_cert(node, cert_file):
|
|
|
|
response = requests.get("https://{}/public_information".format(node.rest_url()), verify=cert_file)
|
2021-10-11 23:41:35 +00:00
|
|
|
ursula = Ursula.from_metadata_bytes(response.content)
|
2018-07-27 03:02:57 +00:00
|
|
|
assert ursula == node
|
|
|
|
|
|
|
|
try:
|
|
|
|
with open("test-cert", "wb") as f:
|
|
|
|
f.write(cert_bytes)
|
|
|
|
yield threads.deferToThread(check_node_with_cert, node, "test-cert")
|
|
|
|
finally:
|
2021-05-12 12:38:43 +00:00
|
|
|
Path("test-cert").unlink()
|