2018-11-04 19:23:11 +00:00
|
|
|
"""
|
|
|
|
This file is part of nucypher.
|
|
|
|
|
|
|
|
nucypher is free software: you can redistribute it and/or modify
|
2019-03-05 02:50:11 +00:00
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
2018-11-04 19:23:11 +00:00
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
nucypher is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-03-05 02:50:11 +00:00
|
|
|
GNU Affero General Public License for more details.
|
2018-11-04 19:23:11 +00:00
|
|
|
|
2019-03-05 02:50:11 +00:00
|
|
|
You should have received a copy of the GNU Affero General Public License
|
2018-11-04 19:23:11 +00:00
|
|
|
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
"""
|
2020-05-23 00:02:00 +00:00
|
|
|
|
|
|
|
|
2018-07-27 03:02:57 +00:00
|
|
|
import os
|
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
|
2020-05-13 03:21:15 +00:00
|
|
|
from tests.utils.ursula import make_federated_ursulas
|
2018-07-27 03:02:57 +00:00
|
|
|
|
|
|
|
|
2018-07-02 12:18:31 +00:00
|
|
|
def test_alice_enacts_policies_in_policy_group_via_rest(enacted_federated_policy):
|
2017-12-01 20:54:33 +00:00
|
|
|
"""
|
|
|
|
Now that Alice has made a PolicyGroup, she can enact its policies, using Ursula's Public Key to encrypt each offer
|
|
|
|
and transmitting them via REST.
|
|
|
|
"""
|
2018-07-12 06:13:44 +00:00
|
|
|
arrangement = list(enacted_federated_policy._accepted_arrangements)[0]
|
|
|
|
ursula = arrangement.ursula
|
|
|
|
policy_arrangement = ursula.datastore.get_policy_arrangement(arrangement.id.hex().encode())
|
2020-06-25 03:26:01 +00:00
|
|
|
with ursula.datastore(PolicyArrangement, arrangement.id.hex()) as policy_arrangement:
|
|
|
|
the_kfrag = policy_arrangement.kfrag
|
|
|
|
assert bool(the_kfrag) # TODO: This can be a more poignant assertion.
|
2018-07-27 03:02:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest_twisted.inlineCallbacks
|
2018-09-17 21:14:11 +00:00
|
|
|
def test_federated_nodes_connect_via_tls_and_verify(ursula_federated_test_config):
|
2018-09-19 21:20:12 +00:00
|
|
|
node = make_federated_ursulas(ursula_config=ursula_federated_test_config, 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)
|
2019-12-23 22:29:15 +00:00
|
|
|
ursula = Ursula.from_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:
|
|
|
|
os.remove("test-cert")
|