Skip to content

Commit

Permalink
Fixes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hopleus committed Oct 5, 2024
1 parent c67deb9 commit f877e02
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
20 changes: 10 additions & 10 deletions hscontrol/db/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (s *Suite) TestGetNode(c *check.C) {
user, err := db.CreateUser("test")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)

_, err = db.getNode("test", "testnode")
Expand Down Expand Up @@ -58,7 +58,7 @@ func (s *Suite) TestGetNodeByID(c *check.C) {
user, err := db.CreateUser("test")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)

_, err = db.GetNodeByID(0)
Expand Down Expand Up @@ -87,7 +87,7 @@ func (s *Suite) TestGetNodeByAnyNodeKey(c *check.C) {
user, err := db.CreateUser("test")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)

_, err = db.GetNodeByID(0)
Expand Down Expand Up @@ -143,7 +143,7 @@ func (s *Suite) TestListPeers(c *check.C) {
user, err := db.CreateUser("test")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)

_, err = db.GetNodeByID(0)
Expand Down Expand Up @@ -189,7 +189,7 @@ func (s *Suite) TestGetACLFilteredPeers(c *check.C) {
for _, name := range []string{"test", "admin"} {
user, err := db.CreateUser(name)
c.Assert(err, check.IsNil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)
stor = append(stor, base{user, pak})
}
Expand Down Expand Up @@ -281,7 +281,7 @@ func (s *Suite) TestExpireNode(c *check.C) {
user, err := db.CreateUser("test")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)

_, err = db.getNode("test", "testnode")
Expand Down Expand Up @@ -322,7 +322,7 @@ func (s *Suite) TestSetTags(c *check.C) {
user, err := db.CreateUser("test")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)

_, err = db.getNode("test", "testnode")
Expand Down Expand Up @@ -558,7 +558,7 @@ func TestAutoApproveRoutes(t *testing.T) {
user, err := adb.CreateUser("test")
assert.NoError(t, err)

pak, err := adb.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := adb.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
assert.NoError(t, err)

nodeKey := key.NewNode()
Expand Down Expand Up @@ -690,10 +690,10 @@ func TestListEphemeralNodes(t *testing.T) {
user, err := db.CreateUser("test")
assert.NoError(t, err)

pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
assert.NoError(t, err)

pakEph, err := db.CreatePreAuthKey(user.Name, false, true, nil, nil)
pakEph, err := db.CreatePreAuthKey(user.Name, false, true, nil, true, nil)
assert.NoError(t, err)

node := types.Node{
Expand Down
22 changes: 11 additions & 11 deletions hscontrol/db/preauth_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
)

func (*Suite) TestCreatePreAuthKey(c *check.C) {
_, err := db.CreatePreAuthKey("bogus", true, false, nil, nil)
_, err := db.CreatePreAuthKey("bogus", true, false, nil, true, nil)

c.Assert(err, check.NotNil)

user, err := db.CreateUser("test")
c.Assert(err, check.IsNil)

key, err := db.CreatePreAuthKey(user.Name, true, false, nil, nil)
key, err := db.CreatePreAuthKey(user.Name, true, false, nil, true, nil)
c.Assert(err, check.IsNil)

// Did we get a valid key?
Expand All @@ -44,7 +44,7 @@ func (*Suite) TestExpiredPreAuthKey(c *check.C) {
c.Assert(err, check.IsNil)

now := time.Now().Add(-5 * time.Second)
pak, err := db.CreatePreAuthKey(user.Name, true, false, &now, nil)
pak, err := db.CreatePreAuthKey(user.Name, true, false, &now, true, nil)
c.Assert(err, check.IsNil)

key, err := db.ValidatePreAuthKey(pak.Key)
Expand All @@ -62,7 +62,7 @@ func (*Suite) TestValidateKeyOk(c *check.C) {
user, err := db.CreateUser("test3")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, true, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, true, false, nil, true, nil)
c.Assert(err, check.IsNil)

key, err := db.ValidatePreAuthKey(pak.Key)
Expand All @@ -74,7 +74,7 @@ func (*Suite) TestAlreadyUsedKey(c *check.C) {
user, err := db.CreateUser("test4")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)

node := types.Node{
Expand All @@ -96,7 +96,7 @@ func (*Suite) TestReusableBeingUsedKey(c *check.C) {
user, err := db.CreateUser("test5")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, true, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, true, false, nil, true, nil)
c.Assert(err, check.IsNil)

node := types.Node{
Expand All @@ -118,7 +118,7 @@ func (*Suite) TestNotReusableNotBeingUsedKey(c *check.C) {
user, err := db.CreateUser("test6")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)

key, err := db.ValidatePreAuthKey(pak.Key)
Expand All @@ -130,7 +130,7 @@ func (*Suite) TestExpirePreauthKey(c *check.C) {
user, err := db.CreateUser("test3")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, true, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, true, false, nil, true, nil)
c.Assert(err, check.IsNil)
c.Assert(pak.Expiration, check.IsNil)

Expand All @@ -147,7 +147,7 @@ func (*Suite) TestNotReusableMarkedAsUsed(c *check.C) {
user, err := db.CreateUser("test6")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)
pak.Used = true
db.DB.Save(&pak)
Expand All @@ -160,12 +160,12 @@ func (*Suite) TestPreAuthKeyACLTags(c *check.C) {
user, err := db.CreateUser("test8")
c.Assert(err, check.IsNil)

_, err = db.CreatePreAuthKey(user.Name, false, false, nil, []string{"badtag"})
_, err = db.CreatePreAuthKey(user.Name, false, false, nil, true, []string{"badtag"})
c.Assert(err, check.NotNil) // Confirm that malformed tags are rejected

tags := []string{"tag:test1", "tag:test2"}
tagsWithDuplicate := []string{"tag:test1", "tag:test2", "tag:test2"}
_, err = db.CreatePreAuthKey(user.Name, false, false, nil, tagsWithDuplicate)
_, err = db.CreatePreAuthKey(user.Name, false, false, nil, true, tagsWithDuplicate)
c.Assert(err, check.IsNil)

listedPaks, err := db.ListPreAuthKeys("test8")
Expand Down
8 changes: 4 additions & 4 deletions hscontrol/db/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s *Suite) TestGetRoutes(c *check.C) {
user, err := db.CreateUser("test")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)

_, err = db.getNode("test", "test_get_route_node")
Expand Down Expand Up @@ -79,7 +79,7 @@ func (s *Suite) TestGetEnableRoutes(c *check.C) {
user, err := db.CreateUser("test")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)

_, err = db.getNode("test", "test_enable_route_node")
Expand Down Expand Up @@ -153,7 +153,7 @@ func (s *Suite) TestIsUniquePrefix(c *check.C) {
user, err := db.CreateUser("test")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)

_, err = db.getNode("test", "test_enable_route_node")
Expand Down Expand Up @@ -234,7 +234,7 @@ func (s *Suite) TestDeleteRoutes(c *check.C) {
user, err := db.CreateUser("test")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)

_, err = db.getNode("test", "test_enable_route_node")
Expand Down
6 changes: 3 additions & 3 deletions hscontrol/db/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (s *Suite) TestDestroyUserErrors(c *check.C) {
user, err := db.CreateUser("test")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)

err = db.DestroyUser("test")
Expand All @@ -44,7 +44,7 @@ func (s *Suite) TestDestroyUserErrors(c *check.C) {
user, err = db.CreateUser("test")
c.Assert(err, check.IsNil)

pak, err = db.CreatePreAuthKey(user.Name, false, false, nil, nil)
pak, err = db.CreatePreAuthKey(user.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)

node := types.Node{
Expand Down Expand Up @@ -97,7 +97,7 @@ func (s *Suite) TestSetMachineUser(c *check.C) {
newUser, err := db.CreateUser("new")
c.Assert(err, check.IsNil)

pak, err := db.CreatePreAuthKey(oldUser.Name, false, false, nil, nil)
pak, err := db.CreatePreAuthKey(oldUser.Name, false, false, nil, true, nil)
c.Assert(err, check.IsNil)

node := types.Node{
Expand Down

0 comments on commit f877e02

Please sign in to comment.