package auth import "testing" // TestEnvelopeFrom guards the "501 Bad sender address syntax" regression: // SMTP_FROM may carry a display name for the From: header, but the SMTP // envelope sender (MAIL FROM) must be a bare address. func TestEnvelopeFrom(t *testing.T) { cases := []struct { name string from string want string }{ {"display name + unicode", "穿山甲 ", "noreply@mail.51yanmei.com"}, {"display name ascii", "Pangolin ", "no-reply@pangolin.app"}, {"bare address", "no-reply@pangolin.app", "no-reply@pangolin.app"}, {"angle only", "", "noreply@mail.51yanmei.com"}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { m := NewSMTPMailer(SMTPConfig{From: tc.from}) if got := m.envelopeFrom(); got != tc.want { t.Fatalf("envelopeFrom(%q) = %q, want %q", tc.from, got, tc.want) } }) } } // TestMaskEmail verifies error-log masking never leaks a full address. func TestMaskEmail(t *testing.T) { cases := map[string]string{ "chenxin880812@gmail.com": "ch***@gmail.com", "ab@x.com": "***@x.com", "a@x.com": "***@x.com", "not-an-email": "***", } for in, want := range cases { if got := maskEmail(in); got != want { t.Errorf("maskEmail(%q) = %q, want %q", in, got, want) } } }