drive: don't allow DELETE on read-only shares

Fixes tailscale/corp#19646

Signed-off-by: Percy Wegmann <percy@tailscale.com>
(cherry picked from commit 2648d475d7)
Signed-off-by: Percy Wegmann <percy@tailscale.com>
percy/cherry-pick-2648d475d751b47755958f47a366e300b6b6de0a
Percy Wegmann 6 months ago
parent ede81e2669
commit 9300c8effe
No known key found for this signature in database
GPG Key ID: 29D8CDEB4C13D48B

@ -82,12 +82,33 @@ func TestFileManipulation(t *testing.T) {
s.checkFileContents(remote1, share11, file111) s.checkFileContents(remote1, share11, file111)
s.addShare(remote1, share12, drive.PermissionReadOnly) s.addShare(remote1, share12, drive.PermissionReadOnly)
s.writeFile("writing file to read-only remote should fail", remote1, share12, file111, "hello world", false)
s.writeFile("writing file to non-existent remote should fail", "non-existent", share11, file111, "hello world", false) s.writeFile("writing file to non-existent remote should fail", "non-existent", share11, file111, "hello world", false)
s.writeFile("writing file to non-existent share should fail", remote1, "non-existent", file111, "hello world", false) s.writeFile("writing file to non-existent share should fail", remote1, "non-existent", file111, "hello world", false)
} }
func TestPermissions(t *testing.T) {
s := newSystem(t)
s.addRemote(remote1)
s.addShare(remote1, share12, drive.PermissionReadOnly)
s.writeFile("writing file to read-only remote should fail", remote1, share12, file111, "hello world", false)
if err := s.client.Mkdir(path.Join(remote1, share12), 0644); err == nil {
t.Error("making directory on read-only remote should fail")
}
// Now, write file directly to file system so that we can test permissions
// on other operations.
s.write(remote1, share12, file111, "hello world")
if err := s.client.Remove(pathTo(remote1, share12, file111)); err == nil {
t.Error("deleting file from read-only remote should fail")
}
if err := s.client.Rename(pathTo(remote1, share12, file111), pathTo(remote1, share12, "another"), true); err == nil {
t.Error("moving file on read-only remote should fail")
}
}
type local struct { type local struct {
l net.Listener l net.Listener
fs *FileSystemForLocal fs *FileSystemForLocal
@ -308,6 +329,14 @@ func (s *system) read(remoteName, shareName, name string) string {
return string(b) return string(b)
} }
func (s *system) write(remoteName, shareName, name, contents string) {
filename := filepath.Join(s.remotes[remoteName].shares[shareName], name)
err := os.WriteFile(filename, []byte(contents), 0644)
if err != nil {
s.t.Fatalf("failed to WriteFile: %s", err)
}
}
func (s *system) readViaWebDAV(remoteName, shareName, name string) string { func (s *system) readViaWebDAV(remoteName, shareName, name string) string {
path := pathTo(remoteName, shareName, name) path := pathTo(remoteName, shareName, name)
b, err := s.client.Read(path) b, err := s.client.Read(path)

@ -380,6 +380,7 @@ var writeMethods = map[string]bool{
"MKCOL": true, "MKCOL": true,
"MOVE": true, "MOVE": true,
"PROPPATCH": true, "PROPPATCH": true,
"DELETE": true,
} }
// canSudo checks wether we can sudo -u the configured executable as the // canSudo checks wether we can sudo -u the configured executable as the

Loading…
Cancel
Save