mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-15 02:12:55 +01:00
Add 'skipTLS' parameter to auth functions in tests
Updated PlainAuth and LoginAuth calls in smtp_test.go and example_test.go to include a 'skipTLS' boolean parameter. This ensures consistent function signatures throughout the test cases and examples.
This commit is contained in:
parent
3c29f68cc1
commit
2bd950469a
2 changed files with 31 additions and 15 deletions
|
@ -67,7 +67,7 @@ var (
|
||||||
func ExamplePlainAuth() {
|
func ExamplePlainAuth() {
|
||||||
// hostname is used by PlainAuth to validate the TLS certificate.
|
// hostname is used by PlainAuth to validate the TLS certificate.
|
||||||
hostname := "mail.example.com"
|
hostname := "mail.example.com"
|
||||||
auth := smtp.PlainAuth("", "user@example.com", "password", hostname)
|
auth := smtp.PlainAuth("", "user@example.com", "password", hostname, false)
|
||||||
|
|
||||||
err := smtp.SendMail(hostname+":25", auth, from, recipients, msg)
|
err := smtp.SendMail(hostname+":25", auth, from, recipients, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -77,7 +77,7 @@ func ExamplePlainAuth() {
|
||||||
|
|
||||||
func ExampleSendMail() {
|
func ExampleSendMail() {
|
||||||
// Set up authentication information.
|
// Set up authentication information.
|
||||||
auth := smtp.PlainAuth("", "user@example.com", "password", "mail.example.com")
|
auth := smtp.PlainAuth("", "user@example.com", "password", "mail.example.com", false)
|
||||||
|
|
||||||
// Connect to the server, authenticate, set the sender and recipient,
|
// Connect to the server, authenticate, set the sender and recipient,
|
||||||
// and send the email all in one step.
|
// and send the email all in one step.
|
||||||
|
|
|
@ -50,7 +50,7 @@ type authTest struct {
|
||||||
|
|
||||||
var authTests = []authTest{
|
var authTests = []authTest{
|
||||||
{
|
{
|
||||||
PlainAuth("", "user", "pass", "testserver"),
|
PlainAuth("", "user", "pass", "testserver", false),
|
||||||
[]string{},
|
[]string{},
|
||||||
"PLAIN",
|
"PLAIN",
|
||||||
[]string{"\x00user\x00pass"},
|
[]string{"\x00user\x00pass"},
|
||||||
|
@ -58,7 +58,15 @@ var authTests = []authTest{
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
PlainAuth("foo", "bar", "baz", "testserver"),
|
PlainAuth("", "user", "pass", "testserver", true),
|
||||||
|
[]string{},
|
||||||
|
"PLAIN",
|
||||||
|
[]string{"\x00user\x00pass"},
|
||||||
|
[]bool{false, false},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
PlainAuth("foo", "bar", "baz", "testserver", false),
|
||||||
[]string{},
|
[]string{},
|
||||||
"PLAIN",
|
"PLAIN",
|
||||||
[]string{"foo\x00bar\x00baz"},
|
[]string{"foo\x00bar\x00baz"},
|
||||||
|
@ -66,7 +74,7 @@ var authTests = []authTest{
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
PlainAuth("foo", "bar", "baz", "testserver"),
|
PlainAuth("foo", "bar", "baz", "testserver", false),
|
||||||
[]string{"foo"},
|
[]string{"foo"},
|
||||||
"PLAIN",
|
"PLAIN",
|
||||||
[]string{"foo\x00bar\x00baz", ""},
|
[]string{"foo\x00bar\x00baz", ""},
|
||||||
|
@ -74,7 +82,7 @@ var authTests = []authTest{
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
LoginAuth("user", "pass", "testserver"),
|
LoginAuth("user", "pass", "testserver", false),
|
||||||
[]string{"Username:", "Password:"},
|
[]string{"Username:", "Password:"},
|
||||||
"LOGIN",
|
"LOGIN",
|
||||||
[]string{"", "user", "pass"},
|
[]string{"", "user", "pass"},
|
||||||
|
@ -82,7 +90,15 @@ var authTests = []authTest{
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
LoginAuth("user", "pass", "testserver"),
|
LoginAuth("user", "pass", "testserver", true),
|
||||||
|
[]string{"Username:", "Password:"},
|
||||||
|
"LOGIN",
|
||||||
|
[]string{"", "user", "pass"},
|
||||||
|
[]bool{false, false},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
LoginAuth("user", "pass", "testserver", false),
|
||||||
[]string{"User Name\x00", "Password\x00"},
|
[]string{"User Name\x00", "Password\x00"},
|
||||||
"LOGIN",
|
"LOGIN",
|
||||||
[]string{"", "user", "pass"},
|
[]string{"", "user", "pass"},
|
||||||
|
@ -90,7 +106,7 @@ var authTests = []authTest{
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
LoginAuth("user", "pass", "testserver"),
|
LoginAuth("user", "pass", "testserver", false),
|
||||||
[]string{"Invalid", "Invalid:"},
|
[]string{"Invalid", "Invalid:"},
|
||||||
"LOGIN",
|
"LOGIN",
|
||||||
[]string{"", "user", "pass"},
|
[]string{"", "user", "pass"},
|
||||||
|
@ -98,7 +114,7 @@ var authTests = []authTest{
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
LoginAuth("user", "pass", "testserver"),
|
LoginAuth("user", "pass", "testserver", false),
|
||||||
[]string{"Invalid", "Invalid:", "Too many"},
|
[]string{"Invalid", "Invalid:", "Too many"},
|
||||||
"LOGIN",
|
"LOGIN",
|
||||||
[]string{"", "user", "pass", ""},
|
[]string{"", "user", "pass", ""},
|
||||||
|
@ -237,7 +253,7 @@ func TestAuthPlain(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
auth := PlainAuth("foo", "bar", "baz", tt.authName)
|
auth := PlainAuth("foo", "bar", "baz", tt.authName, false)
|
||||||
_, _, err := auth.Start(tt.server)
|
_, _, err := auth.Start(tt.server)
|
||||||
got := ""
|
got := ""
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -283,7 +299,7 @@ func TestAuthLogin(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
auth := LoginAuth("foo", "bar", tt.authName)
|
auth := LoginAuth("foo", "bar", tt.authName, false)
|
||||||
_, _, err := auth.Start(tt.server)
|
_, _, err := auth.Start(tt.server)
|
||||||
got := ""
|
got := ""
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -707,7 +723,7 @@ func TestBasic(t *testing.T) {
|
||||||
// fake TLS so authentication won't complain
|
// fake TLS so authentication won't complain
|
||||||
c.tls = true
|
c.tls = true
|
||||||
c.serverName = "smtp.google.com"
|
c.serverName = "smtp.google.com"
|
||||||
if err := c.Auth(PlainAuth("", "user", "pass", "smtp.google.com")); err != nil {
|
if err := c.Auth(PlainAuth("", "user", "pass", "smtp.google.com", false)); err != nil {
|
||||||
t.Fatalf("AUTH failed: %s", err)
|
t.Fatalf("AUTH failed: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1278,7 +1294,7 @@ func TestHello(t *testing.T) {
|
||||||
case 3:
|
case 3:
|
||||||
c.tls = true
|
c.tls = true
|
||||||
c.serverName = "smtp.google.com"
|
c.serverName = "smtp.google.com"
|
||||||
err = c.Auth(PlainAuth("", "user", "pass", "smtp.google.com"))
|
err = c.Auth(PlainAuth("", "user", "pass", "smtp.google.com", false))
|
||||||
case 4:
|
case 4:
|
||||||
err = c.Mail("test@example.com")
|
err = c.Mail("test@example.com")
|
||||||
case 5:
|
case 5:
|
||||||
|
@ -1523,7 +1539,7 @@ func TestSendMailWithAuth(t *testing.T) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = SendMail(l.Addr().String(), PlainAuth("", "user", "pass", "smtp.google.com"), "test@example.com", []string{"other@example.com"}, []byte(strings.Replace(`From: test@example.com
|
err = SendMail(l.Addr().String(), PlainAuth("", "user", "pass", "smtp.google.com", false), "test@example.com", []string{"other@example.com"}, []byte(strings.Replace(`From: test@example.com
|
||||||
To: other@example.com
|
To: other@example.com
|
||||||
Subject: SendMail test
|
Subject: SendMail test
|
||||||
|
|
||||||
|
@ -1558,7 +1574,7 @@ func TestAuthFailed(t *testing.T) {
|
||||||
|
|
||||||
c.tls = true
|
c.tls = true
|
||||||
c.serverName = "smtp.google.com"
|
c.serverName = "smtp.google.com"
|
||||||
err = c.Auth(PlainAuth("", "user", "pass", "smtp.google.com"))
|
err = c.Auth(PlainAuth("", "user", "pass", "smtp.google.com", false))
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("Auth: expected error; got none")
|
t.Error("Auth: expected error; got none")
|
||||||
|
|
Loading…
Reference in a new issue