Ejemplo n.º 1
0
func (s *PasswordSuite) TestPassword(c *gc.C) {
	password := "******"

	hash, err := auth.HashPassword(password)
	c.Assert(err, gc.IsNil)

	c.Assert(auth.TestPassword(password, hash), gc.Equals, true)
	c.Assert(auth.TestPassword("T"+password[1:], hash), gc.Not(gc.Equals), true)
}
Ejemplo n.º 2
0
func (s *RepoSuite) TestRepo(c *gc.C) {
	repo := auth.NewUserRepo()

	_, ok := repo.User("test.user")
	c.Assert(ok, gc.Not(gc.Equals), true)

	hash, err := auth.HashPassword("password")
	c.Assert(err, gc.IsNil)

	err = repo.Save("test.user", hash)
	c.Assert(err, gc.IsNil)

	u, ok := repo.User("test.user")
	c.Assert(ok, gc.Equals, true)

	ok = u.Authenticate("password")
	c.Assert(ok, gc.Equals, true)
}