mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 13:50:49 +01:00
Fix potential null pointer exceptions in msg_test.go
Added robustness and improved error handling in msg_test.go by adding null checks before calling values from the genHeader map in RequestMDNTo and related functions. This enhancement was necessary to avoid the operations on non-existing keys and potential null pointer exceptions.
This commit is contained in:
parent
fb17547e69
commit
ddcad3710d
1 changed files with 15 additions and 9 deletions
24
msg_test.go
24
msg_test.go
|
@ -1135,9 +1135,11 @@ func TestMsg_RequestMDN(t *testing.T) {
|
||||||
if err := m.RequestMDNTo(v); err != nil {
|
if err := m.RequestMDNTo(v); err != nil {
|
||||||
t.Errorf("RequestMDNTo with a single valid address failed: %s", err)
|
t.Errorf("RequestMDNTo with a single valid address failed: %s", err)
|
||||||
}
|
}
|
||||||
if m.genHeader[HeaderDispositionNotificationTo][0] != fmt.Sprintf("<%s>", v) {
|
if val := m.genHeader[HeaderDispositionNotificationTo]; val != nil && len(val) > 1 {
|
||||||
t.Errorf("RequestMDNTo with a single valid address failed. Expected: %s, got: %s", v,
|
if val[0] != fmt.Sprintf("<%s>", v) {
|
||||||
m.genHeader[HeaderDispositionNotificationTo][0])
|
t.Errorf("RequestMDNTo with a single valid address failed. Expected: %s, got: %s", v,
|
||||||
|
val[0])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m.Reset()
|
m.Reset()
|
||||||
|
|
||||||
|
@ -1145,13 +1147,17 @@ func TestMsg_RequestMDN(t *testing.T) {
|
||||||
if err := m.RequestMDNTo(vl...); err != nil {
|
if err := m.RequestMDNTo(vl...); err != nil {
|
||||||
t.Errorf("RequestMDNTo with a multiple valid address failed: %s", err)
|
t.Errorf("RequestMDNTo with a multiple valid address failed: %s", err)
|
||||||
}
|
}
|
||||||
if m.genHeader[HeaderDispositionNotificationTo][0] != fmt.Sprintf("<%s>", v) {
|
if val := m.genHeader[HeaderDispositionNotificationTo]; val != nil && len(val) > 0 {
|
||||||
t.Errorf("RequestMDNTo with a multiple valid addresses failed. Expected 0: %s, got 0: %s", v,
|
if val[0] != fmt.Sprintf("<%s>", v) {
|
||||||
m.genHeader[HeaderDispositionNotificationTo][0])
|
t.Errorf("RequestMDNTo with a multiple valid addresses failed. Expected 0: %s, got 0: %s", v,
|
||||||
|
val[0])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if m.genHeader[HeaderDispositionNotificationTo][1] != fmt.Sprintf("<%s>", v2) {
|
if val := m.genHeader[HeaderDispositionNotificationTo]; val != nil && len(val) > 1 {
|
||||||
t.Errorf("RequestMDNTo with a multiple valid addresses failed. Expected 1: %s, got 1: %s", v2,
|
if val[1] != fmt.Sprintf("<%s>", v2) {
|
||||||
m.genHeader[HeaderDispositionNotificationTo][1])
|
t.Errorf("RequestMDNTo with a multiple valid addresses failed. Expected 1: %s, got 1: %s", v2,
|
||||||
|
val[1])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m.Reset()
|
m.Reset()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue