2021-01-04 10:28:55 +00:00
|
|
|
package notification
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
2021-08-11 01:04:35 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
2022-07-18 00:56:09 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/templates"
|
2021-01-04 10:28:55 +00:00
|
|
|
)
|
|
|
|
|
2021-11-30 11:15:21 +00:00
|
|
|
func TestShouldConfigureSMTPNotifierWithTLS11(t *testing.T) {
|
2021-01-04 10:28:55 +00:00
|
|
|
config := &schema.NotifierConfiguration{
|
|
|
|
DisableStartupCheck: true,
|
|
|
|
SMTP: &schema.SMTPNotifierConfiguration{
|
|
|
|
Host: "smtp.example.com",
|
|
|
|
Port: 25,
|
|
|
|
TLS: &schema.TLSConfig{
|
2021-11-30 11:15:21 +00:00
|
|
|
ServerName: "smtp.example.com",
|
2022-10-21 08:41:33 +00:00
|
|
|
MinimumVersion: schema.TLSVersion{Value: tls.VersionTLS11},
|
2021-01-04 10:28:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-07-18 00:56:09 +00:00
|
|
|
notifier := NewSMTPNotifier(config.SMTP, nil, &templates.Provider{})
|
2021-01-04 10:28:55 +00:00
|
|
|
|
|
|
|
assert.Equal(t, "smtp.example.com", notifier.tlsConfig.ServerName)
|
|
|
|
assert.Equal(t, uint16(tls.VersionTLS11), notifier.tlsConfig.MinVersion)
|
|
|
|
assert.False(t, notifier.tlsConfig.InsecureSkipVerify)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShouldConfigureSMTPNotifierWithServerNameOverrideAndDefaultTLS12(t *testing.T) {
|
|
|
|
config := &schema.NotifierConfiguration{
|
|
|
|
DisableStartupCheck: true,
|
|
|
|
SMTP: &schema.SMTPNotifierConfiguration{
|
|
|
|
Host: "smtp.example.com",
|
|
|
|
Port: 25,
|
|
|
|
TLS: &schema.TLSConfig{
|
|
|
|
ServerName: "smtp.golang.org",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-07-18 00:56:09 +00:00
|
|
|
notifier := NewSMTPNotifier(config.SMTP, nil, &templates.Provider{})
|
2021-01-04 10:28:55 +00:00
|
|
|
|
|
|
|
assert.Equal(t, "smtp.golang.org", notifier.tlsConfig.ServerName)
|
|
|
|
assert.Equal(t, uint16(tls.VersionTLS12), notifier.tlsConfig.MinVersion)
|
|
|
|
assert.False(t, notifier.tlsConfig.InsecureSkipVerify)
|
|
|
|
}
|