Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: support optional SMTP auth#14533

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

Merged
dannykopping merged 2 commits intomainfromdk/optional-auth
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
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
12 changes: 11 additions & 1 deletioncoderd/notifications/dispatch/smtp.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,7 +53,8 @@ type SMTPHandler struct {
cfg codersdk.NotificationsEmailConfig
log slog.Logger

loginWarnOnce sync.Once
noAuthWarnOnce sync.Once
loginWarnOnce sync.Once

helpers template.FuncMap
}
Expand DownExpand Up@@ -431,6 +432,15 @@ func (s *SMTPHandler) loadCertificate() (*tls.Certificate, error) {
func (s *SMTPHandler) auth(ctx context.Context, mechs string) (sasl.Client, error) {
username := s.cfg.Auth.Username.String()

// All auth mechanisms require username, so if one is not defined then don't return an auth client.
if username == "" {
s.noAuthWarnOnce.Do(func() {
s.log.Warn(ctx, "skipping auth; no username configured", slog.F("support_mechanisms", mechs))
})
// nolint:nilnil // This is a valid response.
return nil, nil
Copy link
Member

@mafredrimafredriSep 3, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Is the new return signature handled by the caller(s)? I see that nilnil is new (unless sasl lib also returns it).

Edit: Might be good to mention this return signature in the function comment as well.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yup.

// Check for authentication capabilities.ifok,avail:=c.Extension("AUTH");ok {<---entersifauthissupported// Ensure the auth mechanisms available are ones we can use.auth,err:=s.auth(ctx,avail)iferr!=nil {returntrue,xerrors.Errorf("determine auth mechanism: %w",err)}// If so, use the auth mechanism to authenticate.ifauth!=nil {<---bailsoutbecauseauthisniliferr:=c.Auth(auth);err!=nil {returntrue,xerrors.Errorf("%T auth: %w",auth,err)}}}elseif!s.cfg.Auth.Empty() {returnfalse,xerrors.New("no authentication mechanisms supported by server")}<---...continuestoprocessmessagewithoutauth...

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Admittedly the comments could be better about this case, lemme add that.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Seef7fcaf9@mafredri, thanks for the prompt.

}

var errs error
list := strings.Split(mechs, " ")
for _, mech := range list {
Expand Down
11 changes: 10 additions & 1 deletioncoderd/notifications/dispatch/smtp_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -203,7 +203,6 @@ func TestSMTP(t *testing.T) {
retryable: false,
},
{
// No auth, no problem!
name: "No auth mechanisms supported, none configured",
authMechs: []string{},
cfg: codersdk.NotificationsEmailConfig{
Expand All@@ -213,6 +212,16 @@ func TestSMTP(t *testing.T) {
toAddrs: []string{to},
expectedAuthMeth: "",
},
{
name: "Auth mechanisms supported optionally, none configured",
authMechs: []string{sasl.Login, sasl.Plain},
cfg: codersdk.NotificationsEmailConfig{
Hello: hello,
From: from,
},
toAddrs: []string{to},
expectedAuthMeth: "",
},
/**
* TLS connections
*/
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp