Files
keyhunter/pkg/recon/sources/register_test.go
salvacybersec 3250408f23 feat(11-03): wire 18 sources into RegisterAll + credential wiring in cmd/recon.go
- Extend SourcesConfig with GoogleAPIKey, GoogleCX, BingAPIKey, YandexUser, YandexAPIKey, BraveAPIKey
- RegisterAll registers 8 Phase 11 sources alongside 10 Phase 10 sources (18 total)
- cmd/recon.go reads search engine API keys from env vars and viper config
- Guardrail tests updated to assert 18 sources
2026-04-06 12:02:11 +03:00

74 lines
2.0 KiB
Go

package sources
import (
"reflect"
"testing"
"github.com/salvacybersec/keyhunter/pkg/providers"
"github.com/salvacybersec/keyhunter/pkg/recon"
)
// registerTestRegistry builds a minimal registry with one synthetic provider so
// BuildQueries inside individual sources does not panic.
func registerTestRegistry() *providers.Registry {
return providers.NewRegistryFromProviders([]providers.Provider{
{Name: "openai", Keywords: []string{"sk-proj-"}},
})
}
// TestRegisterAll_WiresAllEighteenSources asserts that RegisterAll registers
// every Phase 10 + Phase 11 source by its stable name on a fresh engine.
func TestRegisterAll_WiresAllEighteenSources(t *testing.T) {
eng := recon.NewEngine()
cfg := SourcesConfig{
Registry: registerTestRegistry(),
Limiters: recon.NewLimiterRegistry(),
}
RegisterAll(eng, cfg)
got := eng.List()
want := []string{
"bing",
"bitbucket",
"brave",
"codeberg",
"codesandbox",
"duckduckgo",
"gist",
"gistpaste",
"github",
"gitlab",
"google",
"huggingface",
"kaggle",
"pastebin",
"pastesites",
"replit",
"sandboxes",
"yandex",
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("RegisterAll names mismatch\n got: %v\nwant: %v", got, want)
}
}
// TestRegisterAll_MissingCredsStillRegistered asserts that sources whose
// credentials are absent are still registered (so eng.List() reports them),
// but their Enabled() returns false. This keeps the CLI surface uniform
// regardless of which tokens are configured.
func TestRegisterAll_MissingCredsStillRegistered(t *testing.T) {
eng := recon.NewEngine()
RegisterAll(eng, SourcesConfig{
Registry: registerTestRegistry(),
Limiters: recon.NewLimiterRegistry(),
})
if n := len(eng.List()); n != 18 {
t.Fatalf("expected 18 sources registered, got %d: %v", n, eng.List())
}
// SweepAll with an empty config should filter out cred-gated sources
// (github, gitlab, bitbucket, gist, kaggle) and still run the credless
// ones. We only check List() here; the integration test covers Sweep.
}