mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-17 17:11:51 +02:00
fix: prevent local absolute paths from being treated as remote URLs (#2397)
Add filepath.IsAbs guard to IsRemote and Parse to prevent Windows drive letter paths (e.g., C:\path) from being misinterpreted as remote URLs by go-getter's url.Parse, which prepends file:// to drive letter paths. Fixes #2384 Signed-off-by: Aditya Menon <amenon@canarytechnologies.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
//go:build windows
|
||||
|
||||
package remote
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIsRemote_Windows(t *testing.T) {
|
||||
testcases := []struct {
|
||||
name string
|
||||
input string
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "windows drive letter path",
|
||||
input: `C:\project\services\values.yaml`,
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "windows UNC path",
|
||||
input: `\\server\share\path\values.yaml`,
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range testcases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := IsRemote(tt.input)
|
||||
if result != tt.expected {
|
||||
t.Errorf("IsRemote(%q) = %v, want %v", tt.input, result, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParse_Windows(t *testing.T) {
|
||||
testcases := []struct {
|
||||
name string
|
||||
input string
|
||||
err string
|
||||
}{
|
||||
{
|
||||
name: "windows drive letter path",
|
||||
input: `C:\project\services\values.yaml`,
|
||||
err: `parse url: local absolute path is not a remote URL: C:\project\services\values.yaml`,
|
||||
},
|
||||
{
|
||||
name: "windows UNC path",
|
||||
input: `\\server\share\path\values.yaml`,
|
||||
err: `parse url: local absolute path is not a remote URL: \\server\share\path\values.yaml`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range testcases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := Parse(tt.input)
|
||||
if err == nil {
|
||||
t.Fatalf("Parse(%q) expected error, got nil", tt.input)
|
||||
}
|
||||
if _, ok := err.(InvalidURLError); !ok {
|
||||
t.Fatalf("Parse(%q) expected InvalidURLError, got %T: %v", tt.input, err, err)
|
||||
}
|
||||
if err.Error() != tt.err {
|
||||
t.Errorf("Parse(%q) error = %q, want %q", tt.input, err.Error(), tt.err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user