mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-18 17:00:38 +01:00
Add SCRAM-SHA1-PLUS authentication tests
Introduced two new unit tests for SCRAM-SHA1-PLUS authentication with TLS exporter and TLS unique options. These tests ensure proper client creation, connection, and disconnection processes are functioning as expected in online environments.
This commit is contained in:
parent
27838f5b1f
commit
e8f3c444e6
1 changed files with 50 additions and 0 deletions
|
@ -1836,6 +1836,56 @@ func TestClient_DialSendConcurrent_local(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestClient_AuthSCRAMSHA1PLUS_tlsexporter(t *testing.T) {
|
||||
if os.Getenv("TEST_ONLINE_SCRAM") == "" {
|
||||
t.Skipf("TEST_ONLINE_SCRAM is not set. Skipping online SCRAM tests")
|
||||
}
|
||||
hostname := os.Getenv("TEST_HOST_SCRAM")
|
||||
username := os.Getenv("TEST_USER_SCRAM")
|
||||
password := os.Getenv("TEST_PASS_SCRAM")
|
||||
|
||||
client, err := NewClient(hostname, WithTLSPortPolicy(TLSMandatory),
|
||||
WithSMTPAuth(SMTPAuthSCRAMSHA1PLUS),
|
||||
WithUsername(username), WithPassword(password))
|
||||
if err != nil {
|
||||
t.Errorf("unable to create new client: %s", err)
|
||||
return
|
||||
}
|
||||
if err = client.DialWithContext(context.Background()); err != nil {
|
||||
t.Errorf("failed to dial to test server: %s", err)
|
||||
}
|
||||
if err = client.Close(); err != nil {
|
||||
t.Errorf("failed to close server connection: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClient_AuthSCRAMSHA1PLUS_tlsunique(t *testing.T) {
|
||||
if os.Getenv("TEST_ONLINE_SCRAM") == "" {
|
||||
t.Skipf("TEST_ONLINE_SCRAM is not set. Skipping online SCRAM tests")
|
||||
}
|
||||
hostname := os.Getenv("TEST_HOST_SCRAM")
|
||||
username := os.Getenv("TEST_USER_SCRAM")
|
||||
password := os.Getenv("TEST_PASS_SCRAM")
|
||||
|
||||
tlsConfig := &tls.Config{}
|
||||
tlsConfig.MaxVersion = tls.VersionTLS12
|
||||
tlsConfig.ServerName = hostname
|
||||
client, err := NewClient(hostname, WithTLSPortPolicy(TLSMandatory),
|
||||
WithTLSConfig(tlsConfig),
|
||||
WithSMTPAuth(SMTPAuthSCRAMSHA1PLUS),
|
||||
WithUsername(username), WithPassword(password))
|
||||
if err != nil {
|
||||
t.Errorf("unable to create new client: %s", err)
|
||||
return
|
||||
}
|
||||
if err = client.DialWithContext(context.Background()); err != nil {
|
||||
t.Errorf("failed to dial to test server: %s", err)
|
||||
}
|
||||
if err = client.Close(); err != nil {
|
||||
t.Errorf("failed to close server connection: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// getTestConnection takes environment variables to establish a connection to a real
|
||||
// SMTP server to test all functionality that requires a connection
|
||||
func getTestConnection(auth bool) (*Client, error) {
|
||||
|
|
Loading…
Reference in a new issue