mirror of
https://github.com/hanzoai/mail.git
synced 2026-09-23 23:53:02 +00:00
Fork of github.com/mjl-/mox at 5656ca6d1b
(upstream v0.0.15 plus 55 commits).
Rename the module path in go.mod and the import paths in 268 Go files. Also
update the five scripts that "go install" the module (genwebsite.sh,
docker-release.sh, apidiff.sh, test-upgrade.sh, Dockerfile.release), which
would otherwise build upstream rather than this fork.
Add NOTICE recording the upstream project, author, license, and fork point,
and stating which license covers which files: MIT for the mox source and our
changes, MPL-2.0 for publicsuffix/public_suffix_list.txt alone, and the
vendored dependencies' own licenses under licenses/. Embed NOTICE so
"mail licenses" prints the lineage from the running binary. LICENSE.MIT,
LICENSE.MPLv2.0 and the licenses/ tree are preserved verbatim; no code is
relicensed.
The mox command name, config keys, data directory layout and website content
are unchanged. LLM.md records the fork point, the rename, what was left alone,
and the steps to stand the server up.
Co-authored-by: Hanzo Dev <[email protected]>
58 lines
2.0 KiB
Go
58 lines
2.0 KiB
Go
package smtpclient
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"reflect"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/hanzoai/mail/dns"
|
|
"github.com/hanzoai/mail/mlog"
|
|
)
|
|
|
|
func TestDialHost(t *testing.T) {
|
|
// We mostly want to test that dialing a second time switches to the other address family.
|
|
ctxbg := context.Background()
|
|
log := mlog.New("smtpclient", nil)
|
|
|
|
resolver := dns.MockResolver{
|
|
A: map[string][]string{
|
|
"dualstack.example.": {"10.0.0.1"},
|
|
},
|
|
AAAA: map[string][]string{
|
|
"dualstack.example.": {"2001:db8::1"},
|
|
},
|
|
}
|
|
|
|
DialHook = func(ctx context.Context, dialer Dialer, timeout time.Duration, addr string, laddr net.Addr) (net.Conn, error) {
|
|
return nil, nil // No error, nil connection isn't used.
|
|
}
|
|
defer func() {
|
|
DialHook = nil
|
|
}()
|
|
|
|
ipdomain := func(s string) dns.IPDomain {
|
|
return dns.IPDomain{Domain: dns.Domain{ASCII: s}}
|
|
}
|
|
|
|
dialedIPs := map[string][]net.IP{}
|
|
_, _, _, ips, dualstack, err := GatherIPs(ctxbg, log.Logger, resolver, "ip", ipdomain("dualstack.example"), dialedIPs)
|
|
if err != nil || !reflect.DeepEqual(ips, []net.IP{net.ParseIP("10.0.0.1"), net.ParseIP("2001:db8::1")}) || !dualstack {
|
|
t.Fatalf("expected err nil, address 10.0.0.1,2001:db8::1, dualstack true, got %v %v %v", err, ips, dualstack)
|
|
}
|
|
_, ip, err := Dial(ctxbg, log.Logger, nil, ipdomain("dualstack.example"), ips, 25, dialedIPs, nil)
|
|
if err != nil || ip.String() != "10.0.0.1" {
|
|
t.Fatalf("expected err nil, address 10.0.0.1, dualstack true, got %v %v %v", err, ip, dualstack)
|
|
}
|
|
|
|
_, _, _, ips, dualstack, err = GatherIPs(ctxbg, log.Logger, resolver, "ip", ipdomain("dualstack.example"), dialedIPs)
|
|
if err != nil || !reflect.DeepEqual(ips, []net.IP{net.ParseIP("2001:db8::1"), net.ParseIP("10.0.0.1")}) || !dualstack {
|
|
t.Fatalf("expected err nil, address 2001:db8::1,10.0.0.1, dualstack true, got %v %v %v", err, ips, dualstack)
|
|
}
|
|
_, ip, err = Dial(ctxbg, log.Logger, nil, ipdomain("dualstack.example"), ips, 25, dialedIPs, nil)
|
|
if err != nil || ip.String() != "2001:db8::1" {
|
|
t.Fatalf("expected err nil, address 2001:db8::1, dualstack true, got %v %v %v", err, ip, dualstack)
|
|
}
|
|
}
|