From 4aa58e28df50bb4850e59977087a32585e8ebef3 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Thu, 13 Jul 2023 00:40:36 +0200 Subject: [PATCH] Remove base path checks during sync --- libs/sync/path.go | 41 ----------------------------------------- libs/sync/path_test.go | 31 ------------------------------- 2 files changed, 72 deletions(-) diff --git a/libs/sync/path.go b/libs/sync/path.go index 7fd1b9a976..a04c28d30b 100644 --- a/libs/sync/path.go +++ b/libs/sync/path.go @@ -13,42 +13,6 @@ import ( "github.com/databricks/databricks-sdk-go/service/workspace" ) -// Return if the child path is nested under the parent path. -func isPathNestedUnder(child, parent string) bool { - child = path.Clean(child) - parent = path.Clean(parent) - - // Traverse up the tree as long as "child" is contained in "parent". - for len(child) > len(parent) && strings.HasPrefix(child, parent) { - child = path.Dir(child) - if child == parent { - return true - } - } - return false -} - -// Check if the specified path is nested under one of the allowed base paths. -func checkPathNestedUnderBasePaths(me *iam.User, p string) error { - validBasePaths := []string{ - path.Clean(fmt.Sprintf("/Users/%s", me.UserName)), - path.Clean(fmt.Sprintf("/Repos/%s", me.UserName)), - } - - givenBasePath := path.Clean(p) - match := false - for _, basePath := range validBasePaths { - if isPathNestedUnder(givenBasePath, basePath) { - match = true - break - } - } - if !match { - return fmt.Errorf("path must be nested under %s", strings.Join(validBasePaths, " or ")) - } - return nil -} - func repoPathForPath(me *iam.User, remotePath string) string { base := path.Clean(fmt.Sprintf("/Repos/%s", me.UserName)) remotePath = path.Clean(remotePath) @@ -66,11 +30,6 @@ func EnsureRemotePathIsUsable(ctx context.Context, wsc *databricks.WorkspaceClie return err } - err = checkPathNestedUnderBasePaths(me, remotePath) - if err != nil { - return err - } - // Ensure that the remote path exists. // If it is a repo, it has to exist. // If it is a workspace path, it may not exist. diff --git a/libs/sync/path_test.go b/libs/sync/path_test.go index 18475c9269..2d492251f2 100644 --- a/libs/sync/path_test.go +++ b/libs/sync/path_test.go @@ -7,37 +7,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestPathNestedUnderBasePaths(t *testing.T) { - me := iam.User{ - UserName: "jane@doe.com", - } - - // Not nested under allowed base paths. - assert.Error(t, checkPathNestedUnderBasePaths(&me, "/Repos/jane@doe.com")) - assert.Error(t, checkPathNestedUnderBasePaths(&me, "/Repos/jane@doe.com/.")) - assert.Error(t, checkPathNestedUnderBasePaths(&me, "/Repos/jane@doe.com/..")) - assert.Error(t, checkPathNestedUnderBasePaths(&me, "/Repos/john@doe.com")) - assert.Error(t, checkPathNestedUnderBasePaths(&me, "/Repos/jane@doe.comsuffix/foo")) - assert.Error(t, checkPathNestedUnderBasePaths(&me, "/Repos/")) - assert.Error(t, checkPathNestedUnderBasePaths(&me, "/Repos")) - assert.Error(t, checkPathNestedUnderBasePaths(&me, "/Users/jane@doe.com")) - assert.Error(t, checkPathNestedUnderBasePaths(&me, "/Users/jane@doe.com/.")) - assert.Error(t, checkPathNestedUnderBasePaths(&me, "/Users/jane@doe.com/..")) - assert.Error(t, checkPathNestedUnderBasePaths(&me, "/Users/john@doe.com")) - assert.Error(t, checkPathNestedUnderBasePaths(&me, "/Users/jane@doe.comsuffix/foo")) - assert.Error(t, checkPathNestedUnderBasePaths(&me, "/Users/")) - assert.Error(t, checkPathNestedUnderBasePaths(&me, "/Users")) - assert.Error(t, checkPathNestedUnderBasePaths(&me, "/")) - - // Nested under allowed base paths. - assert.NoError(t, checkPathNestedUnderBasePaths(&me, "/Repos/jane@doe.com/foo")) - assert.NoError(t, checkPathNestedUnderBasePaths(&me, "/Repos/jane@doe.com/./foo")) - assert.NoError(t, checkPathNestedUnderBasePaths(&me, "/Repos/jane@doe.com/foo/bar/qux")) - assert.NoError(t, checkPathNestedUnderBasePaths(&me, "/Users/jane@doe.com/foo")) - assert.NoError(t, checkPathNestedUnderBasePaths(&me, "/Users/jane@doe.com/./foo")) - assert.NoError(t, checkPathNestedUnderBasePaths(&me, "/Users/jane@doe.com/foo/bar/qux")) -} - func TestPathToRepoPath(t *testing.T) { me := iam.User{ UserName: "jane@doe.com",