mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-09 15:32:54 +01:00
Add fuzzing tests for subject and from fields in msg_test.go
Included two new fuzzing tests for 'Subject' and 'From' to increase code coverage and reliability. These tests expand our checking strategy by using dynamic inputs and making sure no unexpected errors occur when dealing with a variety of possible input scenarios.
This commit is contained in:
parent
91a3fc5261
commit
dae7d80759
1 changed files with 28 additions and 0 deletions
28
msg_test.go
28
msg_test.go
|
@ -3219,3 +3219,31 @@ func TestNewMsgWithNoDefaultUserAgent(t *testing.T) {
|
|||
t.Errorf("WithNoDefaultUserAgent() failed. Expected: %t, got: %t", true, false)
|
||||
}
|
||||
}
|
||||
|
||||
// Fuzzing tests
|
||||
func FuzzMsg_Subject(f *testing.F) {
|
||||
f.Add("Testsubject")
|
||||
f.Add("")
|
||||
f.Add("This is a longer test subject.")
|
||||
f.Add("Let's add some umlauts: üäöß")
|
||||
f.Add("Or even emojis: ☝️💪👍")
|
||||
f.Fuzz(func(t *testing.T, data string) {
|
||||
m := NewMsg()
|
||||
m.Subject(data)
|
||||
m.Reset()
|
||||
})
|
||||
}
|
||||
|
||||
func FuzzMsg_From(f *testing.F) {
|
||||
f.Add("Toni Tester <toni@tester.com>")
|
||||
f.Add("<tester@example.com>")
|
||||
f.Add("mail@server.com")
|
||||
f.Fuzz(func(t *testing.T, data string) {
|
||||
m := NewMsg()
|
||||
if err := m.From(data); err != nil &&
|
||||
!strings.Contains(err.Error(), "failed to parse mail address") {
|
||||
t.Errorf("failed set set FROM address: %s", err)
|
||||
}
|
||||
m.Reset()
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue