mirror of https://github.com/gophish/gophish
Add empty attribute test for PutGroup
If passing a Target instance to the database Updates method then empty attributes will be ignored. Using a map[string]interface ensures all changed attributes, even empty ones, are persisted to database.pull/315/head
parent
731c621095
commit
92f4ca6a90
|
@ -88,6 +88,31 @@ func (s *ModelsSuite) TestPutGroup(c *check.C) {
|
||||||
c.Assert(targets[1].LastName, check.Equals, "Example")
|
c.Assert(targets[1].LastName, check.Equals, "Example")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ModelsSuite) TestPutGroupEmptyAttribute(c *check.C) {
|
||||||
|
// Add test group.
|
||||||
|
group := Group{Name: "Put Empty Attribute Test Group"}
|
||||||
|
group.Targets = []Target{
|
||||||
|
Target{Email: "test3@example.com", FirstName: "Third", LastName: "Example"},
|
||||||
|
Target{Email: "test4@example.com", FirstName: "Fourth", LastName: "Example"},
|
||||||
|
}
|
||||||
|
group.UserId = 1
|
||||||
|
PostGroup(&group)
|
||||||
|
|
||||||
|
// Update one of group's targets.
|
||||||
|
group.Targets[0].FirstName = ""
|
||||||
|
err := PutGroup(&group)
|
||||||
|
c.Assert(err, check.Equals, nil)
|
||||||
|
|
||||||
|
// Verify updated empty attribute was saved.
|
||||||
|
targets, _ := GetTargets(group.Id)
|
||||||
|
c.Assert(targets[0].Email, check.Equals, "test3@example.com")
|
||||||
|
c.Assert(targets[0].FirstName, check.Equals, "")
|
||||||
|
c.Assert(targets[0].LastName, check.Equals, "Example")
|
||||||
|
c.Assert(targets[1].Email, check.Equals, "test4@example.com")
|
||||||
|
c.Assert(targets[1].FirstName, check.Equals, "Fourth")
|
||||||
|
c.Assert(targets[1].LastName, check.Equals, "Example")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ModelsSuite) TestPostSMTP(c *check.C) {
|
func (s *ModelsSuite) TestPostSMTP(c *check.C) {
|
||||||
smtp := SMTP{
|
smtp := SMTP{
|
||||||
Name: "Test SMTP",
|
Name: "Test SMTP",
|
||||||
|
|
Loading…
Reference in New Issue