Shaman: fail unit test when running as root user
If the mock tests are run by root user then this specific test of inaccessible path fails because root can write files to anywhere on the filesystem. It is not clear that Flamenco Manager test TestCheckSharedStoragePath is checking inaccessible file locations when it fails and that it should be run by an unprivileged user. Fix is to fail the permission test if the tests are run as a root user.
This commit is contained in:
parent
7a508c7e6b
commit
b20ede97ea
@ -6,6 +6,7 @@ import (
|
|||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
@ -189,6 +190,16 @@ func TestCheckSharedStoragePath(t *testing.T) {
|
|||||||
// that seems consistent.
|
// that seems consistent.
|
||||||
// FIXME: find another way to test with unwritable directories on Windows.
|
// FIXME: find another way to test with unwritable directories on Windows.
|
||||||
if runtime.GOOS != "windows" {
|
if runtime.GOOS != "windows" {
|
||||||
|
|
||||||
|
// Root can always create directories, so this test would fail with a
|
||||||
|
// confusing message. Instead it's better to refuse running as root at all.
|
||||||
|
currentUser, err := user.Current()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotEqual(t, "0", currentUser.Uid,
|
||||||
|
"this test requires running as normal user, not %s (%s)", currentUser.Username, currentUser.Uid)
|
||||||
|
require.NotEqual(t, "root", currentUser.Username,
|
||||||
|
"this test requires running as normal user, not %s (%s)", currentUser.Username, currentUser.Uid)
|
||||||
|
|
||||||
parentPath := filepath.Join(mf.tempdir, "deep")
|
parentPath := filepath.Join(mf.tempdir, "deep")
|
||||||
testPath := filepath.Join(parentPath, "nesting")
|
testPath := filepath.Join(parentPath, "nesting")
|
||||||
if err := os.Mkdir(parentPath, fs.ModePerm); !assert.NoError(t, err) {
|
if err := os.Mkdir(parentPath, fs.ModePerm); !assert.NoError(t, err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user