mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-01-09 17:55:57 +00:00
smtpsrv: Improve "Received" header standard compliance
Despite its loose appearance, the "Received" header has a reasonably standarized format. We were not following the standard format as closely as we should; this rarely causes problems in this particular case, but there's no need to deviate from it. This patch changes the Received header generation as follows: - The "from" section now uses the remote address as canonical (for non-authenticated users) which provides more valuable information than the user-supplied EHLO address (which is also included). - The remote authenticated user is now hidden, for additional privacy. - Use the "with" optional clause. - Use the standard way of printing TLS cipher suite. - Use the standard way of printing address literals.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package smtpsrv
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"blitiri.com.ar/go/chasquid/internal/domaininfo"
|
||||
@@ -77,3 +78,41 @@ func TestIsHeader(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddrLiteral(t *testing.T) {
|
||||
// TCP addresses.
|
||||
casesTCP := []struct {
|
||||
addr net.IP
|
||||
expected string
|
||||
}{
|
||||
{net.IPv4(1, 2, 3, 4), "1.2.3.4"},
|
||||
{net.IPv4(0, 0, 0, 0), "0.0.0.0"},
|
||||
{net.ParseIP("1.2.3.4"), "1.2.3.4"},
|
||||
{net.ParseIP("2001:db8::68"), "IPv6:2001:db8::68"},
|
||||
{net.ParseIP("::1"), "IPv6:::1"},
|
||||
}
|
||||
for _, c := range casesTCP {
|
||||
tcp := &net.TCPAddr{
|
||||
IP: c.addr,
|
||||
Port: 12345,
|
||||
}
|
||||
s := addrLiteral(tcp)
|
||||
if s != c.expected {
|
||||
t.Errorf("%v: expected %q, got %q", tcp, c.expected, s)
|
||||
}
|
||||
}
|
||||
|
||||
// Non-TCP addresses. We expect these to match addr.String().
|
||||
casesOther := []net.Addr{
|
||||
&net.UDPAddr{
|
||||
IP: net.ParseIP("1.2.3.4"),
|
||||
Port: 12345,
|
||||
},
|
||||
}
|
||||
for _, addr := range casesOther {
|
||||
s := addrLiteral(addr)
|
||||
if s != addr.String() {
|
||||
t.Errorf("%v: expected %q, got %q", addr, addr.String(), s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user