Skip to content

Commit

Permalink
drive: don't allow LOCK and UNLOCK methods
Browse files Browse the repository at this point in the history
Temporarily disables support for locking until we reimplement it properly.

Updates #12097

Signed-off-by: Percy Wegmann <percy@tailscale.com>
  • Loading branch information
oxtoacart committed May 14, 2024
1 parent 7ef2f72 commit 89fe11b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drive/driveimpl/compositedav/compositedav.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ var cacheInvalidatingMethods = map[string]bool{

// ServeHTTP implements http.Handler.
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Method == "PROPFIND" {
switch r.Method {
case "LOCK", "UNLOCK":
http.Error(w, "locking is not currently supported", http.StatusMethodNotAllowed)
return
case "PROPFIND":
h.handlePROPFIND(w, r)
return
}
Expand Down
34 changes: 34 additions & 0 deletions drive/driveimpl/drive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,40 @@ func TestSecretTokenAuth(t *testing.T) {
}
}

func TestLocking(t *testing.T) {
s := newSystem(t)

s.addRemote(remote1)
s.addShare(remote1, share11, drive.PermissionReadWrite)
s.writeFile("writing file to read/write remote should succeed", remote1, share11, file111, "hello world", true)

client := &http.Client{
Transport: &http.Transport{DisableKeepAlives: true},
}

u := fmt.Sprintf("http://%s/%s/%s/%s/%s",
s.local.l.Addr(),
url.PathEscape(domain),
url.PathEscape(remote1),
url.PathEscape(share11),
url.PathEscape(file111))

for _, method := range []string{"LOCK", "UNLOCK"} {
req, err := http.NewRequest(method, u, strings.NewReader(lockBody))

Check failure on line 167 in drive/driveimpl/drive_test.go

View workflow job for this annotation

GitHub Actions / windows

undefined: lockBody
if err != nil {
t.Fatal(err)
}
resp, err := client.Do(req)
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusMethodNotAllowed {
t.Fatalf("expected %s to fail with 405, but got status %d", method, resp.StatusCode)
}
}
}

type local struct {
l net.Listener
fs *FileSystemForLocal
Expand Down

0 comments on commit 89fe11b

Please sign in to comment.