2
0

main_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package main
  2. import (
  3. "testing"
  4. )
  5. func TestAddrAllowedNoDomain(t *testing.T) {
  6. allowedAddrs := []string{"[email protected]"}
  7. if addrAllowed("bob.com", allowedAddrs) {
  8. t.FailNow()
  9. }
  10. }
  11. func TestAddrAllowedSingle(t *testing.T) {
  12. allowedAddrs := []string{"[email protected]"}
  13. if !addrAllowed("[email protected]", allowedAddrs) {
  14. t.FailNow()
  15. }
  16. if addrAllowed("[email protected]", allowedAddrs) {
  17. t.FailNow()
  18. }
  19. }
  20. func TestAddrAllowedDifferentCase(t *testing.T) {
  21. allowedAddrs := []string{"[email protected]"}
  22. testAddrs := []string{
  23. "[email protected]",
  24. "[email protected]",
  25. "[email protected]",
  26. "[email protected]",
  27. }
  28. for _, addr := range testAddrs {
  29. if !addrAllowed(addr, allowedAddrs) {
  30. t.Errorf("Address %v not allowed, but should be", addr)
  31. }
  32. }
  33. }
  34. func TestAddrAllowedLocal(t *testing.T) {
  35. allowedAddrs := []string{"joe"}
  36. if !addrAllowed("joe", allowedAddrs) {
  37. t.FailNow()
  38. }
  39. if addrAllowed("bob", allowedAddrs) {
  40. t.FailNow()
  41. }
  42. }
  43. func TestAddrAllowedMulti(t *testing.T) {
  44. allowedAddrs := []string{"[email protected]", "[email protected]"}
  45. if !addrAllowed("[email protected]", allowedAddrs) {
  46. t.FailNow()
  47. }
  48. if !addrAllowed("[email protected]", allowedAddrs) {
  49. t.FailNow()
  50. }
  51. if addrAllowed("[email protected]", allowedAddrs) {
  52. t.FailNow()
  53. }
  54. }
  55. func TestAddrAllowedSingleDomain(t *testing.T) {
  56. allowedAddrs := []string{"@abc.com"}
  57. if !addrAllowed("[email protected]", allowedAddrs) {
  58. t.FailNow()
  59. }
  60. if addrAllowed("[email protected]", allowedAddrs) {
  61. t.FailNow()
  62. }
  63. }
  64. func TestAddrAllowedMixed(t *testing.T) {
  65. allowedAddrs := []string{"app", "[email protected]", "@appsrv.example.com"}
  66. if !addrAllowed("app", allowedAddrs) {
  67. t.FailNow()
  68. }
  69. if !addrAllowed("[email protected]", allowedAddrs) {
  70. t.FailNow()
  71. }
  72. if addrAllowed("[email protected]", allowedAddrs) {
  73. t.FailNow()
  74. }
  75. if !addrAllowed("[email protected]", allowedAddrs) {
  76. t.FailNow()
  77. }
  78. if !addrAllowed("[email protected]", allowedAddrs) {
  79. t.FailNow()
  80. }
  81. if addrAllowed("[email protected]", allowedAddrs) {
  82. t.FailNow()
  83. }
  84. }