Initial work on ACLs

This commit is contained in:
Juan Font 2021-07-03 11:55:32 +02:00
parent 95fee5aa6f
commit b161a92e58
6 changed files with 252 additions and 0 deletions

33
acls_test.go Normal file
View file

@ -0,0 +1,33 @@
package headscale
import (
"gopkg.in/check.v1"
)
func (s *Suite) TestWrongPath(c *check.C) {
_, err := h.ParsePolicy("asdfg")
c.Assert(err, check.NotNil)
}
func (s *Suite) TestBrokenHuJson(c *check.C) {
_, err := h.ParsePolicy("./tests/acls/broken.hujson")
c.Assert(err, check.NotNil)
}
func (s *Suite) TestInvalidPolicyHuson(c *check.C) {
_, err := h.ParsePolicy("./tests/acls/invalid.hujson")
c.Assert(err, check.NotNil)
c.Assert(err, check.Equals, errorInvalidPolicy)
}
func (s *Suite) TestValidCheckHosts(c *check.C) {
p, err := h.ParsePolicy("./tests/acls/acl_policy_1.hujson")
c.Assert(err, check.IsNil)
c.Assert(p, check.NotNil)
c.Assert(p.IsZero(), check.Equals, false)
hosts, err := p.GetHosts()
c.Assert(err, check.IsNil)
c.Assert(*hosts, check.HasLen, 2)
}