mirror of https://github.com/gophish/gophish
Removing duplicates in campaigns. Fixes #855
parent
aa8c770e73
commit
44154f3bf0
|
@ -404,9 +404,16 @@ func PostCampaign(c *Campaign, uid int64) error {
|
||||||
Logger.Println(err)
|
Logger.Println(err)
|
||||||
}
|
}
|
||||||
// Insert all the results
|
// Insert all the results
|
||||||
|
resultMap := make(map[string]bool)
|
||||||
for _, g := range c.Groups {
|
for _, g := range c.Groups {
|
||||||
// Insert a result for each target in the group
|
// Insert a result for each target in the group
|
||||||
for _, t := range g.Targets {
|
for _, t := range g.Targets {
|
||||||
|
// Remove duplicate results - we should only
|
||||||
|
// send emails to unique email addresses.
|
||||||
|
if _, ok := resultMap[t.Email]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
resultMap[t.Email] = true
|
||||||
r := &Result{
|
r := &Result{
|
||||||
Email: t.Email,
|
Email: t.Email,
|
||||||
Position: t.Position,
|
Position: t.Position,
|
||||||
|
|
|
@ -441,3 +441,47 @@ func (s *ModelsSuite) TestResultScheduledStatus(ch *check.C) {
|
||||||
ch.Assert(r.Status, check.Equals, STATUS_SCHEDULED)
|
ch.Assert(r.Status, check.Equals, STATUS_SCHEDULED)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ModelsSuite) TestDuplicateResults(ch *check.C) {
|
||||||
|
group := Group{Name: "Test Group"}
|
||||||
|
group.Targets = []Target{
|
||||||
|
Target{Email: "test1@example.com", FirstName: "First", LastName: "Example"},
|
||||||
|
Target{Email: "test1@example.com", FirstName: "Duplicate", LastName: "Duplicate"},
|
||||||
|
Target{Email: "test2@example.com", FirstName: "Second", LastName: "Example"},
|
||||||
|
}
|
||||||
|
group.UserId = 1
|
||||||
|
ch.Assert(PostGroup(&group), check.Equals, nil)
|
||||||
|
|
||||||
|
// Add a template
|
||||||
|
t := Template{Name: "Test Template"}
|
||||||
|
t.Subject = "{{.RId}} - Subject"
|
||||||
|
t.Text = "{{.RId}} - Text"
|
||||||
|
t.HTML = "{{.RId}} - HTML"
|
||||||
|
t.UserId = 1
|
||||||
|
ch.Assert(PostTemplate(&t), check.Equals, nil)
|
||||||
|
|
||||||
|
// Add a landing page
|
||||||
|
p := Page{Name: "Test Page"}
|
||||||
|
p.HTML = "<html>Test</html>"
|
||||||
|
p.UserId = 1
|
||||||
|
ch.Assert(PostPage(&p), check.Equals, nil)
|
||||||
|
|
||||||
|
// Add a sending profile
|
||||||
|
smtp := SMTP{Name: "Test Page"}
|
||||||
|
smtp.UserId = 1
|
||||||
|
smtp.Host = "example.com"
|
||||||
|
smtp.FromAddress = "test@test.com"
|
||||||
|
ch.Assert(PostSMTP(&smtp), check.Equals, nil)
|
||||||
|
|
||||||
|
c := Campaign{Name: "Test campaign"}
|
||||||
|
c.UserId = 1
|
||||||
|
c.Template = t
|
||||||
|
c.Page = p
|
||||||
|
c.SMTP = smtp
|
||||||
|
c.Groups = []Group{group}
|
||||||
|
|
||||||
|
ch.Assert(PostCampaign(&c, c.UserId), check.Equals, nil)
|
||||||
|
ch.Assert(len(c.Results), check.Equals, 2)
|
||||||
|
ch.Assert(c.Results[0].Email, check.Equals, group.Targets[0].Email)
|
||||||
|
ch.Assert(c.Results[1].Email, check.Equals, group.Targets[2].Email)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue