mirror of
https://github.com/netbirdio/netbird.git
synced 2025-08-20 11:33:07 +02:00
Add single Unix/Windows path check in process tests
This commit is contained in:
@@ -27,14 +27,14 @@ func (p *ProcessCheck) Check(peer nbpeer.Peer) (bool, error) {
|
|||||||
switch peer.Meta.GoOS {
|
switch peer.Meta.GoOS {
|
||||||
case "darwin", "linux":
|
case "darwin", "linux":
|
||||||
for _, process := range p.Processes {
|
for _, process := range p.Processes {
|
||||||
if !slices.Contains(peerActiveProcesses, process.Path) {
|
if process.Path == "" || !slices.Contains(peerActiveProcesses, process.Path) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
case "windows":
|
case "windows":
|
||||||
for _, process := range p.Processes {
|
for _, process := range p.Processes {
|
||||||
if !slices.Contains(peerActiveProcesses, process.WindowsPath) {
|
if process.WindowsPath == "" || !slices.Contains(peerActiveProcesses, process.WindowsPath) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -35,6 +35,26 @@ func TestProcessCheck_Check(t *testing.T) {
|
|||||||
wantErr: false,
|
wantErr: false,
|
||||||
isValid: true,
|
isValid: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "darwin with windows process paths",
|
||||||
|
input: peer.Peer{
|
||||||
|
Meta: peer.PeerSystemMeta{
|
||||||
|
GoOS: "darwin",
|
||||||
|
Processes: []peer.Process{
|
||||||
|
{Path: "process1"},
|
||||||
|
{Path: "process2"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
check: ProcessCheck{
|
||||||
|
Processes: []Process{
|
||||||
|
{WindowsPath: "process1"},
|
||||||
|
{WindowsPath: "process2"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
isValid: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "linux with matching processes",
|
name: "linux with matching processes",
|
||||||
input: peer.Peer{
|
input: peer.Peer{
|
||||||
@@ -55,6 +75,26 @@ func TestProcessCheck_Check(t *testing.T) {
|
|||||||
wantErr: false,
|
wantErr: false,
|
||||||
isValid: true,
|
isValid: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "linux with windows process paths",
|
||||||
|
input: peer.Peer{
|
||||||
|
Meta: peer.PeerSystemMeta{
|
||||||
|
GoOS: "linux",
|
||||||
|
Processes: []peer.Process{
|
||||||
|
{Path: "process1"},
|
||||||
|
{Path: "process2"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
check: ProcessCheck{
|
||||||
|
Processes: []Process{
|
||||||
|
{WindowsPath: "process1"},
|
||||||
|
{WindowsPath: "process2"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
isValid: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "linux with non-matching processes",
|
name: "linux with non-matching processes",
|
||||||
input: peer.Peer{
|
input: peer.Peer{
|
||||||
@@ -95,6 +135,26 @@ func TestProcessCheck_Check(t *testing.T) {
|
|||||||
wantErr: false,
|
wantErr: false,
|
||||||
isValid: true,
|
isValid: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "windows with darwin process paths",
|
||||||
|
input: peer.Peer{
|
||||||
|
Meta: peer.PeerSystemMeta{
|
||||||
|
GoOS: "windows",
|
||||||
|
Processes: []peer.Process{
|
||||||
|
{Path: "process1"},
|
||||||
|
{Path: "process2"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
check: ProcessCheck{
|
||||||
|
Processes: []Process{
|
||||||
|
{Path: "process1"},
|
||||||
|
{Path: "process2"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
isValid: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "windows with non-matching processes",
|
name: "windows with non-matching processes",
|
||||||
input: peer.Peer{
|
input: peer.Peer{
|
||||||
|
Reference in New Issue
Block a user