mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-20 19:09:07 +01:00
chore(format): run prettier on repo
This commit is contained in:
parent
4bbe0051f6
commit
25550f8866
@ -920,7 +920,9 @@ func Test_expandAlias(t *testing.T) {
|
|||||||
},
|
},
|
||||||
aclPolicy: ACLPolicy{
|
aclPolicy: ACLPolicy{
|
||||||
Groups: Groups{"group:accountant": []string{"joe", "marc"}},
|
Groups: Groups{"group:accountant": []string{"joe", "marc"}},
|
||||||
TagOwners: TagOwners{"tag:accountant-webserver": []string{"group:accountant"}},
|
TagOwners: TagOwners{
|
||||||
|
"tag:accountant-webserver": []string{"group:accountant"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: []string{},
|
want: []string{},
|
||||||
|
23
machine.go
23
machine.go
@ -143,12 +143,22 @@ func containsAddresses(inputs []string, addrs []string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// matchSourceAndDestinationWithRule.
|
// matchSourceAndDestinationWithRule.
|
||||||
func matchSourceAndDestinationWithRule(ruleSources []string, ruleDestinations []string, source []string, destination []string) bool {
|
func matchSourceAndDestinationWithRule(
|
||||||
return containsAddresses(ruleSources, source) && containsAddresses(ruleDestinations, destination)
|
ruleSources []string,
|
||||||
|
ruleDestinations []string,
|
||||||
|
source []string,
|
||||||
|
destination []string,
|
||||||
|
) bool {
|
||||||
|
return containsAddresses(ruleSources, source) &&
|
||||||
|
containsAddresses(ruleDestinations, destination)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getFilteredByACLPeerss should return the list of peers authorized to be accessed from machine.
|
// getFilteredByACLPeerss should return the list of peers authorized to be accessed from machine.
|
||||||
func getFilteredByACLPeers(machines []Machine, rules []tailcfg.FilterRule, machine *Machine) Machines {
|
func getFilteredByACLPeers(
|
||||||
|
machines []Machine,
|
||||||
|
rules []tailcfg.FilterRule,
|
||||||
|
machine *Machine,
|
||||||
|
) Machines {
|
||||||
log.Trace().
|
log.Trace().
|
||||||
Caller().
|
Caller().
|
||||||
Str("machine", machine.Name).
|
Str("machine", machine.Name).
|
||||||
@ -181,7 +191,12 @@ func getFilteredByACLPeers(machines []Machine, rules []tailcfg.FilterRule, machi
|
|||||||
for _, d := range rule.DstPorts {
|
for _, d := range rule.DstPorts {
|
||||||
dst = append(dst, d.IP)
|
dst = append(dst, d.IP)
|
||||||
}
|
}
|
||||||
if matchSourceAndDestinationWithRule(rule.SrcIPs, dst, machine.IPAddresses.ToStringSlice(), peer.IPAddresses.ToStringSlice()) || // match source and destination
|
if matchSourceAndDestinationWithRule(
|
||||||
|
rule.SrcIPs,
|
||||||
|
dst,
|
||||||
|
machine.IPAddresses.ToStringSlice(),
|
||||||
|
peer.IPAddresses.ToStringSlice(),
|
||||||
|
) || // match source and destination
|
||||||
matchSourceAndDestinationWithRule(rule.SrcIPs, dst, machine.IPAddresses.ToStringSlice(), []string{"*"}) || // match source and all destination
|
matchSourceAndDestinationWithRule(rule.SrcIPs, dst, machine.IPAddresses.ToStringSlice(), []string{"*"}) || // match source and all destination
|
||||||
matchSourceAndDestinationWithRule(rule.SrcIPs, dst, peer.IPAddresses.ToStringSlice(), machine.IPAddresses.ToStringSlice()) { // match return path
|
matchSourceAndDestinationWithRule(rule.SrcIPs, dst, peer.IPAddresses.ToStringSlice(), machine.IPAddresses.ToStringSlice()) { // match return path
|
||||||
peers[peer.ID] = peer
|
peers[peer.ID] = peer
|
||||||
|
@ -313,17 +313,23 @@ func Test_getFilteredByACLPeers(t *testing.T) {
|
|||||||
machines: []Machine{ // list of all machines in the database
|
machines: []Machine{ // list of all machines in the database
|
||||||
{
|
{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
IPAddresses: MachineAddresses{netaddr.MustParseIP("100.64.0.1")},
|
IPAddresses: MachineAddresses{
|
||||||
|
netaddr.MustParseIP("100.64.0.1"),
|
||||||
|
},
|
||||||
Namespace: Namespace{Name: "joe"},
|
Namespace: Namespace{Name: "joe"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: 2,
|
ID: 2,
|
||||||
IPAddresses: MachineAddresses{netaddr.MustParseIP("100.64.0.2")},
|
IPAddresses: MachineAddresses{
|
||||||
|
netaddr.MustParseIP("100.64.0.2"),
|
||||||
|
},
|
||||||
Namespace: Namespace{Name: "marc"},
|
Namespace: Namespace{Name: "marc"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: 3,
|
ID: 3,
|
||||||
IPAddresses: MachineAddresses{netaddr.MustParseIP("100.64.0.3")},
|
IPAddresses: MachineAddresses{
|
||||||
|
netaddr.MustParseIP("100.64.0.3"),
|
||||||
|
},
|
||||||
Namespace: Namespace{Name: "mickael"},
|
Namespace: Namespace{Name: "mickael"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -360,17 +366,23 @@ func Test_getFilteredByACLPeers(t *testing.T) {
|
|||||||
machines: []Machine{ // list of all machines in the database
|
machines: []Machine{ // list of all machines in the database
|
||||||
{
|
{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
IPAddresses: MachineAddresses{netaddr.MustParseIP("100.64.0.1")},
|
IPAddresses: MachineAddresses{
|
||||||
|
netaddr.MustParseIP("100.64.0.1"),
|
||||||
|
},
|
||||||
Namespace: Namespace{Name: "joe"},
|
Namespace: Namespace{Name: "joe"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: 2,
|
ID: 2,
|
||||||
IPAddresses: MachineAddresses{netaddr.MustParseIP("100.64.0.2")},
|
IPAddresses: MachineAddresses{
|
||||||
|
netaddr.MustParseIP("100.64.0.2"),
|
||||||
|
},
|
||||||
Namespace: Namespace{Name: "marc"},
|
Namespace: Namespace{Name: "marc"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: 3,
|
ID: 3,
|
||||||
IPAddresses: MachineAddresses{netaddr.MustParseIP("100.64.0.3")},
|
IPAddresses: MachineAddresses{
|
||||||
|
netaddr.MustParseIP("100.64.0.3"),
|
||||||
|
},
|
||||||
Namespace: Namespace{Name: "mickael"},
|
Namespace: Namespace{Name: "mickael"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -402,17 +414,23 @@ func Test_getFilteredByACLPeers(t *testing.T) {
|
|||||||
machines: []Machine{ // list of all machines in the database
|
machines: []Machine{ // list of all machines in the database
|
||||||
{
|
{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
IPAddresses: MachineAddresses{netaddr.MustParseIP("100.64.0.1")},
|
IPAddresses: MachineAddresses{
|
||||||
|
netaddr.MustParseIP("100.64.0.1"),
|
||||||
|
},
|
||||||
Namespace: Namespace{Name: "joe"},
|
Namespace: Namespace{Name: "joe"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: 2,
|
ID: 2,
|
||||||
IPAddresses: MachineAddresses{netaddr.MustParseIP("100.64.0.2")},
|
IPAddresses: MachineAddresses{
|
||||||
|
netaddr.MustParseIP("100.64.0.2"),
|
||||||
|
},
|
||||||
Namespace: Namespace{Name: "marc"},
|
Namespace: Namespace{Name: "marc"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: 3,
|
ID: 3,
|
||||||
IPAddresses: MachineAddresses{netaddr.MustParseIP("100.64.0.3")},
|
IPAddresses: MachineAddresses{
|
||||||
|
netaddr.MustParseIP("100.64.0.3"),
|
||||||
|
},
|
||||||
Namespace: Namespace{Name: "mickael"},
|
Namespace: Namespace{Name: "mickael"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -441,7 +459,11 @@ func Test_getFilteredByACLPeers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got := getFilteredByACLPeers(tt.args.machines, tt.args.rules, tt.args.machine)
|
got := getFilteredByACLPeers(
|
||||||
|
tt.args.machines,
|
||||||
|
tt.args.rules,
|
||||||
|
tt.args.machine,
|
||||||
|
)
|
||||||
if !reflect.DeepEqual(got, tt.want) {
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
t.Errorf("getFilteredByACLPeers() = %v, want %v", got, tt.want)
|
t.Errorf("getFilteredByACLPeers() = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user