mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 22:00:49 +01:00
Merge pull request #193 from wneessen/implement_fuzzing
Implement fuzzing
This commit is contained in:
commit
11258613d5
3 changed files with 48 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -55,3 +55,5 @@ com_crashlytics_export_strings.xml
|
||||||
crashlytics.properties
|
crashlytics.properties
|
||||||
crashlytics-build.properties
|
crashlytics-build.properties
|
||||||
fabric.properties
|
fabric.properties
|
||||||
|
|
||||||
|
testdata
|
|
@ -5,6 +5,7 @@
|
||||||
package mail
|
package mail
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -461,3 +462,20 @@ func (e errorWriter) Write([]byte) (int, error) {
|
||||||
func (e errorWriter) Close() error {
|
func (e errorWriter) Close() error {
|
||||||
return fmt.Errorf("supposed to always fail")
|
return fmt.Errorf("supposed to always fail")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FuzzBase64LineBreaker_Write(f *testing.F) {
|
||||||
|
f.Add([]byte("abc"))
|
||||||
|
f.Add([]byte("def"))
|
||||||
|
f.Add([]uint8{0o0, 0o1, 0o2, 30, 255})
|
||||||
|
buf := bytes.Buffer{}
|
||||||
|
bw := bufio.NewWriter(&buf)
|
||||||
|
f.Fuzz(func(t *testing.T, data []byte) {
|
||||||
|
b := &Base64LineBreaker{out: bw}
|
||||||
|
if _, err := b.Write(data); err != nil {
|
||||||
|
t.Errorf("failed to write to B64LineBreaker: %s", err)
|
||||||
|
}
|
||||||
|
if err := b.Close(); err != nil {
|
||||||
|
t.Errorf("failed to close B64LineBreaker: %s", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
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)
|
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