mirror of
https://github.com/juanfont/headscale.git
synced 2025-04-30 01:19:47 +02:00
add testcases
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
586a20fbff
commit
8da5a8743a
@ -8,6 +8,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"slices"
|
||||
|
||||
"github.com/juanfont/headscale/hscontrol/types"
|
||||
"github.com/juanfont/headscale/hscontrol/util"
|
||||
"github.com/tailscale/hujson"
|
||||
@ -237,8 +239,8 @@ func (t Tag) CanBeAutoApprover() bool {
|
||||
type Host string
|
||||
|
||||
func (h Host) Validate() error {
|
||||
if isHost(string(h)) {
|
||||
fmt.Errorf("Hostname %q is invalid", h)
|
||||
if !isHost(string(h)) {
|
||||
return fmt.Errorf("Hostname %q is invalid", h)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -379,10 +381,8 @@ const (
|
||||
var autogroups = []string{AutoGroupInternet}
|
||||
|
||||
func (ag AutoGroup) Validate() error {
|
||||
for _, valid := range autogroups {
|
||||
if valid == string(ag) {
|
||||
return nil
|
||||
}
|
||||
if slices.Contains(autogroups, string(ag)) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("AutoGroup is invalid, got: %q, must be one of %v", ag, autogroups)
|
||||
@ -525,7 +525,7 @@ Please check the format and try again.`, vs)
|
||||
type AliasEnc struct{ Alias }
|
||||
|
||||
func (ve *AliasEnc) UnmarshalJSON(b []byte) error {
|
||||
ptr, err := unmarshalPointer[Alias](
|
||||
ptr, err := unmarshalPointer(
|
||||
b,
|
||||
parseAlias,
|
||||
)
|
||||
@ -631,7 +631,7 @@ Please check the format and try again.`, s)
|
||||
type AutoApproverEnc struct{ AutoApprover }
|
||||
|
||||
func (ve *AutoApproverEnc) UnmarshalJSON(b []byte) error {
|
||||
ptr, err := unmarshalPointer[AutoApprover](
|
||||
ptr, err := unmarshalPointer(
|
||||
b,
|
||||
parseAutoApprover,
|
||||
)
|
||||
@ -651,7 +651,7 @@ type Owner interface {
|
||||
type OwnerEnc struct{ Owner }
|
||||
|
||||
func (ve *OwnerEnc) UnmarshalJSON(b []byte) error {
|
||||
ptr, err := unmarshalPointer[Owner](
|
||||
ptr, err := unmarshalPointer(
|
||||
b,
|
||||
parseOwner,
|
||||
)
|
||||
|
@ -361,6 +361,46 @@ func TestUnmarshalPolicy(t *testing.T) {
|
||||
`,
|
||||
wantErr: `AutoGroup is invalid, got: "autogroup:invalid", must be one of [autogroup:internet]`,
|
||||
},
|
||||
{
|
||||
name: "undefined-hostname-errors",
|
||||
input: `
|
||||
{
|
||||
"acls": [
|
||||
{
|
||||
"action": "accept",
|
||||
"src": [
|
||||
"user1"
|
||||
],
|
||||
"dst": [
|
||||
"user1:*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
`,
|
||||
wantErr: `Host "user1" is not defined in the Policy, please define or remove the reference to it`,
|
||||
},
|
||||
{
|
||||
name: "defined-hostname-does-not-err",
|
||||
input: `
|
||||
{
|
||||
"hosts": {
|
||||
"user1": "100.100.100.100",
|
||||
},
|
||||
"acls": [
|
||||
{
|
||||
"action": "accept",
|
||||
"src": [
|
||||
"user1"
|
||||
],
|
||||
"dst": [
|
||||
"user1:*"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
||||
cmps := append(util.Comparers, cmp.Comparer(func(x, y Prefix) bool {
|
||||
|
Loading…
Reference in New Issue
Block a user