- Notifications
You must be signed in to change notification settings - Fork914
fix: correctly close SMTP message and await response#14495
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -62,6 +62,7 @@ func TestSMTP(t *testing.T) { | ||
expectedErr string | ||
retryable bool | ||
useTLS bool | ||
failOnDataFn func() error | ||
}{ | ||
/** | ||
* LOGIN auth mechanism | ||
@@ -381,6 +382,21 @@ func TestSMTP(t *testing.T) { | ||
toAddrs: []string{to}, | ||
expectedAuthMeth: sasl.Plain, | ||
}, | ||
/** | ||
* Other errors | ||
*/ | ||
{ | ||
name: "Rejected on DATA", | ||
cfg: codersdk.NotificationsEmailConfig{ | ||
Hello: hello, | ||
From: from, | ||
}, | ||
failOnDataFn: func() error { | ||
return &smtp.SMTPError{Code: 501, EnhancedCode: smtp.EnhancedCode{5, 5, 4}, Message: "Rejected!"} | ||
}, | ||
expectedErr: "SMTP error 501: Rejected!", | ||
retryable: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Isn't this error non-retryable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Not apriori; it could be a temporary failure. | ||
}, | ||
} | ||
// nolint:paralleltest // Reinitialization is not required as of Go v1.22. | ||
@@ -398,6 +414,8 @@ func TestSMTP(t *testing.T) { | ||
AcceptedIdentity: tc.cfg.Auth.Identity.String(), | ||
AcceptedUsername: username, | ||
AcceptedPassword: password, | ||
FailOnDataFn: tc.failOnDataFn, | ||
}) | ||
// Create a mock SMTP server which conditionally listens for plain or TLS connections. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -24,6 +24,7 @@ var ( | ||
type Config struct { | ||
AuthMechanisms []string | ||
AcceptedIdentity, AcceptedUsername, AcceptedPassword string | ||
FailOnDataFn func() error | ||
} | ||
type Message struct { | ||
@@ -147,6 +148,10 @@ func (s *Session) Data(r io.Reader) error { | ||
return err | ||
} | ||
if s.backend.cfg.FailOnDataFn != nil { | ||
return s.backend.cfg.FailOnDataFn() | ||
} | ||
Comment on lines +151 to +153 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. At some point in the future, would it make sense to test with something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I evaluated it, but it does not support authentication. | ||
s.backend.lastMsg.Contents = string(b) | ||
return nil | ||
Uh oh!
There was an error while loading.Please reload this page.