Skip to content

Commit

Permalink
Issue #2362 Check for username/uid for permission test
Browse files Browse the repository at this point in the history
  • Loading branch information
gbraad authored and praveenkumar committed May 9, 2018
1 parent 6a4b8bc commit 8520eab
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build:
image: registry.centos.org/gbraad/minishift-build:latest
image: registry.centos.org/minishift/minishift-build:latest
tags:
- docker
script:
Expand Down
12 changes: 12 additions & 0 deletions pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io"
"os"
"os/user"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -195,3 +196,14 @@ func IsDirectoryWritable(path string) bool {

return true
}

// IsAdministrativeUser returns true when user is either root or
// Administrator
func IsAdministrativeUser() bool {
u, _ := user.Current()
username := strings.ToLower(u.Username)

return u.Uid == "1" ||
username == "root" ||
strings.Contains(username, "administrator")
}
14 changes: 12 additions & 2 deletions pkg/util/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ package util
import (
"fmt"
"os"
"os/user"
"path/filepath"
"runtime"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -217,8 +219,9 @@ func TestWritableDirectory(t *testing.T) {
}

func TestNonWritableDirectory(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping as Appveyor CI is running in administrator mode")
if isAppVeyorUser() ||
IsAdministrativeUser() {
t.Skip("Skipping as CI runs as root or administrator")
}

testDir, err := ioutil.TempDir("", "minishift-test-")
Expand All @@ -227,4 +230,11 @@ func TestNonWritableDirectory(t *testing.T) {

os.Chmod(testDir, 0400) // make dir read-only
assert.False(t, IsDirectoryWritable(testDir))

}

func isAppVeyorUser() bool {
// Checking for $env:APPVEYOR does not work !
u, _ := user.Current()
return strings.Contains(u.Username, "appveyor")
}

0 comments on commit 8520eab

Please sign in to comment.