mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-10-28 15:02:28 +00:00
queue: Fix inverted logic in mustIDNAToASCII
In mustIDNAToASCII, we accidentally return the unconverted domain on success, and the failed conversion on error. This affects the sender rewriting when forwarding, and can only be triggered via aliases in local IDN domains. This patch fixes the problem by adjusting the logic, and adds tests to prevent future regressions.
This commit is contained in:
@@ -524,9 +524,9 @@ func nextDelay(createdAt time.Time) time.Duration {
|
||||
func mustIDNAToASCII(s string) string {
|
||||
a, err := idna.ToASCII(s)
|
||||
if err != nil {
|
||||
return a
|
||||
return s
|
||||
}
|
||||
return s
|
||||
return a
|
||||
}
|
||||
|
||||
func timeFromProto(ts *Timestamp) time.Time {
|
||||
|
||||
@@ -201,6 +201,27 @@ func TestAliases(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestRewriteSender(t *testing.T) {
|
||||
cases := []struct {
|
||||
from, originalAddr, expected string
|
||||
}{
|
||||
{"from@rana", "remote@loco", "remote+fwd_from=from=rana@loco"},
|
||||
|
||||
// The domain of the original address is converted to ASCII.
|
||||
{"from@rana", "remote@ñoño", "remote+fwd_from=from=rana@xn--oo-yjab"},
|
||||
|
||||
// If the conversion fails, the domain is left as-is.
|
||||
{"from@rana", "remote@xn---", "remote+fwd_from=from=rana@xn---"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := rewriteSender(c.from, c.originalAddr)
|
||||
if got != c.expected {
|
||||
t.Errorf("rewriteSender(%q, %q) = %q, expected %q",
|
||||
c.from, c.originalAddr, got, c.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFullQueue(t *testing.T) {
|
||||
synctest.Test(t, func(t *testing.T) {
|
||||
dir := t.ArtifactDir()
|
||||
|
||||
Reference in New Issue
Block a user