|
| 1 | +package passive |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "reflect" |
| 6 | + "strings" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | + |
| 11 | + "github.com/projectdiscovery/gologger" |
| 12 | + "github.com/projectdiscovery/gologger/levels" |
| 13 | + "github.com/projectdiscovery/subfinder/v2/pkg/subscraping" |
| 14 | +) |
| 15 | + |
| 16 | +func TestSourcesWithoutKeys(t *testing.T) { |
| 17 | + domain := "hackerone.com" |
| 18 | + timeout := 60 |
| 19 | + |
| 20 | + gologger.DefaultLogger.SetMaxLevel(levels.LevelDebug) |
| 21 | + |
| 22 | + ctx := context.Background() |
| 23 | + session, err := subscraping.NewSession(domain, "", 0, timeout) |
| 24 | + assert.Nil(t, err) |
| 25 | + |
| 26 | + var expected = subscraping.Result{Type: subscraping.Subdomain, Value: domain, Error: nil} |
| 27 | + |
| 28 | + for _, source := range AllSources { |
| 29 | + if source.NeedsKey() { |
| 30 | + continue |
| 31 | + } |
| 32 | + |
| 33 | + t.Run(source.Name(), func(t *testing.T) { |
| 34 | + var results []subscraping.Result |
| 35 | + |
| 36 | + for result := range source.Run(ctx, domain, session) { |
| 37 | + results = append(results, result) |
| 38 | + |
| 39 | + assert.Equal(t, source.Name(), result.Source) |
| 40 | + |
| 41 | + assert.Equal(t, expected.Type, result.Type) |
| 42 | + assert.Equal(t, reflect.TypeOf(expected.Error), reflect.TypeOf(result.Error), result.Error) |
| 43 | + |
| 44 | + assert.True(t, strings.HasSuffix(strings.ToLower(result.Value), strings.ToLower(expected.Value))) |
| 45 | + } |
| 46 | + |
| 47 | + assert.GreaterOrEqual(t, len(results), 1) |
| 48 | + }) |
| 49 | + } |
| 50 | +} |
0 commit comments