@@ -295,6 +295,165 @@ func TestKustomizationFileMustNotBeDirectory(t *testing.T) {
295295 require .EqualError (t , err , fmt .Sprintf ("kustFileName %s was a directory" , absPath ))
296296}
297297
298+ func TestKustomizationFilePathsMustBeLocalToDirectory (t * testing.T ) {
299+ fields := map [string ]struct {
300+ fieldName string
301+ factory func (string ) types.Kustomization
302+ }{
303+ "components" : {
304+ "Components" ,
305+ func (p string ) types.Kustomization {
306+ return types.Kustomization {
307+ Components : []string {p },
308+ }
309+ },
310+ },
311+ "resources" : {
312+ "Resources" ,
313+ func (p string ) types.Kustomization {
314+ return types.Kustomization {
315+ Resources : []string {p },
316+ }
317+ },
318+ },
319+ "crds" : {
320+ "Crds" ,
321+ func (p string ) types.Kustomization {
322+ return types.Kustomization {
323+ Crds : []string {p },
324+ }
325+ },
326+ },
327+ "configurations" : {
328+ "Configurations" ,
329+ func (p string ) types.Kustomization {
330+ return types.Kustomization {
331+ Configurations : []string {p },
332+ }
333+ },
334+ },
335+ "generators" : {
336+ "Generators" ,
337+ func (p string ) types.Kustomization {
338+ return types.Kustomization {
339+ Generators : []string {p },
340+ }
341+ },
342+ },
343+ "transformers" : {
344+ "Transformers" ,
345+ func (p string ) types.Kustomization {
346+ return types.Kustomization {
347+ Transformers : []string {p },
348+ }
349+ },
350+ },
351+ "validators" : {
352+ "Validators" ,
353+ func (p string ) types.Kustomization {
354+ return types.Kustomization {
355+ Validators : []string {p },
356+ }
357+ },
358+ },
359+ "patches" : {
360+ "Patches" ,
361+ func (p string ) types.Kustomization {
362+ return types.Kustomization {
363+ Patches : []types.Patch {{Path : p }},
364+ }
365+ },
366+ },
367+ "replacements" : {
368+ "Replacements" ,
369+ func (p string ) types.Kustomization {
370+ return types.Kustomization {
371+ Replacements : []types.ReplacementField {{Path : p }},
372+ }
373+ },
374+ },
375+ "configMapGenerator files" : {
376+ "ConfigMapGenerator" ,
377+ func (p string ) types.Kustomization {
378+ return types.Kustomization {
379+ ConfigMapGenerator : []types.ConfigMapArgs {{GeneratorArgs : types.GeneratorArgs {KvPairSources : types.KvPairSources {FileSources : []string {p }}}}},
380+ }
381+ },
382+ },
383+ "configMapGenerator envs" : {
384+ "ConfigMapGenerator" ,
385+ func (p string ) types.Kustomization {
386+ return types.Kustomization {
387+ ConfigMapGenerator : []types.ConfigMapArgs {{GeneratorArgs : types.GeneratorArgs {KvPairSources : types.KvPairSources {EnvSources : []string {p }}}}},
388+ }
389+ },
390+ },
391+ "secretGenerator files" : {
392+ "SecretGenerator" ,
393+ func (p string ) types.Kustomization {
394+ return types.Kustomization {
395+ SecretGenerator : []types.SecretArgs {{GeneratorArgs : types.GeneratorArgs {KvPairSources : types.KvPairSources {FileSources : []string {p }}}}},
396+ }
397+ },
398+ },
399+ "SecretGenerator envs" : {
400+ "SecretGenerator" ,
401+ func (p string ) types.Kustomization {
402+ return types.Kustomization {
403+ SecretGenerator : []types.SecretArgs {{GeneratorArgs : types.GeneratorArgs {KvPairSources : types.KvPairSources {EnvSources : []string {p }}}}},
404+ }
405+ },
406+ },
407+ "helmCharts valuesFile" : {
408+ "HelmCharts" ,
409+ func (p string ) types.Kustomization {
410+ return types.Kustomization {
411+ HelmCharts : []types.HelmChart {{ValuesFile : p }},
412+ }
413+ },
414+ },
415+ "helmCharts additionalValuesFile" : {
416+ "HelmCharts" ,
417+ func (p string ) types.Kustomization {
418+ return types.Kustomization {
419+ HelmCharts : []types.HelmChart {{AdditionalValuesFiles : []string {p }}},
420+ }
421+ },
422+ },
423+ }
424+ paths := map [string ]string {
425+ // "invalid fileurl": "file://asdfsd/something.txt",
426+ "parent directory" : ".." ,
427+ }
428+
429+ for fieldName , generator := range fields {
430+
431+ for pathName , path := range paths {
432+ t .Run (fieldName + "|" + pathName , func (t * testing.T ) {
433+ kustname := "kustomization.yaml"
434+ files := map [string ]string {
435+ filepath .Join ("src" , kustname ): `namePrefix: test-
436+ ` ,
437+ }
438+
439+ dummy , _ , dir := loctest .PrepareFs (t , []string {"src" }, files )
440+ kustomization := generator .factory (path )
441+
442+ pushOptions := PushOptions {
443+ fSys : dummy ,
444+ kustFileName : filepath .Join (dir .String (), "src" , kustname ),
445+ kustomization : & kustomization ,
446+ targets : []reference.NamedTagged {AsNamedTagged ("registry.domain/something" , "sometag" )},
447+ }
448+
449+ err := PushToOciRegistries (& pushOptions )
450+ require .ErrorContains (t , err , "kustomization includes non-local file paths" )
451+ require .ErrorContains (t , err , fmt .Sprintf ("Path '%s' in element %s is not local" , path , generator .fieldName ))
452+ })
453+ }
454+ }
455+ }
456+
298457// func TestFnContainerTransformerWithConfig(t *testing.T) {
299458
300459// kustomization := map[string]string{
0 commit comments