From 9156dd309251ca397f6fd644e11fd040af19584d Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Fri, 21 Oct 2016 11:29:37 +0200 Subject: [PATCH] ssh: fix a bug in dropping privileges on Linux On Linux syscall.Setuid() is not supported in go. So running unit tests with root privileges fails when calling Setuid. Let's skip the test on Linux, if euid is 0. --- ssh/known_hosts_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ssh/known_hosts_test.go b/ssh/known_hosts_test.go index 13a230117..1d9ab7ab0 100644 --- a/ssh/known_hosts_test.go +++ b/ssh/known_hosts_test.go @@ -19,6 +19,7 @@ import ( "io/ioutil" "net" "os" + "runtime" "strconv" "syscall" "testing" @@ -165,7 +166,13 @@ func TestWrongHostKeyFile(t *testing.T) { // If run as root, drop privileges temporarily if id := syscall.Geteuid(); id == 0 { if err := syscall.Setuid(12345); err != nil { - t.Fatalf("error setting uid: %v", err) + if runtime.GOOS == "linux" { + // On Linux syscall.Setuid is not supported, so we should not fail + // the test, but just skip for now. - dpark 20161021 + t.Skipf("error setting uid: %v", err) + } else { + t.Fatalf("error setting uid: %v", err) + } } defer syscall.Setuid(id) }