mirror of
https://github.com/gophish/gophish
synced 2024-11-15 08:47:17 +00:00
70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
package models
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/gophish/gophish/config"
|
|
"gopkg.in/check.v1"
|
|
)
|
|
|
|
// Hook up gocheck into the "go test" runner.
|
|
func Test(t *testing.T) { check.TestingT(t) }
|
|
|
|
type ModelsSuite struct{}
|
|
|
|
var _ = check.Suite(&ModelsSuite{})
|
|
|
|
func (s *ModelsSuite) SetUpSuite(c *check.C) {
|
|
config.Conf.DBPath = ":memory:"
|
|
err := Setup()
|
|
if err != nil {
|
|
c.Fatalf("Failed creating database: %v", err)
|
|
}
|
|
}
|
|
|
|
func (s *ModelsSuite) TestGetUser(c *check.C) {
|
|
u, err := GetUser(1)
|
|
c.Assert(err, check.Equals, nil)
|
|
c.Assert(u.Username, check.Equals, "admin")
|
|
}
|
|
|
|
func (s *ModelsSuite) TestGeneratedAPIKey(c *check.C) {
|
|
u, err := GetUser(1)
|
|
c.Assert(err, check.Equals, nil)
|
|
c.Assert(u.ApiKey, check.Not(check.Equals), "12345678901234567890123456789012")
|
|
}
|
|
|
|
func (s *ModelsSuite) TestPostGroup(c *check.C) {
|
|
g := Group{Name: "Test Group"}
|
|
g.Targets = []Target{Target{Email: "test@example.com"}}
|
|
g.UserId = 1
|
|
err := PostGroup(&g)
|
|
c.Assert(err, check.Equals, nil)
|
|
c.Assert(g.Name, check.Equals, "Test Group")
|
|
c.Assert(g.Targets[0].Email, check.Equals, "test@example.com")
|
|
}
|
|
|
|
func (s *ModelsSuite) TestPostGroupNoName(c *check.C) {
|
|
g := Group{Name: ""}
|
|
g.Targets = []Target{Target{Email: "test@example.com"}}
|
|
g.UserId = 1
|
|
err := PostGroup(&g)
|
|
c.Assert(err, check.Equals, ErrGroupNameNotSpecified)
|
|
}
|
|
|
|
func (s *ModelsSuite) TestPostGroupNoTargets(c *check.C) {
|
|
g := Group{Name: "No Target Group"}
|
|
g.Targets = []Target{}
|
|
g.UserId = 1
|
|
err := PostGroup(&g)
|
|
c.Assert(err, check.Equals, ErrNoTargetsSpecified)
|
|
}
|
|
|
|
func (s *ModelsSuite) TestPutUser(c *check.C) {
|
|
u, err := GetUser(1)
|
|
u.Username = "admin_changed"
|
|
err = PutUser(&u)
|
|
c.Assert(err, check.Equals, nil)
|
|
u, err = GetUser(1)
|
|
c.Assert(u.Username, check.Equals, "admin_changed")
|
|
}
|