|
|
@ -389,12 +389,27 @@ func TestPosixMakeVol(t *testing.T) { |
|
|
|
if err = os.Chmod(permDeniedDir, 0400); err != nil { |
|
|
|
if err = os.Chmod(permDeniedDir, 0400); err != nil { |
|
|
|
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err) |
|
|
|
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Initialize posix storage layer for permission denied error.
|
|
|
|
// Initialize posix storage layer for permission denied error.
|
|
|
|
|
|
|
|
_, err = newPosix(permDeniedDir) |
|
|
|
|
|
|
|
if err != nil && !os.IsPermission(err) { |
|
|
|
|
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = os.Chmod(permDeniedDir, 0755); err != nil { |
|
|
|
|
|
|
|
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
posixStorage, err = newPosix(permDeniedDir) |
|
|
|
posixStorage, err = newPosix(permDeniedDir) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// change backend permissions for MakeVol error.
|
|
|
|
|
|
|
|
if err = os.Chmod(permDeniedDir, 0400); err != nil { |
|
|
|
|
|
|
|
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := posixStorage.MakeVol("test-vol"); err != errDiskAccessDenied { |
|
|
|
if err := posixStorage.MakeVol("test-vol"); err != errDiskAccessDenied { |
|
|
|
t.Fatalf("expected: %s, got: %s", errDiskAccessDenied, err) |
|
|
|
t.Fatalf("expected: %s, got: %s", errDiskAccessDenied, err) |
|
|
|
} |
|
|
|
} |
|
|
@ -491,13 +506,28 @@ func TestPosixDeleteVol(t *testing.T) { |
|
|
|
if err = os.Chmod(permDeniedDir, 0400); err != nil { |
|
|
|
if err = os.Chmod(permDeniedDir, 0400); err != nil { |
|
|
|
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err) |
|
|
|
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Initialize posix storage layer for permission denied error.
|
|
|
|
// Initialize posix storage layer for permission denied error.
|
|
|
|
|
|
|
|
_, err = newPosix(permDeniedDir) |
|
|
|
|
|
|
|
if err != nil && !os.IsPermission(err) { |
|
|
|
|
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = os.Chmod(permDeniedDir, 0755); err != nil { |
|
|
|
|
|
|
|
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
posixStorage, err = newPosix(permDeniedDir) |
|
|
|
posixStorage, err = newPosix(permDeniedDir) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err = posixStorage.DeleteVol("bin"); !os.IsPermission(err) { |
|
|
|
// change backend permissions for MakeVol error.
|
|
|
|
|
|
|
|
if err = os.Chmod(permDeniedDir, 0400); err != nil { |
|
|
|
|
|
|
|
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = posixStorage.DeleteVol("mybucket"); err != errDiskAccessDenied { |
|
|
|
t.Fatalf("expected: Permission error, got: %s", err) |
|
|
|
t.Fatalf("expected: Permission error, got: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -774,14 +804,22 @@ func TestPosixPosixListDir(t *testing.T) { |
|
|
|
defer removePermDeniedFile(permDeniedDir) |
|
|
|
defer removePermDeniedFile(permDeniedDir) |
|
|
|
|
|
|
|
|
|
|
|
// Initialize posix storage layer for permission denied error.
|
|
|
|
// Initialize posix storage layer for permission denied error.
|
|
|
|
|
|
|
|
_, err = newPosix(permDeniedDir) |
|
|
|
|
|
|
|
if err != nil && !os.IsPermission(err) { |
|
|
|
|
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = os.Chmod(permDeniedDir, 0755); err != nil { |
|
|
|
|
|
|
|
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
posixStorage, err = newPosix(permDeniedDir) |
|
|
|
posixStorage, err = newPosix(permDeniedDir) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
errMsg := fmt.Sprintf("stat %v: permission denied", slashpath.Join(permDeniedDir, "mybucket")) |
|
|
|
if err = posixStorage.DeleteFile("mybucket", "myobject"); err != errFileAccessDenied { |
|
|
|
if err = posixStorage.DeleteFile("mybucket", "myobject"); err.Error() != errMsg { |
|
|
|
t.Errorf("expected: %s, got: %s", errFileAccessDenied, err) |
|
|
|
t.Errorf("expected: %s, got: %s", errMsg, err) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -912,14 +950,22 @@ func TestPosixDeleteFile(t *testing.T) { |
|
|
|
defer removePermDeniedFile(permDeniedDir) |
|
|
|
defer removePermDeniedFile(permDeniedDir) |
|
|
|
|
|
|
|
|
|
|
|
// Initialize posix storage layer for permission denied error.
|
|
|
|
// Initialize posix storage layer for permission denied error.
|
|
|
|
|
|
|
|
_, err = newPosix(permDeniedDir) |
|
|
|
|
|
|
|
if err != nil && !os.IsPermission(err) { |
|
|
|
|
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = os.Chmod(permDeniedDir, 0755); err != nil { |
|
|
|
|
|
|
|
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
posixStorage, err = newPosix(permDeniedDir) |
|
|
|
posixStorage, err = newPosix(permDeniedDir) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
errMsg := fmt.Sprintf("stat %v: permission denied", slashpath.Join(permDeniedDir, "mybucket")) |
|
|
|
if err = posixStorage.DeleteFile("mybucket", "myobject"); err != errFileAccessDenied { |
|
|
|
if err = posixStorage.DeleteFile("mybucket", "myobject"); err.Error() != errMsg { |
|
|
|
t.Errorf("expected: %s, got: %s", errFileAccessDenied, err) |
|
|
|
t.Errorf("expected: %s, got: %s", errMsg, err) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1124,20 +1170,31 @@ func TestPosixReadFile(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TestPosix for permission denied.
|
|
|
|
// TestPosix for permission denied.
|
|
|
|
if runtime.GOOS == "linux" { |
|
|
|
if runtime.GOOS != globalWindowsOSName { |
|
|
|
|
|
|
|
permDeniedDir := createPermDeniedFile(t) |
|
|
|
|
|
|
|
defer removePermDeniedFile(permDeniedDir) |
|
|
|
|
|
|
|
|
|
|
|
// Initialize posix storage layer for permission denied error.
|
|
|
|
// Initialize posix storage layer for permission denied error.
|
|
|
|
posixStorage, err = newPosix("/") |
|
|
|
_, err = newPosix(permDeniedDir) |
|
|
|
|
|
|
|
if err != nil && !os.IsPermission(err) { |
|
|
|
|
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = os.Chmod(permDeniedDir, 0755); err != nil { |
|
|
|
|
|
|
|
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
posixStorage, err = newPosix(permDeniedDir) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Errorf("Unable to initialize posix, %s", err) |
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
if err == nil { |
|
|
|
|
|
|
|
// Common read buffer.
|
|
|
|
// Common read buffer.
|
|
|
|
var buf = make([]byte, 10) |
|
|
|
var buf = make([]byte, 10) |
|
|
|
if _, err = posixStorage.ReadFile("proc", "1/fd", 0, buf, nil); err != errFileAccessDenied { |
|
|
|
if _, err = posixStorage.ReadFile("mybucket", "myobject", 0, buf, nil); err != errFileAccessDenied { |
|
|
|
t.Errorf("expected: %s, got: %s", errFileAccessDenied, err) |
|
|
|
t.Errorf("expected: %s, got: %s", errFileAccessDenied, err) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TestPosixing for faulty disk.
|
|
|
|
// TestPosixing for faulty disk.
|
|
|
|
// setting ioErrCnt to 6.
|
|
|
|
// setting ioErrCnt to 6.
|
|
|
@ -1295,15 +1352,25 @@ func TestPosixAppendFile(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
var posixPermStorage StorageAPI |
|
|
|
var posixPermStorage StorageAPI |
|
|
|
// Initialize posix storage layer for permission denied error.
|
|
|
|
// Initialize posix storage layer for permission denied error.
|
|
|
|
|
|
|
|
_, err = newPosix(permDeniedDir) |
|
|
|
|
|
|
|
if err != nil && !os.IsPermission(err) { |
|
|
|
|
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = os.Chmod(permDeniedDir, 0755); err != nil { |
|
|
|
|
|
|
|
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
posixPermStorage, err = newPosix(permDeniedDir) |
|
|
|
posixPermStorage, err = newPosix(permDeniedDir) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err = posixPermStorage.AppendFile("mybucket", "myobject", []byte("hello, world")); !os.IsPermission(err) { |
|
|
|
if err = posixPermStorage.AppendFile("mybucket", "myobject", []byte("hello, world")); err != errFileAccessDenied { |
|
|
|
t.Fatalf("expected: Permission error, got: %s", err) |
|
|
|
t.Fatalf("expected: Permission error, got: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TestPosix case with invalid volume name.
|
|
|
|
// TestPosix case with invalid volume name.
|
|
|
|
// A valid volume name should be atleast of size 3.
|
|
|
|
// A valid volume name should be atleast of size 3.
|
|
|
|
err = posixStorage.AppendFile("bn", "yes", []byte("hello, world")) |
|
|
|
err = posixStorage.AppendFile("bn", "yes", []byte("hello, world")) |
|
|
@ -1386,12 +1453,21 @@ func TestPosixPrepareFile(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
var posixPermStorage StorageAPI |
|
|
|
var posixPermStorage StorageAPI |
|
|
|
// Initialize posix storage layer for permission denied error.
|
|
|
|
// Initialize posix storage layer for permission denied error.
|
|
|
|
|
|
|
|
_, err = newPosix(permDeniedDir) |
|
|
|
|
|
|
|
if err != nil && !os.IsPermission(err) { |
|
|
|
|
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err = os.Chmod(permDeniedDir, 0755); err != nil { |
|
|
|
|
|
|
|
t.Fatalf("Unable to change permission to temporary directory %v. %v", permDeniedDir, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
posixPermStorage, err = newPosix(permDeniedDir) |
|
|
|
posixPermStorage, err = newPosix(permDeniedDir) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
t.Fatalf("Unable to initialize posix, %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err = posixPermStorage.PrepareFile("mybucket", "myobject", 16); !os.IsPermission(err) { |
|
|
|
if err = posixPermStorage.PrepareFile("mybucket", "myobject", 16); err != errFileAccessDenied { |
|
|
|
t.Fatalf("expected: Permission error, got: %s", err) |
|
|
|
t.Fatalf("expected: Permission error, got: %s", err) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|