2017-12-09 21:42:07 +00:00
|
|
|
package worker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gophish/gophish/config"
|
|
|
|
"github.com/gophish/gophish/models"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
// WorkerSuite is a suite of tests to cover API related functions
|
|
|
|
type WorkerSuite struct {
|
|
|
|
suite.Suite
|
2018-12-15 21:42:32 +00:00
|
|
|
config *config.Config
|
2017-12-09 21:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *WorkerSuite) SetupSuite() {
|
2018-12-15 21:42:32 +00:00
|
|
|
conf := &config.Config{
|
|
|
|
DBName: "sqlite3",
|
|
|
|
DBPath: ":memory:",
|
|
|
|
MigrationsPath: "../db/db_sqlite3/migrations/",
|
|
|
|
}
|
|
|
|
err := models.Setup(conf)
|
2017-12-09 21:42:07 +00:00
|
|
|
if err != nil {
|
|
|
|
s.T().Fatalf("Failed creating database: %v", err)
|
|
|
|
}
|
2018-12-15 21:42:32 +00:00
|
|
|
s.config = conf
|
2017-12-09 21:42:07 +00:00
|
|
|
s.Nil(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *WorkerSuite) TearDownTest() {
|
|
|
|
campaigns, _ := models.GetCampaigns(1)
|
|
|
|
for _, campaign := range campaigns {
|
|
|
|
models.DeleteCampaign(campaign.Id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *WorkerSuite) SetupTest() {
|
2018-12-15 21:42:32 +00:00
|
|
|
s.config.TestFlag = true
|
2017-12-09 21:42:07 +00:00
|
|
|
// Add a group
|
|
|
|
group := models.Group{Name: "Test Group"}
|
|
|
|
group.Targets = []models.Target{
|
2018-06-09 02:20:52 +00:00
|
|
|
models.Target{BaseRecipient: models.BaseRecipient{Email: "test1@example.com", FirstName: "First", LastName: "Example"}},
|
|
|
|
models.Target{BaseRecipient: models.BaseRecipient{Email: "test2@example.com", FirstName: "Second", LastName: "Example"}},
|
2017-12-09 21:42:07 +00:00
|
|
|
}
|
|
|
|
group.UserId = 1
|
|
|
|
models.PostGroup(&group)
|
|
|
|
|
|
|
|
// Add a template
|
|
|
|
t := models.Template{Name: "Test Template"}
|
|
|
|
t.Subject = "Test subject"
|
|
|
|
t.Text = "Text text"
|
|
|
|
t.HTML = "<html>Test</html>"
|
|
|
|
t.UserId = 1
|
|
|
|
models.PostTemplate(&t)
|
|
|
|
|
|
|
|
// Add a landing page
|
|
|
|
p := models.Page{Name: "Test Page"}
|
|
|
|
p.HTML = "<html>Test</html>"
|
|
|
|
p.UserId = 1
|
|
|
|
models.PostPage(&p)
|
|
|
|
|
|
|
|
// Add a sending profile
|
|
|
|
smtp := models.SMTP{Name: "Test Page"}
|
|
|
|
smtp.UserId = 1
|
|
|
|
smtp.Host = "example.com"
|
|
|
|
smtp.FromAddress = "test@test.com"
|
|
|
|
models.PostSMTP(&smtp)
|
|
|
|
|
|
|
|
// Setup and "launch" our campaign
|
|
|
|
// Set the status such that no emails are attempted
|
|
|
|
c := models.Campaign{Name: "Test campaign"}
|
|
|
|
c.UserId = 1
|
|
|
|
c.Template = t
|
|
|
|
c.Page = p
|
|
|
|
c.SMTP = smtp
|
|
|
|
c.Groups = []models.Group{group}
|
|
|
|
models.PostCampaign(&c, c.UserId)
|
|
|
|
c.UpdateStatus(models.CAMPAIGN_EMAILS_SENT)
|
|
|
|
}
|