fix(client): update icmp/ping logic to determine pinger privileged mode (#1346)
* fix(pinger): update logic to determine pinger privileged mode * add some unit tests for pinger Signed-off-by: Zee Aslam <zeet6613@gmail.com> * undo accidental removal Signed-off-by: Zee Aslam <zeet6613@gmail.com> * check for cap_net_raw by trying to open a raw socket and checking for permission error Signed-off-by: Zee Aslam <zeet6613@gmail.com> * revert syscall after testing. It is unable to build a binary on windows Signed-off-by: Zee Aslam <zeet6613@gmail.com> * remove extra import * review icmp section of readme. No changes required Signed-off-by: Zee Aslam <zeet6613@gmail.com> * Update client/client.go Co-authored-by: TwiN <twin@linux.com> * Update client/client.go Match function name Co-authored-by: TwiN <twin@linux.com> * Update client/client.go Remove extra line Co-authored-by: TwiN <twin@linux.com> --------- Signed-off-by: Zee Aslam <zeet6613@gmail.com> Co-authored-by: TwiN <twin@linux.com>
This commit is contained in:
@@ -6,6 +6,8 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -129,6 +131,33 @@ func TestPing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestShouldRunPingerAsPrivileged(t *testing.T) {
|
||||
// Don't run in parallel since we're testing system-dependent behavior
|
||||
if runtime.GOOS == "windows" {
|
||||
result := ShouldRunPingerAsPrivileged()
|
||||
if !result {
|
||||
t.Error("On Windows, ShouldRunPingerAsPrivileged() should return true")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Non-Windows tests
|
||||
result := ShouldRunPingerAsPrivileged()
|
||||
isRoot := os.Geteuid() == 0
|
||||
|
||||
// Test cases based on current environment
|
||||
if isRoot {
|
||||
if !result {
|
||||
t.Error("When running as root, ShouldRunPingerAsPrivileged() should return true")
|
||||
}
|
||||
} else {
|
||||
// When not root, the result depends on raw socket creation
|
||||
// We can at least verify the function runs without panic
|
||||
t.Logf("Non-root privileged result: %v", result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func TestCanPerformStartTLS(t *testing.T) {
|
||||
type args struct {
|
||||
address string
|
||||
|
||||
Reference in New Issue
Block a user