-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Unify (most) SMTP client calls
To send mails, today some tests use msmtp and others our internal smtpc.py. This works, but msmtp slows down the tests significantly, and smtpc.py is also not particularly fast, and also has some limitations. This patch introduces a new SMTP client tool written in Go, and makes almost all the tests use it. Some tests still remain on msmtp, mainly for client-check compatibility. It's likely that this will be moved in later patches to a separate special-purpose test. With this patch, integration tests take ~20% less time than before.
Showing
54 changed files
with
282 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
addr localhost:1465 | ||
server_cert config/certs/srv-chasquid/fullchain.pem | ||
user user@srv-chasquid | ||
password secretpassword |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
From: user@testserver | ||
Subject: Prueba desde el test | ||
|
||
Crece desde el test el futuro | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
addr localhost:1465 | ||
server_cert config/certs/testserver/fullchain.pem | ||
user user@testserver | ||
password secretpassword |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
addr localhost:1465 | ||
server_cert config/certs/testserver/fullchain.pem | ||
user user@testserver | ||
password secretpassword |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
addr localhost:1465 | ||
server_cert A/certs/srv-A/fullchain.pem | ||
user userA@srv-A | ||
password userA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
addr localhost:1465 | ||
server_cert config/certs/testserver/fullchain.pem | ||
user user@testserver | ||
password secretpassword |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
From: user@srv | ||
Subject: Prueba desde el test | ||
|
||
Crece desde el test el futuro | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
addr localhost:1465 | ||
server_cert config/certs/srv/fullchain.pem | ||
user user@srv | ||
password password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
addr localhost:1465 | ||
server_cert config/certs/testserver/fullchain.pem | ||
user someone@testserver | ||
password password222 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
addr localhost:1465 | ||
server_cert A/certs/srv-A/fullchain.pem | ||
user userA@srv-A | ||
password userA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
addr localhost:1465 | ||
server_cert A/certs/srv-A/fullchain.pem | ||
user userA@srv-A | ||
password userA |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
addr localhost:1465 | ||
server_cert config/certs/testserver/fullchain.pem | ||
user user@testserver | ||
password secretpassword |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"crypto/tls" | ||
"crypto/x509" | ||
"encoding/pem" | ||
"errors" | ||
"flag" | ||
"io" | ||
"net" | ||
"net/smtp" | ||
"os" | ||
"strings" | ||
) | ||
|
||
var ( | ||
addr = flag.String("addr", "", "Address of the SMTP server") | ||
|
||
user = flag.String("user", "", "Username to use in SMTP AUTH") | ||
password = flag.String("password", "", "Password to use in SMTP AUTH") | ||
|
||
from = flag.String("from", "", "From address to use in the message") | ||
|
||
serverCert = flag.String("server_cert", "", | ||
"Path to the server certificate to expect") | ||
|
||
confPath = flag.String("c", "smtpc.conf", | ||
"Path to the configuration file") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
loadConfig() | ||
|
||
// Read message from stdin. | ||
rawMsg, err := io.ReadAll(os.Stdin) | ||
notnil(err) | ||
|
||
// RCPT TO from the command line. | ||
tos := make([]string, len(flag.Args())) | ||
for i, to := range flag.Args() { | ||
tos[i] = to | ||
} | ||
|
||
// Connect to the server. | ||
var conn net.Conn | ||
if *serverCert != "" { | ||
cert := loadCert(*serverCert) | ||
rootCAs := x509.NewCertPool() | ||
|
||
rootCAs.AddCert(cert) | ||
tlsConfig := &tls.Config{ | ||
ServerName: cert.DNSNames[0], | ||
RootCAs: rootCAs, | ||
} | ||
|
||
conn, err = tls.Dial("tcp", *addr, tlsConfig) | ||
defer conn.Close() | ||
} else { | ||
conn, err = net.Dial("tcp", *addr) | ||
} | ||
notnil(err) | ||
|
||
// Send the message. | ||
client, err := smtp.NewClient(conn, *addr) | ||
notnil(err) | ||
|
||
if *user != "" { | ||
auth := smtp.PlainAuth("", *user, *password, *addr) | ||
err = client.Auth(auth) | ||
notnil(err) | ||
} | ||
|
||
if *from == "" { | ||
*from = *user | ||
} | ||
err = client.Mail(*from) | ||
notnil(err) | ||
|
||
for _, to := range tos { | ||
err = client.Rcpt(to) | ||
notnil(err) | ||
} | ||
|
||
w, err := client.Data() | ||
notnil(err) | ||
_, err = io.Copy(w, bytes.NewReader(rawMsg)) | ||
notnil(err) | ||
err = w.Close() | ||
notnil(err) | ||
|
||
err = client.Quit() | ||
notnil(err) | ||
} | ||
|
||
func loadConfig() { | ||
data, err := os.ReadFile(*confPath) | ||
if errors.Is(err, os.ErrNotExist) { | ||
return | ||
} | ||
notnil(err) | ||
|
||
for _, line := range strings.Split(string(data), "\n") { | ||
k, v, ok := strings.Cut(line, " ") | ||
if !ok { | ||
continue | ||
} | ||
|
||
k = strings.TrimSpace(k) | ||
|
||
// Set the flag but only if it wasn't already set. | ||
// Command-line flags take precedence. | ||
isSet := false | ||
flag.Visit(func(f *flag.Flag) { | ||
if f.Name == k { | ||
isSet = true | ||
} | ||
}) | ||
if !isSet { | ||
flag.Lookup(k).Value.Set(strings.TrimSpace(v)) | ||
} | ||
} | ||
} | ||
|
||
func loadCert(path string) *x509.Certificate { | ||
data, err := os.ReadFile(path) | ||
notnil(err) | ||
|
||
block, _ := pem.Decode(data) | ||
|
||
cert, err := x509.ParseCertificate(block.Bytes) | ||
notnil(err) | ||
|
||
return cert | ||
} | ||
|
||
func notnil(err error) { | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |