Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump github.com/emersion/go-smtp from 0.18.1 to 0.19.0 #280

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestSmokeLoadConfigShouldBeOk(t *testing.T) {
data := `
smtpd-proxy:
listen: 127.0.0.1:1025
ehlo: localhost
ehlo: 127.0.0.1
username: user
password: secret
server-cert: server.crt
Expand Down Expand Up @@ -41,7 +41,7 @@ smtpd-proxy:

srv := c.ServerConfig
assert.Equal(t, "127.0.0.1:1025", srv.Listen)
assert.Equal(t, "localhost", srv.Ehlo)
assert.Equal(t, "127.0.0.1", srv.Ehlo)
assert.Equal(t, "user", srv.Username)
assert.Equal(t, "secret", srv.Password)
assert.Equal(t, "server.crt", srv.ServerCertificatePath)
Expand Down
6 changes: 3 additions & 3 deletions app/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Test_Main(t *testing.T) {
yamlConfig := fmt.Sprintf(`
smtpd-proxy:
listen: %s:%d
ehlo: localhost
ehlo: 127.0.0.1
username: user
password: secret
is_anon_auth_allowed: true
Expand Down Expand Up @@ -73,7 +73,7 @@ smtpd-proxy:

response := readStrings(bufReader)
for _, s := range [...]string{
"220 localhost ESMTP Service Ready",
"220 127.0.0.1 ESMTP Service Ready",
"250-Hello test",
"250-PIPELINING",
"250-8BITMIME",
Expand All @@ -100,7 +100,7 @@ func waitForPortListenStart(ctx context.Context, t *testing.T, port int) (conn n
var d net.Dialer
var err error
addr := fmt.Sprintf("%s:%d", bindHost, port)
poll := time.NewTicker(20 * time.Millisecond)
poll := time.NewTicker(50 * time.Millisecond)
defer poll.Stop()
timeout := time.NewTimer(5 * time.Second)
defer timeout.Stop()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/ses v1.18.1
github.com/creasty/defaults v1.7.0
github.com/emersion/go-sasl v0.0.0-20220912192320-0145f2c60ead
github.com/emersion/go-smtp v0.18.1
github.com/emersion/go-smtp v0.19.0
github.com/hashicorp/go-multierror v1.1.1
github.com/jessevdk/go-flags v1.5.0
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ=
github.com/emersion/go-sasl v0.0.0-20220912192320-0145f2c60ead h1:fI1Jck0vUrXT8bnphprS1EoVRe2Q5CKCX8iDlpqjQ/Y=
github.com/emersion/go-sasl v0.0.0-20220912192320-0145f2c60ead/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ=
github.com/emersion/go-smtp v0.18.1 h1:4DFV0jxKhq0Gqt/Br3BRHyKZy5TStk6NIMHAx6GE/LA=
github.com/emersion/go-smtp v0.18.1/go.mod h1:qm27SGYgoIPRot6ubfQ/GpiPy/g3PaZAVRxiO/sDUgQ=
github.com/emersion/go-smtp v0.19.0 h1:iVCDtR2/JY3RpKoaZ7u6I/sb52S3EzfNHO1fAWVHgng=
github.com/emersion/go-smtp v0.19.0/go.mod h1:qm27SGYgoIPRot6ubfQ/GpiPy/g3PaZAVRxiO/sDUgQ=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
Expand Down
9 changes: 2 additions & 7 deletions tests/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"time"

"github.com/leonardinius/smtpd-proxy/app/cmd"
"github.com/leonardinius/smtpd-proxy/app/zlog"
"github.com/stretchr/testify/require"
tc "github.com/testcontainers/testcontainers-go"
)
Expand All @@ -34,6 +33,7 @@ func RunMainWithConfig(ctx context.Context, t *testing.T, yamlConfig string, por

serverCh := make(chan cmd.ServerSignal)
done := make(chan struct{})

go func() {
<-done
serverCh <- cmd.ServerStopSignal
Expand All @@ -52,11 +52,6 @@ func RunMainWithConfig(ctx context.Context, t *testing.T, yamlConfig string, por
}()

conn := waitForPortListenStart(ctx, t, port)
defer func() {
err = conn.Close()
zlog.Debugf("conn.Close() error: %v", err)
}()

test(t, conn)
}

Expand All @@ -81,7 +76,7 @@ func waitForPortListenStart(ctx context.Context, t *testing.T, port int) (conn n
}

require.NotNil(t, conn)
err = conn.SetDeadline(time.Now().Add(100 * time.Millisecond))
err = conn.SetDeadline(time.Now().Add(500 * time.Millisecond))
if err != nil {
t.Fatal("SMTP set connection deadline error", err)
}
Expand Down
68 changes: 36 additions & 32 deletions tests/ses_forwarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ func (su *SESSystemTestSuite) /* */ TearDownSuite() {
func (su *SESSystemTestSuite) TestSmokeSESForwardAcceptsSimpleEMail() {
port := DynamicPort()
proxyEndpoint := fmt.Sprintf("%s:%d", BindHost, port)
sesEndpoint, err := su.localstack.PortEndpoint(su.ctx, "4566/tcp", "http")
sesPort, err := su.localstack.MappedPort(su.ctx, "4566/tcp")
require.NoError(su.T(), err)
sesEndpoint := fmt.Sprintf("http://%s:%s", BindHost, sesPort.Port())
config := fmt.Sprintf(`
smtpd-proxy:
listen: %s:%d
ehlo: localhost
username: [email protected]
ehlo: 127.0.0.1
username: user-ses@example.com
password: password
is_anon_auth_allowed: false
upstream-servers:
Expand All @@ -80,46 +81,47 @@ smtpd-proxy:
region: us-east-1
`, BindHost, port, sesEndpoint)
RunMainWithConfig(su.ctx, su.T(), config, port, func(t *testing.T, conn net.Conn) {
fromEmail := "<[email protected]>"
fromEmail := fmt.Sprintf("<gotest-%d-[email protected]>", time.Now().UnixMilli())
// Setup authentication information.
auth := smtp.PlainAuth("", "[email protected]", "password", BindHost)
to := []string{"[email protected]"}
auth := smtp.PlainAuth("", "user-ses@example.com", "password", BindHost)
to := []string{"recipient-ses@example.net"}
msg := strings.Join([]string{
"To: <[email protected]>",
"To: <discard-simple-ses@tld.invalid>",
"From: " + fromEmail,
"Subject: Test E-mail!",
"Subject: Test E-mail! (SES)",
"",
"This is the email body.",
"This is the email body (SES).",
"",
}, "\r\n")
err := smtp.SendMail(proxyEndpoint, auth, "[email protected]", to, []byte(msg))
require.ErrorContains(t, err, "Email address not verified <[email protected]>")
err := smtp.SendMail(proxyEndpoint, auth, "sender-ses@example.org", to, []byte(msg))
require.ErrorContains(t, err, "Email address not verified")

ses := newSesClient(su.ctx, t, sesEndpoint)
_, err = ses.VerifyEmailIdentity(su.ctx, &awsses.VerifyEmailIdentityInput{EmailAddress: aws.String(fromEmail)})
require.NoError(t, err)
err = smtp.SendMail(proxyEndpoint, auth, "[email protected]", to, []byte(msg))
err = smtp.SendMail(proxyEndpoint, auth, "sender-ses@example.org", to, []byte(msg))
assert.NoError(t, err)

sesFile := requireSesFileWithContains(t, fromEmail)
bytes, err := io.ReadAll(sesFile)
require.NoError(t, err)
jsonMessage := string(bytes)
assert.Contains(t, jsonMessage,
"\"This is the email body.\\r\\n\"")
"\"This is the email body (SES).\\r\\n\"")
})
}

func (su *SESSystemTestSuite) TestSmokeSESForwardAcceptsEMailWithAttachments() {
port := DynamicPort()
proxyEndpoint := fmt.Sprintf("%s:%d", BindHost, port)
sesEndpoint, err := su.localstack.PortEndpoint(su.ctx, "4566/tcp", "http")
sesPort, err := su.localstack.MappedPort(su.ctx, "4566/tcp")
require.NoError(su.T(), err)
sesEndpoint := fmt.Sprintf("http://%s:%s", BindHost, sesPort.Port())
config := fmt.Sprintf(`
smtpd-proxy:
listen: %s:%d
ehlo: localhost
username: [email protected]
ehlo: 127.0.0.1
username: user-ses@example.com
password: password
is_anon_auth_allowed: false
upstream-servers:
Expand All @@ -131,18 +133,19 @@ smtpd-proxy:
region: us-east-1
`, BindHost, port, sesEndpoint)
RunMainWithConfig(su.ctx, su.T(), config, port, func(t *testing.T, conn net.Conn) {
fromEmail := fmt.Sprintf("<gotest-%[email protected]>", time.Now().UnixMilli())
ses := newSesClient(su.ctx, t, sesEndpoint)
_, err = ses.VerifyEmailIdentity(su.ctx, &awsses.VerifyEmailIdentityInput{EmailAddress: aws.String("<[email protected]>")})
require.NoError(t, err, "failed to verify gotest-attachment@esmtp.email")
_, err = ses.VerifyEmailIdentity(su.ctx, &awsses.VerifyEmailIdentityInput{EmailAddress: aws.String(fromEmail)})
require.NoError(t, err, "failed to verify attachment email")

// Setup authentication information.
auth := smtp.PlainAuth("", "[email protected]", "password", BindHost)
auth := smtp.PlainAuth("", "user-ses@example.com", "password", BindHost)
envelope := email.NewEmail()
envelope.To = []string{"<[email protected]>"}
envelope.From = "<[email protected]>"
envelope.Subject = "Subject: Test E-mail!"
envelope.Text = []byte("This is the email body.")
envelope.Sender = "[email protected]"
envelope.To = []string{"<discard-attachment-ses@tld.invalid>"}
envelope.From = fromEmail
envelope.Subject = "Subject: Test Ses E-mail!"
envelope.Text = []byte("This is the email body (SES).")
envelope.Sender = "recipient-ses@example.net"
_, err := envelope.AttachFile("_testData/text-attachment.txt")
require.NoError(t, err, "failed to attach file")
err = envelope.Send(proxyEndpoint, auth)
Expand All @@ -157,31 +160,32 @@ smtpd-proxy:
for strings.HasSuffix(loremIpsumBase64, "=") {
loremIpsumBase64 = strings.TrimSuffix(loremIpsumBase64, "=")
}
assert.Contains(t, jsonMessage, "\\r\\nThis is the email body.\\r\\n")
assert.Contains(t, jsonMessage, "\\r\\nThis is the email body (SES).\\r\\n")
assert.Contains(t, jsonMessage, loremIpsumBase64)
})
}

func iniFakeSMTPContainer(ctx context.Context) (container tc.Container, err error) {
vol, _ := filepath.Abs(".volume")
_ = os.Mkdir(vol, 0o755)
_ = os.RemoveAll(filepath.Join(vol, "tmp", "state", "ses"))
_ = os.RemoveAll(vol + "/state/ses")
localstackReq := tc.ContainerRequest{
Image: "localstack/localstack",
Image: "localstack/localstack:2.3.2",
ExposedPorts: []string{"4566/tcp"},
Env: map[string]string{
"EAGER_SERVICE_LOADING": "1",
"SERVICES": "ses",
"DEBUG": "1",
"PERSISTENCE": "1",
},
Mounts: tc.Mounts(tc.BindMount(vol, "/var/lib/localstack")),
WaitingFor: wait.ForListeningPort("4566/tcp"),
}

container, err = tc.GenericContainer(ctx, tc.GenericContainerRequest{
ContainerRequest: localstackReq,
Started: true,
})
return
return container, err
}

func newSesClient(ctx context.Context, t *testing.T, endpoint string) *awsses.Client {
Expand All @@ -205,7 +209,7 @@ func newSesClient(ctx context.Context, t *testing.T, endpoint string) *awsses.Cl

func requireSesFileWithContains(t *testing.T, needle string) *os.File {
var sesFile *os.File
const mailSesJSONDir = ".volume/tmp/state/ses/"
const mailSesJSONDir = ".volume/state/ses/"
assert.Eventuallyf(t,
func() bool {
dir, e := filepath.Abs(mailSesJSONDir)
Expand Down Expand Up @@ -233,8 +237,8 @@ func requireSesFileWithContains(t *testing.T, needle string) *os.File {
}
return sesFile != nil
},
5*time.Second,
50*time.Millisecond,
10*time.Second,
300*time.Millisecond,
"Failed to obtain ses payloads for %s", needle,
)
require.NotNil(t, sesFile)
Expand Down
Loading
Loading