-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make local files default for fs commands #506
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3eeac39
[WIP] Remove support for file scheme
shreyas-goenka 78c60d2
added test
shreyas-goenka b6d4ce7
added tests
shreyas-goenka bbdfb99
Merge remote-tracking branch 'origin' into remove-file-scheme
shreyas-goenka 55c5cb4
-
shreyas-goenka 06311d0
remove dbfs integration testt
shreyas-goenka 12c8ab2
add tests for local root path
shreyas-goenka b1a1c61
fix tests
shreyas-goenka d1f1772
fix tests
shreyas-goenka 6ecfa4d
Merge branch 'main' into remove-file-scheme
shreyas-goenka 2e69c2a
fix integration tests
shreyas-goenka 2d88bac
merge
shreyas-goenka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package filer | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
type localRootPath struct { | ||
rootPath string | ||
} | ||
|
||
func NewLocalRootPath(root string) localRootPath { | ||
if root == "" { | ||
return localRootPath{""} | ||
} | ||
return localRootPath{filepath.Clean(root)} | ||
} | ||
|
||
func (rp *localRootPath) Join(name string) (string, error) { | ||
absPath := filepath.Join(rp.rootPath, name) | ||
|
||
if !strings.HasPrefix(absPath, rp.rootPath) { | ||
return "", fmt.Errorf("relative path escapes root: %s", name) | ||
} | ||
return absPath, nil | ||
} | ||
shreyas-goenka marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package filer | ||
|
||
import ( | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func testUnixLocalRootPath(t *testing.T, uncleanRoot string) { | ||
cleanRoot := filepath.Clean(uncleanRoot) | ||
rp := NewLocalRootPath(uncleanRoot) | ||
|
||
remotePath, err := rp.Join("a/b/c") | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot+"/a/b/c", remotePath) | ||
|
||
remotePath, err = rp.Join("a/b/../d") | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot+"/a/d", remotePath) | ||
|
||
remotePath, err = rp.Join("a/../c") | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot+"/c", remotePath) | ||
|
||
remotePath, err = rp.Join("a/b/c/.") | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot+"/a/b/c", remotePath) | ||
|
||
remotePath, err = rp.Join("a/b/c/d/./../../f/g") | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot+"/a/b/f/g", remotePath) | ||
|
||
remotePath, err = rp.Join(".//a/..//./b/..") | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot, remotePath) | ||
|
||
remotePath, err = rp.Join("a/b/../..") | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot, remotePath) | ||
|
||
remotePath, err = rp.Join("") | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot, remotePath) | ||
|
||
remotePath, err = rp.Join(".") | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot, remotePath) | ||
|
||
remotePath, err = rp.Join("/") | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot, remotePath) | ||
|
||
_, err = rp.Join("..") | ||
assert.ErrorContains(t, err, `relative path escapes root: ..`) | ||
|
||
_, err = rp.Join("a/../..") | ||
assert.ErrorContains(t, err, `relative path escapes root: a/../..`) | ||
|
||
_, err = rp.Join("./../.") | ||
assert.ErrorContains(t, err, `relative path escapes root: ./../.`) | ||
|
||
_, err = rp.Join("/./.././..") | ||
assert.ErrorContains(t, err, `relative path escapes root: /./.././..`) | ||
|
||
_, err = rp.Join("./../.") | ||
assert.ErrorContains(t, err, `relative path escapes root: ./../.`) | ||
|
||
_, err = rp.Join("./..") | ||
assert.ErrorContains(t, err, `relative path escapes root: ./..`) | ||
|
||
_, err = rp.Join("./../../..") | ||
assert.ErrorContains(t, err, `relative path escapes root: ./../../..`) | ||
|
||
_, err = rp.Join("./../a/./b../../..") | ||
assert.ErrorContains(t, err, `relative path escapes root: ./../a/./b../../..`) | ||
|
||
_, err = rp.Join("../..") | ||
assert.ErrorContains(t, err, `relative path escapes root: ../..`) | ||
} | ||
|
||
func TestUnixLocalRootPath(t *testing.T) { | ||
if runtime.GOOS != "darwin" && runtime.GOOS != "linux" { | ||
t.SkipNow() | ||
} | ||
|
||
testUnixLocalRootPath(t, "/some/root/path") | ||
testUnixLocalRootPath(t, "/some/root/path/") | ||
testUnixLocalRootPath(t, "/some/root/path/.") | ||
testUnixLocalRootPath(t, "/some/root/../path/") | ||
} | ||
|
||
func testWindowsLocalRootPath(t *testing.T, uncleanRoot string) { | ||
cleanRoot := filepath.Clean(uncleanRoot) | ||
rp := NewLocalRootPath(uncleanRoot) | ||
|
||
remotePath, err := rp.Join(`a\b\c`) | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot+`\a\b\c`, remotePath) | ||
|
||
remotePath, err = rp.Join(`a\b\..\d`) | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot+`\a\d`, remotePath) | ||
|
||
remotePath, err = rp.Join(`a\..\c`) | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot+`\c`, remotePath) | ||
|
||
remotePath, err = rp.Join(`a\b\c\.`) | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot+`\a\b\c`, remotePath) | ||
|
||
remotePath, err = rp.Join(`a\b\..\..`) | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot, remotePath) | ||
|
||
remotePath, err = rp.Join("") | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot, remotePath) | ||
|
||
remotePath, err = rp.Join(".") | ||
assert.NoError(t, err) | ||
assert.Equal(t, cleanRoot, remotePath) | ||
|
||
_, err = rp.Join("..") | ||
assert.ErrorContains(t, err, `relative path escapes root`) | ||
|
||
_, err = rp.Join(`a\..\..`) | ||
assert.ErrorContains(t, err, `relative path escapes root`) | ||
} | ||
|
||
func TestWindowsLocalRootPath(t *testing.T) { | ||
if runtime.GOOS != "windows" { | ||
t.SkipNow() | ||
} | ||
|
||
testWindowsLocalRootPath(t, `c:\some\root\path`) | ||
testWindowsLocalRootPath(t, `c:\some\root\path\`) | ||
testWindowsLocalRootPath(t, `c:\some\root\path\.`) | ||
testWindowsLocalRootPath(t, `C:\some\root\..\path\`) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct though; if folks specify foobar:/bla` it shouldn't be interpreted as a local path.
If there is a
:
in the path they can always use./foo:bar
to specify it and it should work.As long as the
parts[0]
is all\w
characters, it should be "dbfs". If it isn't, we should return an error.Otherwise typos on the scheme can cause issues.