@@ -423,6 +423,41 @@ func TestNormalizeRepos(t *testing.T) {
423423 }
424424}
425425
426+ func TestNormalizeRepo (t * testing.T ) {
427+ // Test that normalizeRepo correctly identifies URLs with protocols
428+ source := & Source {}
429+
430+ // Test case 1: HTTP URL
431+ result , err := source .normalizeRepo ("https://github.com/org/repo.git" )
432+ assert .NoError (t , err )
433+ assert .Contains (t , result , "github.com/org/repo" )
434+
435+ // Test case 2: HTTP URL without .git
436+ result , err = source .normalizeRepo ("http://github.com/org/repo" )
437+ assert .NoError (t , err )
438+ assert .Contains (t , result , "github.com/org/repo" )
439+
440+ // Test case 3: Git protocol URL
441+ result , err = source .normalizeRepo ("git://github.com/org/repo.git" )
442+ assert .NoError (t , err )
443+ assert .Contains (t , result , "github.com/org/repo" )
444+
445+ // Test case 4: SSH URL
446+ result ,
err = source .
normalizeRepo (
"ssh://[email protected] /org/repo.git" )
447+ assert .NoError (t , err )
448+ assert .Contains (t , result , "github.com/org/repo" )
449+
450+ // Test case 5: Org/repo format (should convert to full URL)
451+ result , err = source .normalizeRepo ("org/repo" )
452+ assert .NoError (t , err )
453+ assert .Contains (t , result , "github.com/org/repo" )
454+
455+ // Test case 6: Invalid format (no protocol, no slash)
456+ _ , err = source .normalizeRepo ("invalid" )
457+ assert .Error (t , err )
458+ assert .Contains (t , err .Error (), "no repositories found" )
459+ }
460+
426461func TestHandleRateLimit (t * testing.T ) {
427462 s := initTestSource (& sourcespb.GitHub {Credential : & sourcespb.GitHub_Unauthenticated {}})
428463 ctx := context .Background ()
@@ -493,7 +528,7 @@ func TestEnumerateWithToken(t *testing.T) {
493528 JSON (map [string ]string {"login" : "super-secret-user" })
494529
495530 gock .New ("https://api.github.com" ).
496- Get ("/users/super-secret- user/repos" ).
531+ Get ("/user/repos" ).
497532 MatchParam ("per_page" , "100" ).
498533 Reply (200 ).
499534 JSON ([]map [string ]string {{"clone_url" : "https://github.com/super-secret-user/super-secret-repo.git" , "full_name" : "super-secret-user/super-secret-repo" }})
@@ -574,7 +609,7 @@ func TestEnumerate(t *testing.T) {
574609
575610 //
576611 gock .New ("https://api.github.com" ).
577- Get ("/users/super-secret- user/repos" ).
612+ Get ("/user/repos" ).
578613 Reply (200 ).
579614 JSON (`[{"name": "super-secret-repo", "full_name": "super-secret-user/super-secret-repo", "owner": {"login": "super-secret-user"}, "clone_url": "https://github.com/super-secret-user/super-secret-repo.git", "has_wiki": false, "size": 1}]` )
580615
@@ -978,6 +1013,39 @@ func Test_ScanMultipleTargets_MultipleErrors(t *testing.T) {
9781013 }
9791014}
9801015
1016+ func TestRepositoryFiltering (t * testing.T ) {
1017+ // Test that the filteredRepoCache correctly filters repositories
1018+ source := & Source {}
1019+
1020+ // Test case 1: No filters specified (should include everything)
1021+ cache1 := source .newFilteredRepoCache (context .Background (), simple .NewCache [string ](), []string {}, []string {})
1022+ assert .True (t , cache1 .wantRepo ("org/repo1" ))
1023+ assert .True (t , cache1 .wantRepo ("org/repo2" ))
1024+ assert .True (t , cache1 .wantRepo ("org/repo3" ))
1025+
1026+ // Test case 2: Include filter specified (should only include matching repos)
1027+ cache2 := source .newFilteredRepoCache (context .Background (), simple .NewCache [string ](), []string {"org/repo1" , "org/repo2" }, []string {})
1028+ assert .True (t , cache2 .wantRepo ("org/repo1" ))
1029+ assert .True (t , cache2 .wantRepo ("org/repo2" ))
1030+ assert .False (t , cache2 .wantRepo ("org/repo3" ))
1031+
1032+ // Test case 3: Exclude filter specified (should exclude matching repos)
1033+ cache3 := source .newFilteredRepoCache (context .Background (), simple .NewCache [string ](), []string {}, []string {"org/repo1" })
1034+ assert .False (t , cache3 .wantRepo ("org/repo1" ))
1035+ assert .True (t , cache3 .wantRepo ("org/repo2" ))
1036+ assert .True (t , cache3 .wantRepo ("org/repo3" ))
1037+
1038+ // Test case 4: Both include and exclude filters (exclude takes precedence)
1039+ cache4 := source .newFilteredRepoCache (context .Background (), simple .NewCache [string ](), []string {"org/repo1" }, []string {"org/repo1" })
1040+ assert .False (t , cache4 .wantRepo ("org/repo1" ))
1041+
1042+ // Test case 5: Wildcard patterns
1043+ cache5 := source .newFilteredRepoCache (context .Background (), simple .NewCache [string ](), []string {"org/*" }, []string {})
1044+ assert .True (t , cache5 .wantRepo ("org/repo1" ))
1045+ assert .True (t , cache5 .wantRepo ("org/repo2" ))
1046+ assert .False (t , cache5 .wantRepo ("other/repo1" ))
1047+ }
1048+
9811049func noopReporter () sources.UnitReporter {
9821050 return sources.VisitorReporter {
9831051 VisitUnit : func (context.Context , sources.SourceUnit ) error {
0 commit comments