Cover reciprocal peer access and initialize the SFTP path
This commit is contained in:
1 parent
1223273fcb
commit
c29874fa60
3 files changed
+77
-3
No files matched your search
@@ -10,7 +10,15 @@ from django_otp import DEVICE_ID_SESSION_KEY
|
||||
from django_otp.plugins.otp_totp.models import TOTPDevice
|
||||
|
||||
from .models import OperatorOperation, PanelPeer, PeerActionGrant
|
||||
from .peering import PROTOCOL, issue_grant, panel_public_key, signed, verify
|
||||
from .peering import (
|
||||
PROTOCOL,
|
||||
PeerAccessError,
|
||||
issue_grant,
|
||||
panel_public_key,
|
||||
refresh_peer,
|
||||
signed,
|
||||
verify,
|
||||
)
|
||||
from .tasks import run_operator_operation
|
||||
|
||||
|
||||
@@ -137,3 +145,47 @@ class PanelPeerTests(TestCase):
|
||||
apply.assert_not_called()
|
||||
operation.refresh_from_db()
|
||||
self.assertEqual(operation.state, "failed")
|
||||
|
||||
def test_reverse_direction_and_unreachable_peer(self):
|
||||
target_key = panel_public_key()
|
||||
with override_settings(SECRET_KEY="source-panel-identity"):
|
||||
operator = get_user_model().objects.create_superuser("source")
|
||||
TOTPDevice.objects.create(user=operator, name="source device")
|
||||
reciprocal = PanelPeer.objects.create(
|
||||
origin="https://target.example.test",
|
||||
public_key=target_key,
|
||||
remote_username="target",
|
||||
operator=operator,
|
||||
)
|
||||
token = issue_grant(reciprocal, operator)
|
||||
packet = signed(
|
||||
{
|
||||
"request": str(uuid4()),
|
||||
"sender": target_key,
|
||||
"recipient": self.source_key,
|
||||
"protocol": PROTOCOL,
|
||||
"timestamp": int(timezone.now().timestamp()),
|
||||
"action": "package-check",
|
||||
"actor": "target",
|
||||
"value": token,
|
||||
}
|
||||
)
|
||||
with (
|
||||
override_settings(SECRET_KEY="source-panel-identity"),
|
||||
patch(
|
||||
"coulobre.hosting.peering.Path.is_socket", return_value=True
|
||||
),
|
||||
):
|
||||
reply = self.call_target(packet)
|
||||
self.assertEqual(reply.status_code, 200)
|
||||
envelope = reply.json()
|
||||
verify(self.source_key, envelope["message"], envelope["signature"])
|
||||
self.assertEqual(OperatorOperation.objects.get().actor, operator)
|
||||
with patch(
|
||||
"coulobre.hosting.peering.peer_call",
|
||||
side_effect=PeerAccessError("The peer did not respond."),
|
||||
):
|
||||
refresh_peer(reciprocal)
|
||||
reciprocal.refresh_from_db()
|
||||
self.assertEqual(reciprocal.problem, "The peer did not respond.")
|
||||
self.assertEqual(reciprocal.status, {})
|
||||
@@ -242,6 +242,7 @@ def check_folder_sftp_filesystem():
|
||||
run_mount,
|
||||
)
|
||||
|
||||
require_root_directory(WEB_ROOT.parent, create_mode=0o755)
|
||||
require_root_directory(WEB_ROOT, create_mode=0o755)
|
||||
require_root_directory(JAIL_ROOT, create_mode=0o755)
|
||||
with (
|
||||
|
||||
@@ -18,7 +18,10 @@ from .mail_queue import MailQueueRequest
|
||||
from .node_requests import serve_apply_request
|
||||
from .node_retirement import RetirementRequest
|
||||
from .service_access import ServiceAccessRequest
|
||||
from .service_credentials import ServiceCredentialRequest
|
||||
from .service_credentials import (
|
||||
ServiceCredentialRequest,
|
||||
apply_mailbox_password_request,
|
||||
)
|
||||
|
||||
|
||||
def check_request(role, spec=None):
|
||||
@@ -99,12 +102,13 @@ class ReceiverScopeTests(TestCase):
|
||||
patch.object(
|
||||
receiver_scope,
|
||||
"scoped_domains",
|
||||
side_effect=[{mailbox.domain}, {"beta.example.test"}] * 2,
|
||||
side_effect=[{mailbox.domain}, {"beta.example.test"}] * 3,
|
||||
),
|
||||
):
|
||||
for operation in (
|
||||
ServiceCredentialRequest(mailbox, "generation"),
|
||||
ServiceCredentialRequest(mailbox, "rotate", str(uuid4())),
|
||||
ServiceCredentialRequest(mailbox, "webmail"),
|
||||
):
|
||||
request = parse_mailbox_request(operation.manifest())
|
||||
self.assertEqual(request, operation)
|
||||
@@ -114,6 +118,23 @@ class ReceiverScopeTests(TestCase):
|
||||
with self.assertRaisesRegex(ValueError, "not assigned"):
|
||||
check_request("mail", request)
|
||||
|
||||
def test_scoped_webmail_refuses_an_unscoped_legacy_relay(self):
|
||||
mailbox = MailboxSpec("alpha.example.test", "sales")
|
||||
request = ServiceCredentialRequest(mailbox, "webmail")
|
||||
with (
|
||||
patch("coulobre.service_credentials.socket_peer") as peer,
|
||||
patch(
|
||||
"coulobre.service_credentials.read_mailbox_credentials"
|
||||
) as read,
|
||||
):
|
||||
peer.return_value = "coulobre-mail-relay"
|
||||
with self.assertRaisesRegex(ValueError, "domain-scoped"):
|
||||
apply_mailbox_password_request(request)
|
||||
read.assert_not_called()
|
||||
peer.return_value = "coulobre-mail-p-alpha"
|
||||
apply_mailbox_password_request(request)
|
||||
read.assert_called_once_with(mailbox, active_only=True)
|
||||
|
||||
def test_scope_is_enforced_before_dispatching_dns_operations(self):
|
||||
zone = DnsZone(
|
||||
"beta.example.test",
|
||||
|
||||
Reference in new issue
Block a user