Skip to content

Commit 64b3103

Browse files
committed
test: use absolute and complex paths to test normalization
Previous tests were too simple. Now testing paths that would actually expose concatenation bugs without normalization: 1. Absolute paths (like Windows C:\path issue) 2. Paths with parent directory (..) that need cleaning 3. Paths with redundant separators (//) that need normalization These tests verify the fix prevents path duplication like: /path/test/path/test/file (without normalization) /path/test/file (with proper normalization) Addresses review feedback on PR #5674. Signed-off-by: Sibasis Padhi <[email protected]>
1 parent 2be4733 commit 64b3103

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

cmd/flux/build_kustomization_test.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,25 +219,37 @@ spec:
219219
}
220220
}
221221

222-
// TestBuildKustomizationWithRelativePaths verifies that relative and absolute
223-
// paths are handled correctly to prevent path concatenation issues.
224-
// See: https://github.com/fluxcd/flux2/issues/5673
225-
func TestBuildKustomizationWithRelativePaths(t *testing.T) {
222+
// TestBuildKustomizationPathNormalization verifies that absolute and complex
223+
// paths are normalized to prevent path concatenation bugs (issue #5673).
224+
// Without normalization, paths could be duplicated like: /path/test/path/test/file
225+
func TestBuildKustomizationPathNormalization(t *testing.T) {
226+
// Get absolute path to testdata to test absolute path handling
227+
absTestDataPath, err := filepath.Abs("testdata/build-kustomization/podinfo")
228+
if err != nil {
229+
t.Fatalf("failed to get absolute path: %v", err)
230+
}
231+
226232
tests := []struct {
227233
name string
228234
args string
229235
resultFile string
230236
assertFunc string
231237
}{
232238
{
233-
name: "build with relative path",
234-
args: "build kustomization podinfo --path testdata/build-kustomization/podinfo",
239+
name: "build with absolute path",
240+
args: "build kustomization podinfo --path " + absTestDataPath,
235241
resultFile: "./testdata/build-kustomization/podinfo-result.yaml",
236242
assertFunc: "assertGoldenTemplateFile",
237243
},
238244
{
239-
name: "build with dot-slash relative path",
240-
args: "build kustomization podinfo --path ./testdata/build-kustomization/podinfo",
245+
name: "build with complex relative path (parent dir)",
246+
args: "build kustomization podinfo --path ./testdata/build-kustomization/../build-kustomization/podinfo",
247+
resultFile: "./testdata/build-kustomization/podinfo-result.yaml",
248+
assertFunc: "assertGoldenTemplateFile",
249+
},
250+
{
251+
name: "build with path containing redundant separators",
252+
args: "build kustomization podinfo --path ./testdata//build-kustomization//podinfo",
241253
resultFile: "./testdata/build-kustomization/podinfo-result.yaml",
242254
assertFunc: "assertGoldenTemplateFile",
243255
},

0 commit comments

Comments
 (0)