mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 10:07:02 +00:00
chore: Update BeforeMailAccepted (#547)
* chore: rename BeforeMailAccepted to BeforeMailFromAccepted Signed-off-by: James Hillyerd <james@hillyerd.com> * chore: update BeforeMailAccepted to use SMTPSession Signed-off-by: James Hillyerd <james@hillyerd.com> --------- Signed-off-by: James Hillyerd <james@hillyerd.com>
This commit is contained in:
@@ -105,11 +105,11 @@ func TestAfterMessageStored(t *testing.T) {
|
||||
test.AssertNotified(t, notify)
|
||||
}
|
||||
|
||||
func TestBeforeMailAccepted(t *testing.T) {
|
||||
func TestBeforeMailFromAccepted(t *testing.T) {
|
||||
// Register lua event listener.
|
||||
script := `
|
||||
function inbucket.before.mail_accepted(localpart, domain)
|
||||
if localpart == "from" and domain == "test" then
|
||||
function inbucket.before.mail_from_accepted(session)
|
||||
if session.from.address == "from@example.com" then
|
||||
logger.info("allowing message", {})
|
||||
return smtp.allow()
|
||||
else
|
||||
@@ -123,22 +123,30 @@ func TestBeforeMailAccepted(t *testing.T) {
|
||||
consoleLogger, extHost, strings.NewReader(test.LuaInit+script), "test.lua")
|
||||
require.NoError(t, err)
|
||||
|
||||
// Send event to be accepted.
|
||||
addr := &event.AddressParts{Local: "from", Domain: "test"}
|
||||
got := extHost.Events.BeforeMailAccepted.Emit(addr)
|
||||
want := event.ActionAllow
|
||||
require.NotNil(t, got, "Expected result from Emit()")
|
||||
if got.Action != want {
|
||||
t.Errorf("Got %v, wanted %v for addr %v", got.Action, want, addr)
|
||||
{
|
||||
// Send event to be accepted.
|
||||
session := event.SMTPSession{
|
||||
From: &mail.Address{Name: "", Address: "from@example.com"},
|
||||
}
|
||||
got := extHost.Events.BeforeMailFromAccepted.Emit(&session)
|
||||
want := event.ActionAllow
|
||||
require.NotNil(t, got, "Expected result from Emit()")
|
||||
if got.Action != want {
|
||||
t.Errorf("Got %v, wanted %v for addr %v", got.Action, want, session.From)
|
||||
}
|
||||
}
|
||||
|
||||
// Send event to be denied.
|
||||
addr = &event.AddressParts{Local: "reject", Domain: "me"}
|
||||
got = extHost.Events.BeforeMailAccepted.Emit(addr)
|
||||
want = event.ActionDeny
|
||||
require.NotNil(t, got, "Expected result from Emit()")
|
||||
if got.Action != want {
|
||||
t.Errorf("Got %v, wanted %v for addr %v", got.Action, want, addr)
|
||||
{
|
||||
// Send event to be denied.
|
||||
session := event.SMTPSession{
|
||||
From: &mail.Address{Name: "", Address: "from@reject.com"},
|
||||
}
|
||||
got := extHost.Events.BeforeMailFromAccepted.Emit(&session)
|
||||
want := event.ActionDeny
|
||||
require.NotNil(t, got, "Expected result from Emit()")
|
||||
if got.Action != want {
|
||||
t.Errorf("Got %v, wanted %v for addr %v", got.Action, want, session.From)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user