feat: add sender/recipient accept gates, security+stress test harnesses, nix flake, and docs
This commit is contained in:
parent
a0950fab52
commit
5dda6567af
18 changed files with 1764 additions and 44 deletions
|
|
@ -8,22 +8,27 @@ from pneumatube.lookup_server import _lookup
|
|||
|
||||
|
||||
class _StubBridge:
|
||||
def __init__(self, known):
|
||||
def __init__(self, known, accepted=None):
|
||||
self.known = known
|
||||
self.accepted = known if accepted is None else accepted
|
||||
|
||||
def user_exists(self, username):
|
||||
if username == "broken":
|
||||
return None
|
||||
return username in self.known
|
||||
|
||||
def recipient_accepted_gateway(self, username):
|
||||
return username in self.accepted
|
||||
|
||||
|
||||
class _InlineWorker:
|
||||
async def run(self, fn, *args):
|
||||
return fn(*args)
|
||||
|
||||
|
||||
def _config():
|
||||
return SimpleNamespace(email_domain="gateway.example")
|
||||
def _config(**overrides):
|
||||
defaults = {"email_domain": "gateway.example", "require_accepted_recipient": True}
|
||||
return SimpleNamespace(**{**defaults, **overrides})
|
||||
|
||||
|
||||
def test_lookup_known_user_returns_ok():
|
||||
|
|
@ -52,3 +57,20 @@ def test_lookup_other_domain_has_no_opinion():
|
|||
bridge = _StubBridge({"alice"})
|
||||
reply = asyncio.run(_lookup(bridge, _InlineWorker(), _config(), "alice@other.example"))
|
||||
assert reply == "500 not found"
|
||||
|
||||
|
||||
def test_lookup_rejects_unaccepted_recipient_by_default():
|
||||
bridge = _StubBridge({"alice"}, accepted=set())
|
||||
reply = asyncio.run(_lookup(bridge, _InlineWorker(), _config(), "alice@gateway.example"))
|
||||
code, _, text = reply.partition(" ")
|
||||
assert code == "200"
|
||||
assert unquote(text) == "550 5.7.1 recipient has not accepted mail from this gateway"
|
||||
|
||||
|
||||
def test_lookup_allows_unaccepted_recipient_when_disabled():
|
||||
bridge = _StubBridge({"alice"}, accepted=set())
|
||||
config = _config(require_accepted_recipient=False)
|
||||
reply = asyncio.run(_lookup(bridge, _InlineWorker(), config, "alice@gateway.example"))
|
||||
code, _, text = reply.partition(" ")
|
||||
assert code == "200"
|
||||
assert unquote(text) == "OK"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue