@@ -388,3 +388,145 @@ func TestOssRealtimeScan_CsprojFile_ReturnsLocations(t *testing.T) {
388388 "Location %d endIndex should be %d" , i , expected .endIndex )
389389 }
390390}
391+
392+ // Tests for validateSupportedManifestFile function
393+ func TestValidateSupportedManifestFile_ValidExtensions (t * testing.T ) {
394+ tests := []struct {
395+ name string
396+ filePath string
397+ isValid bool
398+ }{
399+ {
400+ name : "CsprojExtension" ,
401+ filePath : "project.csproj" ,
402+ isValid : true ,
403+ },
404+ {
405+ name : "SbtExtension" ,
406+ filePath : "build.sbt" ,
407+ isValid : true ,
408+ },
409+ {
410+ name : "CsprojWithPath" ,
411+ filePath : "/path/to/project.csproj" ,
412+ isValid : true ,
413+ },
414+ {
415+ name : "SbtWithPath" ,
416+ filePath : "src/build.sbt" ,
417+ isValid : true ,
418+ },
419+ }
420+
421+ for _ , tt := range tests {
422+ t .Run (tt .name , func (t * testing.T ) {
423+ err := validateSupportedManifestFile (tt .filePath )
424+ if tt .isValid {
425+ assert .Nil (t , err , "Should accept %s file" , tt .filePath )
426+ } else {
427+ assert .NotNil (t , err , "Should reject %s file" , tt .filePath )
428+ }
429+ })
430+ }
431+ }
432+
433+ func TestValidateSupportedManifestFile_ValidFilenames (t * testing.T ) {
434+ tests := []struct {
435+ name string
436+ filePath string
437+ }{
438+ {name : "PomXml" , filePath : "pom.xml" },
439+ {name : "PackageJson" , filePath : "package.json" },
440+ {name : "GoMod" , filePath : "go.mod" },
441+ {name : "BuildGradle" , filePath : "build.gradle" },
442+ {name : "BuildGradleKts" , filePath : "build.gradle.kts" },
443+ {name : "LibsVersionsToml" , filePath : "libs.versions.toml" },
444+ {name : "SetupCfg" , filePath : "setup.cfg" },
445+ {name : "SetupPy" , filePath : "setup.py" },
446+ {name : "PyprojectToml" , filePath : "pyproject.toml" },
447+ {name : "PackagesConfig" , filePath : "packages.config" },
448+ {name : "DirectoryPackagesProps" , filePath : "Directory.Packages.props" },
449+ {name : "PomXmlWithPath" , filePath : "/path/to/pom.xml" },
450+ {name : "PackageJsonWithPath" , filePath : "src/package.json" },
451+ {name : "GoModWithPath" , filePath : "project/go.mod" },
452+ }
453+
454+ for _ , tt := range tests {
455+ t .Run (tt .name , func (t * testing.T ) {
456+ err := validateSupportedManifestFile (tt .filePath )
457+ assert .Nil (t , err , "Should accept %s file" , tt .filePath )
458+ })
459+ }
460+ }
461+
462+ func TestValidateSupportedManifestFile_ValidTxtFilesWithPrefixes (t * testing.T ) {
463+ tests := []struct {
464+ name string
465+ filePath string
466+ }{
467+ {name : "RequirementsTxt" , filePath : "requirements.txt" },
468+ {name : "RequirementsDevTxt" , filePath : "requirements-dev.txt" },
469+ {name : "PackagesTxt" , filePath : "packages.txt" },
470+ {name : "ConstraintsTxt" , filePath : "constraints.txt" },
471+ {name : "RequirementsWithPath" , filePath : "/path/to/requirements.txt" },
472+ {name : "PackagesWithPath" , filePath : "config/packages.txt" },
473+ {name : "ConstraintsWithPath" , filePath : "src/constraints.txt" },
474+ }
475+
476+ for _ , tt := range tests {
477+ t .Run (tt .name , func (t * testing.T ) {
478+ err := validateSupportedManifestFile (tt .filePath )
479+ assert .Nil (t , err , "Should accept %s file" , tt .filePath )
480+ })
481+ }
482+ }
483+
484+ func TestValidateSupportedManifestFile_InvalidTxtFilesWithoutPrefixes (t * testing.T ) {
485+ tests := []struct {
486+ name string
487+ filePath string
488+ }{
489+ {name : "UnrelatedTxt" , filePath : "readme.txt" },
490+ {name : "DataTxt" , filePath : "data.txt" },
491+ {name : "ConfigTxt" , filePath : "config.txt" },
492+ {name : "InfoTxt" , filePath : "info.txt" },
493+ {name : "UnrelatedTxtWithPath" , filePath : "/path/to/random.txt" },
494+ }
495+
496+ for _ , tt := range tests {
497+ t .Run (tt .name , func (t * testing.T ) {
498+ err := validateSupportedManifestFile (tt .filePath )
499+ assert .NotNil (t , err , "Should reject %s file (missing prefix)" , tt .filePath )
500+ // Verify error message indicates unsupported format
501+ assert .Contains (t , err .Error (), "OSS Realtime scanner doesn't currently support scanning" )
502+ })
503+ }
504+ }
505+
506+ func TestValidateSupportedManifestFile_UnsupportedFormats (t * testing.T ) {
507+ tests := []struct {
508+ name string
509+ filePath string
510+ }{
511+ {name : "RubyGemfile" , filePath : "Gemfile" },
512+ {name : "PHPComposer" , filePath : "composer.json" },
513+ {name : "RustCargo" , filePath : "Cargo.toml" },
514+ {name : "PythonPipfile" , filePath : "Pipfile" },
515+ {name : "JavaGradleProperties" , filePath : "gradle.properties" },
516+ {name : "NodeNpmLock" , filePath : "package-lock.json" },
517+ {name : "YarnLock" , filePath : "yarn.lock" },
518+ {name : "UnsupportedExtension" , filePath : "manifest.xml" },
519+ {name : "RandomFile" , filePath : "random.txt" },
520+ {name : "NoPyproject" , filePath : "pyproject.yaml" },
521+ {name : "PomWithDifferentName" , filePath : "maven.xml" },
522+ }
523+
524+ for _ , tt := range tests {
525+ t .Run (tt .name , func (t * testing.T ) {
526+ err := validateSupportedManifestFile (tt .filePath )
527+ assert .NotNil (t , err , "Should reject %s file (unsupported format)" , tt .filePath )
528+ // Verify error message indicates unsupported format
529+ assert .Contains (t , err .Error (), "OSS Realtime scanner doesn't currently support scanning" )
530+ })
531+ }
532+ }
0 commit comments