From 05acf76392b558613876fdeadef47050b135c995 Mon Sep 17 00:00:00 2001 From: Percy Wegmann Date: Tue, 27 Feb 2024 07:54:24 -0600 Subject: [PATCH] tailfs: fix race condition in tailfs_test Ues a noop authenticator to avoid potential races in gowebdav's built-in authenticator. Fixes #11259 Signed-off-by: Percy Wegmann --- tailfs/tailfsimpl/tailfs_test.go | 33 +++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tailfs/tailfsimpl/tailfs_test.go b/tailfs/tailfsimpl/tailfs_test.go index 42936585e..e8a729144 100644 --- a/tailfs/tailfsimpl/tailfs_test.go +++ b/tailfs/tailfsimpl/tailfs_test.go @@ -5,6 +5,7 @@ package tailfsimpl import ( "fmt" + "io" "io/fs" "log" "net" @@ -142,7 +143,7 @@ func newSystem(t *testing.T) *system { } }() - client := gowebdav.NewClient(fmt.Sprintf("http://%s", l.Addr()), "", "") + client := gowebdav.NewAuthClient(fmt.Sprintf("http://%s", l.Addr()), &noopAuthorizer{}) client.SetTransport(&http.Transport{DisableKeepAlives: true}) s := &system{ t: t, @@ -375,3 +376,33 @@ func fileInfoToStatic(fi fs.FileInfo, fixupMode bool) fs.FileInfo { func pathTo(remote, share, name string) string { return path.Join(domain, remote, share, name) } + +// noopAuthorizer implements gowebdav.Authorizer. It does no actual +// authorizing. We use it in place of gowebdav's built-in authorizer in order +// to avoid a race condition in that authorizer. +type noopAuthorizer struct{} + +func (a *noopAuthorizer) NewAuthenticator(body io.Reader) (gowebdav.Authenticator, io.Reader) { + return &noopAuthenticator{}, nil +} + +func (a *noopAuthorizer) AddAuthenticator(key string, fn gowebdav.AuthFactory) { +} + +type noopAuthenticator struct{} + +func (a *noopAuthenticator) Authorize(c *http.Client, rq *http.Request, path string) error { + return nil +} + +func (a *noopAuthenticator) Verify(c *http.Client, rs *http.Response, path string) (redo bool, err error) { + return false, nil +} + +func (a *noopAuthenticator) Clone() gowebdav.Authenticator { + return &noopAuthenticator{} +} + +func (a *noopAuthenticator) Close() error { + return nil +}