@@ -2401,6 +2401,91 @@ func Test_validateThresholds(t *testing.T) {
24012401
24022402// TestValidateContainerImageFormat_Comprehensive tests the complete validation logic
24032403// including input normalization, helpful hints, and all error cases.
2404+ // TestIsWindowsAbsolutePath tests the Windows absolute path detection.
2405+ // Container-security scan-type related test function.
2406+ func TestIsWindowsAbsolutePath (t * testing.T ) {
2407+ testCases := []struct {
2408+ name string
2409+ input string
2410+ expected bool
2411+ }{
2412+ // Valid Windows absolute paths
2413+ {name : "C drive with backslash" , input : "C:\\ Users\\ file.tar" , expected : true },
2414+ {name : "D drive with backslash" , input : "D:\\ data\\ image.tar" , expected : true },
2415+ {name : "C drive with forward slash" , input : "C:/Users/file.tar" , expected : true },
2416+ {name : "Lowercase drive letter" , input : "c:\\ path\\ file.tar" , expected : true },
2417+
2418+ // Not Windows absolute paths
2419+ {name : "Unix absolute path" , input : "/path/to/file.tar" , expected : false },
2420+ {name : "Relative path" , input : "Downloads/file.tar" , expected : false },
2421+ {name : "Simple filename" , input : "file.tar" , expected : false },
2422+ {name : "Image with tag" , input : "nginx:latest" , expected : false },
2423+ {name : "Too short" , input : "C:" , expected : false },
2424+ {name : "No path separator after colon" , input : "C:file.tar" , expected : false },
2425+ }
2426+
2427+ for _ , tc := range testCases {
2428+ tc := tc
2429+ t .Run (tc .name , func (t * testing.T ) {
2430+ result := isWindowsAbsolutePath (tc .input )
2431+ if result != tc .expected {
2432+ t .Errorf ("isWindowsAbsolutePath(%q) = %v, expected %v" , tc .input , result , tc .expected )
2433+ }
2434+ })
2435+ }
2436+ }
2437+
2438+ // TestLooksLikeFilePath tests the file path detection logic for cross-platform support.
2439+ // Container-security scan-type related test function.
2440+ // This test validates the looksLikeFilePath function for various Windows and Unix path formats.
2441+ func TestLooksLikeFilePath (t * testing.T ) {
2442+ testCases := []struct {
2443+ name string
2444+ input string
2445+ expected bool
2446+ }{
2447+ // Tar file extensions
2448+ {name : "Simple tar file" , input : "image.tar" , expected : true },
2449+ {name : "Tar.gz file" , input : "image.tar.gz" , expected : true },
2450+ {name : "Tar.bz2 file" , input : "image.tar.bz2" , expected : true },
2451+ {name : "Tar.xz file" , input : "image.tar.xz" , expected : true },
2452+ {name : "Tgz file" , input : "image.tgz" , expected : true },
2453+
2454+ // Unix-style paths
2455+ {name : "Unix relative path with tar" , input : "subdir/image.tar" , expected : true },
2456+ {name : "Unix absolute path with tar" , input : "/path/to/image.tar" , expected : true },
2457+ {name : "Unix path with version in filename" , input : "Downloads/alpine_3.21.0_podman.tar" , expected : true },
2458+ {name : "Unix nested path" , input : "path/to/nested/dir/file.tar" , expected : true },
2459+
2460+ // Windows-style paths
2461+ {name : "Windows absolute path with drive letter" , input : "C:\\ Users\\ Downloads\\ image.tar" , expected : true },
2462+ {name : "Windows path with forward slash after drive" , input : "C:/Users/Downloads/image.tar" , expected : true },
2463+ {name : "Windows relative path with backslash" , input : "Downloads\\ alpine_3.21.0_podman.tar" , expected : true },
2464+ {name : "Windows D drive path" , input : "D:\\ data\\ images\\ test.tar" , expected : true },
2465+
2466+ // Not file paths (image:tag format)
2467+ {name : "Simple image:tag" , input : "nginx:latest" , expected : false },
2468+ {name : "Image with registry" , input : "registry.io/namespace/image:tag" , expected : false },
2469+ {name : "Image with port" , input : "registry.io:5000/image:tag" , expected : false },
2470+ {name : "Image without tag" , input : "nginx" , expected : false },
2471+
2472+ // Edge cases
2473+ {name : "Tar file with dots in name" , input : "alpine.3.18.0.tar" , expected : true },
2474+ {name : "Tar file with version like name" , input : "app_v1.2.3.tar" , expected : true },
2475+ {name : "Path with tar in middle" , input : "tarball/other.tar" , expected : true },
2476+ }
2477+
2478+ for _ , tc := range testCases {
2479+ tc := tc
2480+ t .Run (tc .name , func (t * testing.T ) {
2481+ result := looksLikeFilePath (tc .input )
2482+ if result != tc .expected {
2483+ t .Errorf ("looksLikeFilePath(%q) = %v, expected %v" , tc .input , result , tc .expected )
2484+ }
2485+ })
2486+ }
2487+ }
2488+
24042489// Container-security scan-type related test function.
24052490// This test validates all supported container image formats, prefixes, tar files,
24062491// error messages, and helpful hints for the --container-images flag.
@@ -2487,6 +2572,36 @@ func TestValidateContainerImageFormat_Comprehensive(t *testing.T) {
24872572 expectedError : "--container-images flag error: file 'image.tgz' is compressed, use non-compressed format (tar)" ,
24882573 },
24892574
2575+ // ==================== File Path Tests (Windows and Unix) ====================
2576+ // Note: These tests validate that path-like inputs are correctly recognized as file paths
2577+ {
2578+ name : "Valid tar file with filename containing version number" ,
2579+ containerImage : "alpine_3.21.0_podman.tar" ,
2580+ expectedError : "" ,
2581+ setupFiles : []string {"alpine_3.21.0_podman.tar" },
2582+ },
2583+ {
2584+ name : "Valid tar file with filename containing underscore and version" ,
2585+ containerImage : "mysql_5.7_backup.tar" ,
2586+ expectedError : "" ,
2587+ setupFiles : []string {"mysql_5.7_backup.tar" },
2588+ },
2589+ {
2590+ name : "Invalid - Unix relative path does not exist" ,
2591+ containerImage : "subdir/image.tar" ,
2592+ expectedError : "--container-images flag error: file 'subdir/image.tar' does not exist" ,
2593+ },
2594+ {
2595+ name : "Invalid - Unix nested path does not exist" ,
2596+ containerImage : "path/to/archive/my-image.tar" ,
2597+ expectedError : "--container-images flag error: file 'path/to/archive/my-image.tar' does not exist" ,
2598+ },
2599+ {
2600+ name : "Invalid - file path with version-like name does not exist" ,
2601+ containerImage : "Downloads/alpine_3.21.0_podman.tar" ,
2602+ expectedError : "--container-images flag error: file 'Downloads/alpine_3.21.0_podman.tar' does not exist" ,
2603+ },
2604+
24902605 // ==================== Helpful Hints Tests ====================
24912606 {
24922607 name : "Hint - looks like tar file (wrong extension)" ,
0 commit comments