Merge pull request #30 from cure/bugfix-and-more-tests

a bunch of smaller fixes
This commit is contained in:
Juan Font 2021-05-24 19:52:38 +02:00 committed by GitHub
commit d1be440c89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 7 deletions

5
app.go
View file

@ -100,11 +100,6 @@ func (h *Headscale) redirect(w http.ResponseWriter, req *http.Request) {
// ExpireEphemeralNodes deletes ephemeral machine records that have not been
// seen for longer than h.cfg.EphemeralNodeInactivityTimeout
func (h *Headscale) ExpireEphemeralNodes(milliSeconds int64) {
if milliSeconds == 0 {
// For testing
h.expireEphemeralNodesWorker()
return
}
ticker := time.NewTicker(time.Duration(milliSeconds) * time.Millisecond)
for range ticker.C {
h.expireEphemeralNodesWorker()

36
cli_test.go Normal file
View file

@ -0,0 +1,36 @@
package headscale
import (
"gopkg.in/check.v1"
)
func (s *Suite) TestRegisterMachine(c *check.C) {
n, err := h.CreateNamespace("test")
c.Assert(err, check.IsNil)
db, err := h.db()
if err != nil {
c.Fatal(err)
}
defer db.Close()
m := Machine{
ID: 0,
MachineKey: "8ce002a935f8c394e55e78fbbb410576575ff8ec5cfa2e627e4b807f1be15b0e",
NodeKey: "bar",
DiscoKey: "faa",
Name: "testmachine",
NamespaceID: n.ID,
}
db.Save(&m)
_, err = h.GetMachine("test", "testmachine")
c.Assert(err, check.IsNil)
m2, err := h.RegisterMachine("8ce002a935f8c394e55e78fbbb410576575ff8ec5cfa2e627e4b807f1be15b0e", n.Name)
c.Assert(err, check.IsNil)
c.Assert(m2.Registered, check.Equals, true)
_, err = m2.GetHostInfo()
c.Assert(err, check.IsNil)
}

View file

@ -67,7 +67,11 @@ var ListNodesCmd = &cobra.Command{
fmt.Printf("name\t\tlast seen\t\tephemeral\n")
for _, m := range *machines {
fmt.Printf("%s\t%s\t%t\n", m.Name, m.LastSeen.Format("2006-01-02 15:04:05"), m.AuthKey.Ephemeral)
var ephemeral bool
if m.AuthKey != nil && m.AuthKey.Ephemeral {
ephemeral = true
}
fmt.Printf("%s\t%s\t%t\n", m.Name, m.LastSeen.Format("2006-01-02 15:04:05"), ephemeral)
}
},

View file

@ -172,7 +172,7 @@ func (*Suite) TestEphemeralKey(c *check.C) {
_, err = h.GetMachine("test7", "testest")
c.Assert(err, check.IsNil)
h.ExpireEphemeralNodes(0)
h.expireEphemeralNodesWorker()
// The machine record should have been deleted
_, err = h.GetMachine("test7", "testest")