ssh commands: send a generic error for unexpected failures

and log the real error, it could leak a filesystem path
This commit is contained in:
Nicola Murino
2020-06-29 18:53:33 +02:00
parent 4814786556
commit dd593b1035
2 changed files with 31 additions and 3 deletions

View File

@@ -2163,3 +2163,28 @@ func TestRecursiveCopyErrors(t *testing.T) {
err = sshCmd.checkRecursiveCopyPermissions("adir", "another", "/another")
assert.Error(t, err)
}
func TestSSHMappedError(t *testing.T) {
user := dataprovider.User{
HomeDir: os.TempDir(),
}
fs, err := user.GetFilesystem("123")
assert.NoError(t, err)
conn := Connection{
User: user,
fs: fs,
}
sshCommand := sshCommand{
command: "test",
connection: conn,
args: []string{},
}
err = sshCommand.getMappedError(os.ErrNotExist)
assert.EqualError(t, err, errNotExist.Error())
err = sshCommand.getMappedError(os.ErrPermission)
assert.EqualError(t, err, errPermissionDenied.Error())
err = sshCommand.getMappedError(os.ErrInvalid)
assert.EqualError(t, err, errGenericFailure.Error())
err = sshCommand.getMappedError(os.ErrNoDeadline)
assert.EqualError(t, err, errGenericFailure.Error())
}