|
@ -17,7 +17,7 @@ func Test_findRecipient(t *testing.T) { |
|
|
} |
|
|
} |
|
|
t.Run("No recipient specified", func(t *testing.T) { |
|
|
t.Run("No recipient specified", func(t *testing.T) { |
|
|
prepare() |
|
|
prepare() |
|
|
values := FormValues{} |
|
|
|
|
|
|
|
|
values := &FormValues{} |
|
|
result := findRecipient(values) |
|
|
result := findRecipient(values) |
|
|
if result != "mail@example.com" { |
|
|
if result != "mail@example.com" { |
|
|
t.Error() |
|
|
t.Error() |
|
@ -25,7 +25,7 @@ func Test_findRecipient(t *testing.T) { |
|
|
}) |
|
|
}) |
|
|
t.Run("Multiple recipients specified", func(t *testing.T) { |
|
|
t.Run("Multiple recipients specified", func(t *testing.T) { |
|
|
prepare() |
|
|
prepare() |
|
|
values := FormValues{ |
|
|
|
|
|
|
|
|
values := &FormValues{ |
|
|
"_to": {"abc@example.com", "def@example.com"}, |
|
|
"_to": {"abc@example.com", "def@example.com"}, |
|
|
} |
|
|
} |
|
|
result := findRecipient(values) |
|
|
result := findRecipient(values) |
|
@ -35,7 +35,7 @@ func Test_findRecipient(t *testing.T) { |
|
|
}) |
|
|
}) |
|
|
t.Run("Allowed recipient specified", func(t *testing.T) { |
|
|
t.Run("Allowed recipient specified", func(t *testing.T) { |
|
|
prepare() |
|
|
prepare() |
|
|
values := FormValues{ |
|
|
|
|
|
|
|
|
values := &FormValues{ |
|
|
"_to": {"test@example.com"}, |
|
|
"_to": {"test@example.com"}, |
|
|
} |
|
|
} |
|
|
result := findRecipient(values) |
|
|
result := findRecipient(values) |
|
@ -45,7 +45,7 @@ func Test_findRecipient(t *testing.T) { |
|
|
}) |
|
|
}) |
|
|
t.Run("Forbidden recipient specified", func(t *testing.T) { |
|
|
t.Run("Forbidden recipient specified", func(t *testing.T) { |
|
|
prepare() |
|
|
prepare() |
|
|
values := FormValues{ |
|
|
|
|
|
|
|
|
values := &FormValues{ |
|
|
"_to": {"forbidden@example.com"}, |
|
|
"_to": {"forbidden@example.com"}, |
|
|
} |
|
|
} |
|
|
result := findRecipient(values) |
|
|
result := findRecipient(values) |
|
@ -57,17 +57,17 @@ func Test_findRecipient(t *testing.T) { |
|
|
|
|
|
|
|
|
func Test_findFormName(t *testing.T) { |
|
|
func Test_findFormName(t *testing.T) { |
|
|
t.Run("No form name", func(t *testing.T) { |
|
|
t.Run("No form name", func(t *testing.T) { |
|
|
if "a form" != findFormName(FormValues{}) { |
|
|
|
|
|
|
|
|
if "a form" != findFormName(&FormValues{}) { |
|
|
t.Error() |
|
|
t.Error() |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
t.Run("Multiple form names", func(t *testing.T) { |
|
|
t.Run("Multiple form names", func(t *testing.T) { |
|
|
if "a form" != findFormName(FormValues{"_formName": {"Test", "ABC"}}) { |
|
|
|
|
|
|
|
|
if "a form" != findFormName(&FormValues{"_formName": {"Test", "ABC"}}) { |
|
|
t.Error() |
|
|
t.Error() |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
t.Run("Form name", func(t *testing.T) { |
|
|
t.Run("Form name", func(t *testing.T) { |
|
|
if "Test" != findFormName(FormValues{"_formName": {"Test"}}) { |
|
|
|
|
|
|
|
|
if "Test" != findFormName(&FormValues{"_formName": {"Test"}}) { |
|
|
t.Error() |
|
|
t.Error() |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
@ -75,17 +75,17 @@ func Test_findFormName(t *testing.T) { |
|
|
|
|
|
|
|
|
func Test_findReplyTo(t *testing.T) { |
|
|
func Test_findReplyTo(t *testing.T) { |
|
|
t.Run("No replyTo", func(t *testing.T) { |
|
|
t.Run("No replyTo", func(t *testing.T) { |
|
|
if "" != findReplyTo(FormValues{}) { |
|
|
|
|
|
|
|
|
if "" != findReplyTo(&FormValues{}) { |
|
|
t.Error() |
|
|
t.Error() |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
t.Run("Multiple replyTo", func(t *testing.T) { |
|
|
t.Run("Multiple replyTo", func(t *testing.T) { |
|
|
if "" != findReplyTo(FormValues{"_replyTo": {"test@example.com", "test2@example.com"}}) { |
|
|
|
|
|
|
|
|
if "" != findReplyTo(&FormValues{"_replyTo": {"test@example.com", "test2@example.com"}}) { |
|
|
t.Error() |
|
|
t.Error() |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
t.Run("replyTo", func(t *testing.T) { |
|
|
t.Run("replyTo", func(t *testing.T) { |
|
|
if "test@example.com" != findReplyTo(FormValues{"_replyTo": {"test@example.com"}}) { |
|
|
|
|
|
|
|
|
if "test@example.com" != findReplyTo(&FormValues{"_replyTo": {"test@example.com"}}) { |
|
|
t.Error() |
|
|
t.Error() |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
@ -93,14 +93,14 @@ func Test_findReplyTo(t *testing.T) { |
|
|
|
|
|
|
|
|
func Test_removeMetaValues(t *testing.T) { |
|
|
func Test_removeMetaValues(t *testing.T) { |
|
|
t.Run("Remove meta values", func(t *testing.T) { |
|
|
t.Run("Remove meta values", func(t *testing.T) { |
|
|
result := removeMetaValues(FormValues{ |
|
|
|
|
|
|
|
|
result := removeMetaValues(&FormValues{ |
|
|
"_test": {"abc"}, |
|
|
"_test": {"abc"}, |
|
|
"test": {"def"}, |
|
|
"test": {"def"}, |
|
|
}) |
|
|
}) |
|
|
want := FormValues{ |
|
|
want := FormValues{ |
|
|
"test": {"def"}, |
|
|
"test": {"def"}, |
|
|
} |
|
|
} |
|
|
if !reflect.DeepEqual(result, want) { |
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(*result, want) { |
|
|
t.Error() |
|
|
t.Error() |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
@ -113,7 +113,7 @@ func Test_buildMessage(t *testing.T) { |
|
|
_ = os.Setenv("ALLOWED_TO", "mail@example.com,test@example.com") |
|
|
_ = os.Setenv("ALLOWED_TO", "mail@example.com,test@example.com") |
|
|
_ = os.Setenv("EMAIL_FROM", "forms@example.com") |
|
|
_ = os.Setenv("EMAIL_FROM", "forms@example.com") |
|
|
appConfig, _ = parseConfig() |
|
|
appConfig, _ = parseConfig() |
|
|
values := FormValues{ |
|
|
|
|
|
|
|
|
values := &FormValues{ |
|
|
"_formName": {"Testform"}, |
|
|
"_formName": {"Testform"}, |
|
|
"_replyTo": {"reply@example.com"}, |
|
|
"_replyTo": {"reply@example.com"}, |
|
|
"Testkey": {"Testvalue"}, |
|
|
"Testkey": {"Testvalue"}, |
|
@ -134,4 +134,4 @@ func Test_buildMessage(t *testing.T) { |
|
|
t.Error() |
|
|
t.Error() |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
} |
|
|
|
|
|
|
|
|
} |