Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
ssh: fix a bug in dropping privileges on Linux
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Dongsu Park committed Oct 21, 2016
1 parent b42d8bf commit 3f2cc17
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ssh/known_hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"io/ioutil"
"net"
"os"
"runtime"
"strconv"
"syscall"
"testing"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 3f2cc17

Please sign in to comment.