1
0

check_valid_test.go 648 B

1234567891011121314151617181920212223242526272829
  1. package entity
  2. import "testing"
  3. func TestCheckValidSmtpFrom(t *testing.T) {
  4. base := func() *AllSetting {
  5. return &AllSetting{WebPort: 2053, SubPort: 2096}
  6. }
  7. for _, v := range []string{"", "[email protected]"} {
  8. s := base()
  9. s.SmtpFrom = v
  10. if err := s.CheckValid(); err != nil {
  11. t.Errorf("CheckValid with smtpFrom=%q: unexpected error %v", v, err)
  12. }
  13. }
  14. for _, v := range []string{
  15. "not-an-address",
  16. "[email protected]\r\nBcc: [email protected]",
  17. "a@b\nSubject: injected",
  18. } {
  19. s := base()
  20. s.SmtpFrom = v
  21. if err := s.CheckValid(); err == nil {
  22. t.Errorf("CheckValid with smtpFrom=%q: want error, got nil", v)
  23. }
  24. }
  25. }