Skip to content

Commit

Permalink
fix(isSearched): replace regexp.MatchString by strings.Contains and r…
Browse files Browse the repository at this point in the history
…emove special characters from body fields

Signed-off-by: Tom ADELE <tom.adele@ovhcloud.com>
  • Loading branch information
tomadele committed Dec 9, 2022
1 parent cdf11ee commit 32d46c4
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions executors/imap/imap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"crypto/tls"
"fmt"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -310,8 +309,6 @@ func (Executor) GetDefaultAssertions() *venom.StepAssertions {

// Run execute TestStep of type exec
func (Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, error) {
venom.InitTestLogger("debug")

var e Executor
if err := mapstructure.Decode(step, &e); err != nil {
return nil, err
Expand Down Expand Up @@ -763,26 +760,31 @@ func (m *Mail) isSearched(mailToFind SearchCriteria) (bool, error) {
}
}
if mailToFind.From != "" {
matched, err = regexp.MatchString(mailToFind.From, m.From)
if err != nil || !matched {
matched = strings.Contains(m.From, mailToFind.From)
if !matched {
return false, err
}
}
if mailToFind.To != "" {
matched, err = regexp.MatchString(mailToFind.To, m.To)
if err != nil || !matched {
matched = strings.Contains(m.To, mailToFind.To)
if !matched {
return false, err
}
}
if mailToFind.Subject != "" {
matched, err = regexp.MatchString(mailToFind.Subject, m.Subject)
if err != nil || !matched {
matched = strings.Contains(m.Subject, mailToFind.Subject)
if !matched {
return false, err
}
}
if mailToFind.Body != "" {
matched, err = regexp.MatchString(mailToFind.Body, m.Body)
if err != nil || !matched {
// As a body can have complex characters, we need to remove all special characters that can make the match fail
replacer := strings.NewReplacer("\n", "", "\r", "", "\t", "")
m.Body = replacer.Replace(m.Body)
mailToFind.Body = replacer.Replace(mailToFind.Body)

matched = strings.Contains(m.Body, mailToFind.Body)
if !matched {
return false, err
}
}
Expand Down

0 comments on commit 32d46c4

Please sign in to comment.