Files
Reims-Go/internal/guesttools/clipboard_path_windows_test.go
T

46 lines
1.5 KiB
Go

package guesttools
import (
"errors"
"os"
"path/filepath"
"testing"
"golang.org/x/sys/windows"
)
func TestClipboardFilesRequireLocalDrive(t *testing.T) {
file := filepath.Join(t.TempDir(), "copied.txt")
if err := os.WriteFile(file, []byte("local"), 0600); err != nil {
t.Fatal(err)
}
original := clipboardDriveType
t.Cleanup(func() { clipboardDriveType = original })
root := filepath.VolumeName(file) + string(os.PathSeparator)
driveType := uint32(windows.DRIVE_FIXED)
clipboardDriveType = func(rootPtr *uint16) uint32 {
if got := windows.UTF16PtrToString(rootPtr); got != root {
t.Fatalf("GetDriveType root = %q, want %q", got, root)
}
return driveType
}
paths := []string{file}
fsys := &dropWebDAVFS{store: newDropShareStore(), allowClipboard: func() bool { return true }}
if !fsys.store.ensure("clip", prepareClipboardFiles(paths)) {
t.Fatal("local clipboard registration failed")
}
for _, driveType = range []uint32{windows.DRIVE_FIXED, windows.DRIVE_REMOVABLE, windows.DRIVE_RAMDISK, windows.DRIVE_CDROM} {
if len(prepareClipboardFiles(paths)) != 1 {
t.Errorf("local drive type %d was filtered out", driveType)
}
}
for _, driveType = range []uint32{windows.DRIVE_REMOTE, windows.DRIVE_UNKNOWN, windows.DRIVE_NO_ROOT_DIR} {
if len(prepareClipboardFiles(paths)) != 0 {
t.Errorf("drive type %d was accepted", driveType)
}
if _, err := fsys.Stat(t.Context(), "/clip/copied.txt"); !errors.Is(err, os.ErrPermission) {
t.Errorf("read previously local file on drive type %d: %v", driveType, err)
}
}
}