summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cli/cli_test.go24
-rw-r--r--tests/test_helpers/helpers.go11
2 files changed, 32 insertions, 3 deletions
diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go
index 8808742..5508360 100644
--- a/tests/cli/cli_test.go
+++ b/tests/cli/cli_test.go
@@ -449,6 +449,30 @@ func TestMultipleOperationFlags(t *testing.T) {
}
}
+func TestNoexec(t *testing.T) {
+ dir := test_helpers.InitFS(t)
+ mnt := dir + ".mnt"
+ err := os.Mkdir(mnt, 0700)
+ if err != nil {
+ t.Fatal(err)
+ }
+ test_helpers.MountOrFatal(t, dir, mnt, "-extpass=echo test", "-noexec")
+ defer test_helpers.UnmountPanic(mnt)
+ sh := mnt + "/x.sh"
+ content := `#!/bin/bash
+echo hello
+`
+ err = ioutil.WriteFile(sh, []byte(content), 0755)
+ if err != nil {
+ t.Fatal(err)
+ }
+ err = exec.Command(sh).Run()
+ exitCode := test_helpers.ExtractCmdExitCode(err)
+ if exitCode != int(syscall.EACCES) {
+ t.Errorf("got exitcode %d instead of EPERM (%d)", exitCode, syscall.EPERM)
+ }
+}
+
// Test that a missing argument to "-o" triggers exit code 1.
// See also cli_args_test.go for comprehensive tests of "-o" parsing.
func TestMissingOArg(t *testing.T) {
diff --git a/tests/test_helpers/helpers.go b/tests/test_helpers/helpers.go
index e7fcf4b..ef748e2 100644
--- a/tests/test_helpers/helpers.go
+++ b/tests/test_helpers/helpers.go
@@ -433,9 +433,14 @@ func ExtractCmdExitCode(err error) int {
return 0
}
// OMG this is convoluted
- err2 := err.(*exec.ExitError)
- code := err2.Sys().(syscall.WaitStatus).ExitStatus()
- return code
+ if err2, ok := err.(*exec.ExitError); ok {
+ return err2.Sys().(syscall.WaitStatus).ExitStatus()
+ }
+ if err2, ok := err.(*os.PathError); ok {
+ return int(err2.Err.(syscall.Errno))
+ }
+ log.Panicf("could not decode error %#v", err)
+ return 0
}
// ListFds lists our open file descriptors.