2021-05-11 20:55:36 -04:00
|
|
|
package headscale
|
|
|
|
|
|
|
|
import (
|
|
|
|
"gopkg.in/check.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Suite) TestGetMachine(c *check.C) {
|
|
|
|
n, err := h.CreateNamespace("test")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
2021-05-22 20:15:29 -04:00
|
|
|
pak, err := h.CreatePreAuthKey(n.Name, false, false, nil)
|
2021-05-11 20:55:36 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
_, err = h.GetMachine("test", "testmachine")
|
|
|
|
c.Assert(err, check.NotNil)
|
|
|
|
|
|
|
|
m := Machine{
|
|
|
|
ID: 0,
|
|
|
|
MachineKey: "foo",
|
|
|
|
NodeKey: "bar",
|
|
|
|
DiscoKey: "faa",
|
|
|
|
Name: "testmachine",
|
|
|
|
NamespaceID: n.ID,
|
|
|
|
Registered: true,
|
|
|
|
RegisterMethod: "authKey",
|
|
|
|
AuthKeyID: uint(pak.ID),
|
|
|
|
}
|
2021-07-04 15:40:46 -04:00
|
|
|
h.db.Save(&m)
|
2021-05-11 20:55:36 -04:00
|
|
|
|
|
|
|
m1, err := h.GetMachine("test", "testmachine")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
_, err = m1.GetHostInfo()
|
|
|
|
c.Assert(err, check.IsNil)
|
2021-07-16 18:14:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Suite) TestGetMachineByID(c *check.C) {
|
|
|
|
n, err := h.CreateNamespace("test")
|
|
|
|
c.Assert(err, check.IsNil)
|
2021-05-11 20:55:36 -04:00
|
|
|
|
2021-07-16 18:14:22 -04:00
|
|
|
pak, err := h.CreatePreAuthKey(n.Name, false, false, nil)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
_, err = h.GetMachineByID(0)
|
|
|
|
c.Assert(err, check.NotNil)
|
|
|
|
|
|
|
|
m := Machine{
|
|
|
|
ID: 0,
|
|
|
|
MachineKey: "foo",
|
|
|
|
NodeKey: "bar",
|
|
|
|
DiscoKey: "faa",
|
|
|
|
Name: "testmachine",
|
|
|
|
NamespaceID: n.ID,
|
|
|
|
Registered: true,
|
|
|
|
RegisterMethod: "authKey",
|
|
|
|
AuthKeyID: uint(pak.ID),
|
|
|
|
}
|
|
|
|
h.db.Save(&m)
|
|
|
|
|
|
|
|
m1, err := h.GetMachineByID(0)
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
|
|
_, err = m1.GetHostInfo()
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Suite) TestDeleteMachine(c *check.C) {
|
|
|
|
n, err := h.CreateNamespace("test")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
m := Machine{
|
|
|
|
ID: 0,
|
|
|
|
MachineKey: "foo",
|
|
|
|
NodeKey: "bar",
|
|
|
|
DiscoKey: "faa",
|
|
|
|
Name: "testmachine",
|
|
|
|
NamespaceID: n.ID,
|
|
|
|
Registered: true,
|
|
|
|
RegisterMethod: "authKey",
|
|
|
|
AuthKeyID: uint(1),
|
|
|
|
}
|
|
|
|
h.db.Save(&m)
|
2021-07-16 18:29:14 -04:00
|
|
|
err = h.DeleteMachine(&m)
|
|
|
|
c.Assert(err, check.IsNil)
|
2021-07-16 18:14:22 -04:00
|
|
|
_, err = h.GetMachine(n.Name, "testmachine")
|
|
|
|
c.Assert(err, check.NotNil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Suite) TestHardDeleteMachine(c *check.C) {
|
|
|
|
n, err := h.CreateNamespace("test")
|
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
m := Machine{
|
|
|
|
ID: 0,
|
|
|
|
MachineKey: "foo",
|
|
|
|
NodeKey: "bar",
|
|
|
|
DiscoKey: "faa",
|
|
|
|
Name: "testmachine3",
|
|
|
|
NamespaceID: n.ID,
|
|
|
|
Registered: true,
|
|
|
|
RegisterMethod: "authKey",
|
|
|
|
AuthKeyID: uint(1),
|
|
|
|
}
|
|
|
|
h.db.Save(&m)
|
2021-07-16 18:29:14 -04:00
|
|
|
err = h.HardDeleteMachine(&m)
|
|
|
|
c.Assert(err, check.IsNil)
|
2021-07-16 18:14:22 -04:00
|
|
|
_, err = h.GetMachine(n.Name, "testmachine3")
|
|
|
|
c.Assert(err, check.NotNil)
|
2021-05-11 20:55:36 -04:00
|
|
|
}
|