mirror of
https://github.com/juanfont/headscale.git
synced 2025-08-25 09:37:28 +00:00
WIP Working on authkeys + tests
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
_ "github.com/jinzhu/gorm/dialects/sqlite" // sql driver
|
||||
|
||||
@@ -48,6 +49,7 @@ func (s *Suite) TearDownSuite(c *check.C) {
|
||||
|
||||
func (*Suite) TestCreatePreAuthKey(c *check.C) {
|
||||
_, err := h.CreatePreAuthKey("bogus", true, nil)
|
||||
|
||||
c.Assert(err, check.NotNil)
|
||||
|
||||
n, err := h.CreateNamespace("test")
|
||||
@@ -73,3 +75,22 @@ func (*Suite) TestCreatePreAuthKey(c *check.C) {
|
||||
// Make sure the Namespace association is populated
|
||||
c.Assert((*keys)[0].Namespace.Name, check.Equals, n.Name)
|
||||
}
|
||||
|
||||
func (*Suite) TestExpiredPreAuthKey(c *check.C) {
|
||||
n, err := h.CreateNamespace("test2")
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
now := time.Now()
|
||||
pak, err := h.CreatePreAuthKey(n.Name, true, &now)
|
||||
c.Assert(err, check.IsNil)
|
||||
|
||||
p, err := h.checkKeyValidity(pak.Key)
|
||||
c.Assert(err, check.Equals, errorAuthKeyExpired)
|
||||
c.Assert(p, check.IsNil)
|
||||
}
|
||||
|
||||
func (*Suite) TestPreAuthKeyDoesNotExist(c *check.C) {
|
||||
p, err := h.checkKeyValidity("potatoKey")
|
||||
c.Assert(err, check.Equals, errorAuthKeyNotFound)
|
||||
c.Assert(p, check.IsNil)
|
||||
}
|
||||
|
Reference in New Issue
Block a user