Skip to content

Commit

Permalink
endpoint/smtp: Fix auth_map ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
foxcpp committed Feb 1, 2025
1 parent c852199 commit 1d04424
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/endpoint/smtp/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ func (endp *Endpoint) setConfig(cfg *config.Map) error {
return err
}

endp.saslAuth.Log.Debug = endp.Log.Debug

// INTERNATIONALIZATION: See RFC 6531 Section 3.3.
endp.serv.Domain, err = idna.ToASCII(hostname)
if err != nil {
Expand All @@ -310,8 +312,6 @@ func (endp *Endpoint) setConfig(cfg *config.Map) error {
return fmt.Errorf("%s: auth. provider must be set for submission endpoint", endp.name)
}
}
endp.saslAuth.AuthNormalize = endp.authNormalize
endp.saslAuth.AuthMap = endp.authMap

if ioDebug {
endp.serv.Debug = endp.Log.DebugWriter()
Expand Down
69 changes: 69 additions & 0 deletions tests/multiple_domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,44 @@ func TestMultipleDomains_SeparateNamespace(tt *testing.T) {
t.Run(2)

user1 := t.Conn("imap")
defer user1.Close()
user1.ExpectPattern(`\* OK *`)
user1.Writeln(`. LOGIN [email protected] user1`)
user1.ExpectPattern(`. OK *`)
user1.Writeln(`. CREATE user1`)
user1.ExpectPattern(`. OK *`)

user1SMTP := t.Conn("submission")
defer user1SMTP.Close()
user1SMTP.SMTPNegotation("localhost", []string{"AUTH PLAIN"}, nil)
user1SMTP.SMTPPlainAuth("[email protected]", "user1", true)

user2 := t.Conn("imap")
defer user2.Close()
user2.ExpectPattern(`\* OK *`)
user2.Writeln(`. LOGIN [email protected] user2`)
user2.ExpectPattern(`. OK *`)
user2.Writeln(`. CREATE user2`)
user2.ExpectPattern(`. OK *`)

user2SMTP := t.Conn("submission")
defer user2SMTP.Close()
user2SMTP.SMTPNegotation("localhost", []string{"AUTH PLAIN"}, nil)
user2SMTP.SMTPPlainAuth("[email protected]", "user2", true)

user3 := t.Conn("imap")
defer user3.Close()
user3.ExpectPattern(`\* OK *`)
user3.Writeln(`. LOGIN [email protected] user3`)
user3.ExpectPattern(`. OK *`)
user3.Writeln(`. CREATE user3`)
user3.ExpectPattern(`. OK *`)

user3SMTP := t.Conn("submission")
defer user3SMTP.Close()
user3SMTP.SMTPNegotation("localhost", []string{"AUTH PLAIN"}, nil)
user3SMTP.SMTPPlainAuth("[email protected]", "user3", true)

user1.Writeln(`. LIST "" "*"`)
user1.Expect(`* LIST (\HasNoChildren) "." INBOX`)
user1.Expect(`* LIST (\HasNoChildren) "." "user1"`)
Expand Down Expand Up @@ -150,26 +168,44 @@ func TestMultipleDomains_SharedCredentials_DistinctMailboxes(tt *testing.T) {
t.Run(2)

user1 := t.Conn("imap")
defer user1.Close()
user1.ExpectPattern(`\* OK *`)
user1.Writeln(`. LOGIN [email protected] user1`)
user1.ExpectPattern(`. OK *`)
user1.Writeln(`. CREATE user1`)
user1.ExpectPattern(`. OK *`)

user1SMTP := t.Conn("submission")
defer user1SMTP.Close()
user1SMTP.SMTPNegotation("localhost", []string{"AUTH PLAIN"}, nil)
user1SMTP.SMTPPlainAuth("[email protected]", "user1", true)

user2 := t.Conn("imap")
defer user2.Close()
user2.ExpectPattern(`\* OK *`)
user2.Writeln(`. LOGIN [email protected] user2`)
user2.ExpectPattern(`. OK *`)
user2.Writeln(`. CREATE user2`)
user2.ExpectPattern(`. OK *`)

user2SMTP := t.Conn("submission")
defer user2SMTP.Close()
user2SMTP.SMTPNegotation("localhost", []string{"AUTH PLAIN"}, nil)
user2SMTP.SMTPPlainAuth("[email protected]", "user2", true)

user3 := t.Conn("imap")
defer user3.Close()
user3.ExpectPattern(`\* OK *`)
user3.Writeln(`. LOGIN [email protected] user1`)
user3.ExpectPattern(`. OK *`)
user3.Writeln(`. CREATE user3`)
user3.ExpectPattern(`. OK *`)

user3SMTP := t.Conn("submission")
defer user3SMTP.Close()
user3SMTP.SMTPNegotation("localhost", []string{"AUTH PLAIN"}, nil)
user3SMTP.SMTPPlainAuth("[email protected]", "user1", true)

user1.Writeln(`. LIST "" "*"`)
user1.Expect(`* LIST (\HasNoChildren) "." INBOX`)
user1.Expect(`* LIST (\HasNoChildren) "." "user1"`)
Expand Down Expand Up @@ -232,30 +268,62 @@ func TestMultipleDomains_SharedCredentials_SharedMailboxes(tt *testing.T) {
t.Run(2)

user1 := t.Conn("imap")
defer user1.Close()
user1.ExpectPattern(`\* OK *`)
user1.Writeln(`. LOGIN user1 user1`)
user1.ExpectPattern(`. OK *`)
user1.Writeln(`. CREATE user1`)
user1.ExpectPattern(`. OK *`)

user1SMTP := t.Conn("submission")
defer user1SMTP.Close()
user1SMTP.SMTPNegotation("localhost", []string{"AUTH PLAIN"}, nil)
user1SMTP.SMTPPlainAuth("user1", "user1", true)

user2 := t.Conn("imap")
defer user2.Close()
user2.ExpectPattern(`\* OK *`)
user2.Writeln(`. LOGIN [email protected] user2`)
user2.ExpectPattern(`. OK *`)
user2.Writeln(`. CREATE user2`)
user2.ExpectPattern(`. OK *`)

user2SMTP := t.Conn("submission")
defer user2SMTP.Close()
user2SMTP.SMTPNegotation("localhost", []string{"AUTH PLAIN"}, nil)
user2SMTP.SMTPPlainAuth("user2", "user2", true)

user12 := t.Conn("imap")
defer user12.Close()
user12.ExpectPattern(`\* OK *`)
user12.Writeln(`. LOGIN [email protected] user1`)
user12.ExpectPattern(`. OK *`)
user12.Writeln(`. CREATE user12`)
user12.ExpectPattern(`. OK *`)

user13 := t.Conn("imap")
defer user13.Close()
user13.ExpectPattern(`\* OK *`)
user13.Writeln(`. LOGIN [email protected] user1`)
user13.ExpectPattern(`. OK *`)
user13.Writeln(`. CREATE user13`)
user13.ExpectPattern(`. OK *`)

user12SMTP := t.Conn("submission")
defer user12SMTP.Close()
user12SMTP.SMTPNegotation("localhost", []string{"AUTH PLAIN"}, nil)
user12SMTP.SMTPPlainAuth("user1", "user1", true)

user13SMTP := t.Conn("submission")
defer user13SMTP.Close()
user13SMTP.SMTPNegotation("localhost", []string{"AUTH PLAIN"}, nil)
user13SMTP.SMTPPlainAuth("[email protected]", "user1", true)

user1.Writeln(`. LIST "" "*"`)
user1.Expect(`* LIST (\HasNoChildren) "." INBOX`)
user1.Expect(`* LIST (\HasNoChildren) "." "user1"`)
user1.Expect(`* LIST (\HasNoChildren) "." "user12"`)
user1.Expect(`* LIST (\HasNoChildren) "." "user13"`)
user1.ExpectPattern(". OK *")

user2.Writeln(`. LIST "" "*"`)
Expand All @@ -267,5 +335,6 @@ func TestMultipleDomains_SharedCredentials_SharedMailboxes(tt *testing.T) {
user12.Expect(`* LIST (\HasNoChildren) "." INBOX`)
user12.Expect(`* LIST (\HasNoChildren) "." "user1"`)
user12.Expect(`* LIST (\HasNoChildren) "." "user12"`)
user12.Expect(`* LIST (\HasNoChildren) "." "user13"`)
user12.ExpectPattern(". OK *")
}

1 comment on commit 1d04424

@McSinyx
Copy link

@McSinyx McSinyx commented on 1d04424 Mar 6, 2025

Choose a reason for hiding this comment

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

I suppose this fixes the regression introduced by 120c5c9, which prevents me from sending out emails (we use auth.shadow on our server). Could you please tag a release with this included?

Please sign in to comment.