Skip to content

Commit d1cd5fd

Browse files
committed
wip
1 parent bf5c9d9 commit d1cd5fd

File tree

6 files changed

+45
-21
lines changed

6 files changed

+45
-21
lines changed

api/internal/loader/fileloader.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,9 @@ func newLoaderAtGitClone(
211211
// check for this after cloning repo.
212212
if !root.HasPrefix(repoSpec.CloneDir()) {
213213
_ = cleaner()
214-
return nil, fmt.Errorf("%q refers to directory outside of repo %q", repoSpec.AbsPath(),
215-
repoSpec.CloneDir())
214+
return nil, fmt.Errorf("%q refers to directory outside of repo %q",
215+
filepath.ToSlash(repoSpec.AbsPath()),
216+
filepath.ToSlash(repoSpec.CloneDir().String()))
216217
}
217218
return &FileLoader{
218219
// Clones never allowed to escape root.

api/internal/loader/fileloader_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func TestLoaderLocalScheme(t *testing.T) {
208208
t.Run("file", func(t *testing.T) {
209209
fSys, dir := setupOnDisk(t)
210210
parts := []string{
211-
"ssh:",
211+
"ssh-scheme",
212212
"resource.yaml",
213213
}
214214
require.NoError(t, fSys.Mkdir(dir.Join(parts[0])))
@@ -226,8 +226,9 @@ func TestLoaderLocalScheme(t *testing.T) {
226226
})
227227
t.Run("directory", func(t *testing.T) {
228228
fSys, dir := setupOnDisk(t)
229+
// Use scheme-like name without colon for Windows compatibility
229230
parts := []string{
230-
"https:",
231+
"https-scheme",
231232
"root",
232233
}
233234
require.NoError(t, fSys.MkdirAll(dir.Join(filepath.Join(parts...))))

api/internal/loader/loadrestrictions_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package loader
55

66
import (
7+
"fmt"
78
"path/filepath"
89
"strings"
910
"testing"
@@ -59,9 +60,11 @@ func TestRestrictionRootOnly(t *testing.T) {
5960
if err == nil {
6061
t.Fatal("should have an error")
6162
}
62-
if !strings.Contains(
63-
err.Error(),
64-
"file '/tmp/illegal' is not in or below '/tmp/foo'") {
63+
// Normalize paths to forward slashes for cross-platform comparison
64+
expectedErr := fmt.Sprintf("file '%s' is not in or below '%s'",
65+
filepath.ToSlash(filepath.Join(filesys.Separator+"tmp", "illegal")),
66+
filepath.ToSlash(filepath.Join(filesys.Separator+"tmp", "foo")))
67+
if !strings.Contains(err.Error(), expectedErr) {
6568
t.Fatalf("unexpected err: %s", err)
6669
}
6770
}

api/internal/localizer/util_test.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"sigs.k8s.io/kustomize/api/ifc"
1515
"sigs.k8s.io/kustomize/api/internal/git"
1616
"sigs.k8s.io/kustomize/kyaml/filesys"
17+
"sigs.k8s.io/kustomize/kyaml/testutil"
1718
)
1819

1920
func TestDefaultNewDirRepo(t *testing.T) {
@@ -139,6 +140,9 @@ func TestLocFilePathColon(t *testing.T) {
139140
}
140141

141142
func TestLocFilePath_SpecialChar(t *testing.T) {
143+
// Skip on Windows as asterisk is invalid in Windows paths
144+
testutil.SkipWindows(t)
145+
142146
req := require.New(t)
143147

144148
// The wild card character is one of the legal uri characters with more meaning
@@ -163,19 +167,26 @@ func TestLocFilePath_SpecialFiles(t *testing.T) {
163167
for name, tFSys := range map[string]struct {
164168
urlPath string
165169
pathDir, pathFile string
170+
skipWindows bool // Skip this test case on Windows
166171
}{
167172
"windows_reserved_name": {
168173
urlPath: "/aux/file",
169174
pathDir: "aux",
170175
pathFile: "file",
171176
},
172177
"hidden_files": {
173-
urlPath: "/.../.file",
174-
pathDir: "...",
175-
pathFile: ".file",
178+
urlPath: "/.../.file",
179+
pathDir: "...",
180+
pathFile: ".file",
181+
skipWindows: true, // Windows treats "..." specially
176182
},
177183
} {
178184
t.Run(name, func(t *testing.T) {
185+
// Skip Windows-incompatible tests
186+
if tFSys.skipWindows {
187+
testutil.SkipWindows(t)
188+
}
189+
179190
req := require.New(t)
180191

181192
expectedPath := simpleJoin(t, LocalizeDir, "host", tFSys.pathDir, tFSys.pathFile)
@@ -304,23 +315,27 @@ func TestLocRootPath_SymlinkPath(t *testing.T) {
304315

305316
func TestCleanedRelativePath(t *testing.T) {
306317
fSys := filesys.MakeFsInMemory()
307-
require.NoError(t, fSys.MkdirAll("/root/test"))
308-
require.NoError(t, fSys.WriteFile("/root/test/file.yaml", []byte("")))
309-
require.NoError(t, fSys.WriteFile("/root/filetwo.yaml", []byte("")))
318+
// Use platform-appropriate root path
319+
rootPath := string(filepath.Separator) + "root"
320+
testPath := rootPath + string(filepath.Separator) + "test"
321+
322+
require.NoError(t, fSys.MkdirAll(testPath))
323+
require.NoError(t, fSys.WriteFile(testPath+string(filepath.Separator)+"file.yaml", []byte("")))
324+
require.NoError(t, fSys.WriteFile(rootPath+string(filepath.Separator)+"filetwo.yaml", []byte("")))
310325

311326
// Absolute path is cleaned to relative path
312-
cleanedPath := cleanedRelativePath(fSys, "/root/", "/root/test/file.yaml")
313-
require.Equal(t, "test/file.yaml", cleanedPath)
327+
cleanedPath := cleanedRelativePath(fSys, filesys.ConfirmedDir(rootPath+string(filepath.Separator)), testPath+string(filepath.Separator)+"file.yaml")
328+
require.Equal(t, filepath.Join("test", "file.yaml"), cleanedPath)
314329

315330
// Winding absolute path is cleaned to relative path
316-
cleanedPath = cleanedRelativePath(fSys, "/root/", "/root/test/../filetwo.yaml")
331+
cleanedPath = cleanedRelativePath(fSys, filesys.ConfirmedDir(rootPath+string(filepath.Separator)), rootPath+string(filepath.Separator)+"test"+string(filepath.Separator)+".."+string(filepath.Separator)+"filetwo.yaml")
317332
require.Equal(t, "filetwo.yaml", cleanedPath)
318333

319334
// Already clean relative path stays the same
320-
cleanedPath = cleanedRelativePath(fSys, "/root/", "test/file.yaml")
321-
require.Equal(t, "test/file.yaml", cleanedPath)
335+
cleanedPath = cleanedRelativePath(fSys, filesys.ConfirmedDir(rootPath+string(filepath.Separator)), "test"+string(filepath.Separator)+"file.yaml")
336+
require.Equal(t, filepath.Join("test", "file.yaml"), cleanedPath)
322337

323338
// Winding relative path is cleaned
324-
cleanedPath = cleanedRelativePath(fSys, "/root/", "test/../filetwo.yaml")
339+
cleanedPath = cleanedRelativePath(fSys, filesys.ConfirmedDir(rootPath+string(filepath.Separator)), "test"+string(filepath.Separator)+".."+string(filepath.Separator)+"filetwo.yaml")
325340
require.Equal(t, "filetwo.yaml", cleanedPath)
326341
}

api/internal/target/kusttarget_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,13 @@ commonLabels:
122122
},
123123
}
124124

125+
// Use platform-appropriate root directory
126+
rootDir := string(filepath.Separator)
125127
kt := makeKustTargetWithRf(
126-
t, th.GetFSys(), "/", provider.NewDefaultDepProvider())
128+
t, th.GetFSys(), rootDir, provider.NewDefaultDepProvider())
127129
for tn, tc := range testCases {
128130
t.Run(tn, func(t *testing.T) {
129-
th.WriteK("/", tc.content)
131+
th.WriteK(rootDir, tc.content)
130132
err := kt.Load()
131133
if tc.errContains != "" {
132134
require.NotNilf(t, err, "expected error containing: `%s`", tc.errContains)

api/resource/origin.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func (origin *Origin) Append(inputPath string) *Origin {
5454
if err == nil {
5555
originCopy.Repo = repoSpec.CloneSpec()
5656
absPath := repoSpec.AbsPath()
57+
// Normalize to forward slashes for cross-platform compatibility
58+
absPath = strings.ReplaceAll(absPath, "\\", "/")
5759
inputPath = absPath[strings.Index(absPath[1:], "/")+1:][1:]
5860
originCopy.Path = ""
5961
originCopy.Ref = repoSpec.Ref

0 commit comments

Comments
 (0)