mirror of
https://github.com/juanfont/headscale.git
synced 2025-06-10 01:17:20 +02:00
Merge 8da5a8743a
into 109989005d
This commit is contained in:
commit
a0d037d40d
@ -8,6 +8,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"slices"
|
||||||
|
|
||||||
"github.com/juanfont/headscale/hscontrol/types"
|
"github.com/juanfont/headscale/hscontrol/types"
|
||||||
"github.com/juanfont/headscale/hscontrol/util"
|
"github.com/juanfont/headscale/hscontrol/util"
|
||||||
"github.com/tailscale/hujson"
|
"github.com/tailscale/hujson"
|
||||||
@ -237,8 +239,8 @@ func (t Tag) CanBeAutoApprover() bool {
|
|||||||
type Host string
|
type Host string
|
||||||
|
|
||||||
func (h Host) Validate() error {
|
func (h Host) Validate() error {
|
||||||
if isHost(string(h)) {
|
if !isHost(string(h)) {
|
||||||
fmt.Errorf("Hostname %q is invalid", h)
|
return fmt.Errorf("Hostname %q is invalid", h)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -379,11 +381,9 @@ const (
|
|||||||
var autogroups = []string{AutoGroupInternet}
|
var autogroups = []string{AutoGroupInternet}
|
||||||
|
|
||||||
func (ag AutoGroup) Validate() error {
|
func (ag AutoGroup) Validate() error {
|
||||||
for _, valid := range autogroups {
|
if slices.Contains(autogroups, string(ag)) {
|
||||||
if valid == string(ag) {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Errorf("AutoGroup is invalid, got: %q, must be one of %v", ag, autogroups)
|
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 }
|
type AliasEnc struct{ Alias }
|
||||||
|
|
||||||
func (ve *AliasEnc) UnmarshalJSON(b []byte) error {
|
func (ve *AliasEnc) UnmarshalJSON(b []byte) error {
|
||||||
ptr, err := unmarshalPointer[Alias](
|
ptr, err := unmarshalPointer(
|
||||||
b,
|
b,
|
||||||
parseAlias,
|
parseAlias,
|
||||||
)
|
)
|
||||||
@ -631,7 +631,7 @@ Please check the format and try again.`, s)
|
|||||||
type AutoApproverEnc struct{ AutoApprover }
|
type AutoApproverEnc struct{ AutoApprover }
|
||||||
|
|
||||||
func (ve *AutoApproverEnc) UnmarshalJSON(b []byte) error {
|
func (ve *AutoApproverEnc) UnmarshalJSON(b []byte) error {
|
||||||
ptr, err := unmarshalPointer[AutoApprover](
|
ptr, err := unmarshalPointer(
|
||||||
b,
|
b,
|
||||||
parseAutoApprover,
|
parseAutoApprover,
|
||||||
)
|
)
|
||||||
@ -651,7 +651,7 @@ type Owner interface {
|
|||||||
type OwnerEnc struct{ Owner }
|
type OwnerEnc struct{ Owner }
|
||||||
|
|
||||||
func (ve *OwnerEnc) UnmarshalJSON(b []byte) error {
|
func (ve *OwnerEnc) UnmarshalJSON(b []byte) error {
|
||||||
ptr, err := unmarshalPointer[Owner](
|
ptr, err := unmarshalPointer(
|
||||||
b,
|
b,
|
||||||
parseOwner,
|
parseOwner,
|
||||||
)
|
)
|
||||||
|
@ -361,6 +361,46 @@ func TestUnmarshalPolicy(t *testing.T) {
|
|||||||
`,
|
`,
|
||||||
wantErr: `AutoGroup is invalid, got: "autogroup:invalid", must be one of [autogroup:internet]`,
|
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 {
|
cmps := append(util.Comparers, cmp.Comparer(func(x, y Prefix) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user