check_valid_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. }
  26. func TestCheckValidWildcardListenPortConflict(t *testing.T) {
  27. s := &AllSetting{WebPort: 2053, SubPort: 2053, WebListen: "0.0.0.0", SubListen: ""}
  28. if err := s.CheckValid(); err == nil {
  29. t.Error("CheckValid must reject the same port bound on 0.0.0.0 and \"\" (both wildcard)")
  30. }
  31. ok := &AllSetting{WebPort: 2053, SubPort: 2053, WebListen: "127.0.0.1", SubListen: "192.168.1.1"}
  32. if err := ok.CheckValid(); err != nil {
  33. t.Errorf("distinct specific listens on the same port should be allowed: %v", err)
  34. }
  35. }