mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 09:37:02 +00:00
feat: Add SMTPResponse type for extensions (#539)
Signed-off-by: James Hillyerd <james@hillyerd.com>
This commit is contained in:
40
pkg/extension/luahost/bind_smtpresponse_test.go
Normal file
40
pkg/extension/luahost/bind_smtpresponse_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package luahost
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/inbucket/inbucket/v3/pkg/extension/event"
|
||||
"github.com/inbucket/inbucket/v3/pkg/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSMTPResponseConstructors(t *testing.T) {
|
||||
check := func(script string, want event.SMTPResponse) {
|
||||
t.Helper()
|
||||
ls, _ := test.NewLuaState()
|
||||
registerSMTPResponseType(ls)
|
||||
require.NoError(t, ls.DoString(script))
|
||||
|
||||
got, err := unwrapSMTPResponse(ls.Get(-1))
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, &want, got)
|
||||
}
|
||||
|
||||
check("return smtp.defer()", event.SMTPResponse{Action: event.ActionDefer})
|
||||
check("return smtp.allow()", event.SMTPResponse{Action: event.ActionAllow})
|
||||
|
||||
// Verify deny() has default code & msg.
|
||||
check("return smtp.deny()", event.SMTPResponse{
|
||||
Action: event.ActionDeny,
|
||||
ErrorCode: 550,
|
||||
ErrorMsg: "Mail denied by policy",
|
||||
})
|
||||
|
||||
// Verify defaults can be overridden.
|
||||
check("return smtp.deny(123, 'bacon')", event.SMTPResponse{
|
||||
Action: event.ActionDeny,
|
||||
ErrorCode: 123,
|
||||
ErrorMsg: "bacon",
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user