2020-02-24 19:21:12 +00:00
|
|
|
package dorkgen
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
var dork *GoogleSearch
|
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
func TestInit(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
2020-02-24 19:43:58 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
t.Run("should convert to URL correctly", func(t *testing.T) {
|
|
|
|
dork = &GoogleSearch{}
|
2020-02-24 19:43:58 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
result := dork.
|
|
|
|
Site("example.com").
|
|
|
|
ToURL()
|
2020-02-24 19:43:58 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
assert.Equal(result, "https://www.google.com/search?q=site%3Aexample.com", "they should be equal")
|
|
|
|
})
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
t.Run("should handle site tag correctly", func(t *testing.T) {
|
|
|
|
dork = &GoogleSearch{}
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
result := dork.
|
|
|
|
Site("example.com").
|
|
|
|
ToString()
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
assert.Equal(result, "site:example.com", "they should be equal")
|
|
|
|
})
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
t.Run("should handle intext tag correctly", func(t *testing.T) {
|
|
|
|
dork = &GoogleSearch{}
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
result := dork.
|
|
|
|
Intext("text").
|
|
|
|
ToString()
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
assert.Equal(result, "\"text\"", "they should be equal")
|
|
|
|
})
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
t.Run("should handle inurl tag correctly", func(t *testing.T) {
|
|
|
|
dork = &GoogleSearch{}
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
result := dork.
|
|
|
|
Inurl("index.php").
|
|
|
|
ToString()
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
assert.Equal(result, "inurl:\"index.php\"", "they should be equal")
|
|
|
|
})
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
t.Run("should handle rrrrr tag correctly", func(t *testing.T) {
|
|
|
|
dork = &GoogleSearch{}
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
result := dork.
|
|
|
|
Filetype("pdf").
|
|
|
|
ToString()
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
assert.Equal(result, "filetype:\"pdf\"", "they should be equal")
|
|
|
|
})
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
t.Run("should handle cache tag correctly", func(t *testing.T) {
|
|
|
|
dork = &GoogleSearch{}
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
result := dork.
|
|
|
|
Cache("www.google.com").
|
|
|
|
ToString()
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
assert.Equal(result, "cache:\"www.google.com\"", "they should be equal")
|
|
|
|
})
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
t.Run("should handle related tag correctly", func(t *testing.T) {
|
|
|
|
dork = &GoogleSearch{}
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
result := dork.
|
|
|
|
Related("www.google.com").
|
|
|
|
ToString()
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
assert.Equal(result, "related:\"www.google.com\"", "they should be equal")
|
|
|
|
})
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
t.Run("should handle ext tag correctly", func(t *testing.T) {
|
|
|
|
dork = &GoogleSearch{}
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
result := dork.
|
|
|
|
Ext("(doc | pdf | xls | txt | xml)").
|
|
|
|
ToString()
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
assert.Equal(result, "ext:(doc | pdf | xls | txt | xml)", "they should be equal")
|
|
|
|
})
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
t.Run("should handle exclude tag correctly", func(t *testing.T) {
|
|
|
|
dork = &GoogleSearch{}
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
result := dork.
|
|
|
|
Exclude("html").
|
|
|
|
Exclude("htm").
|
|
|
|
Exclude("php").
|
|
|
|
Exclude("md5sums").
|
|
|
|
ToString()
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
assert.Equal(result, "-html -htm -php -md5sums", "they should be equal")
|
|
|
|
})
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
t.Run("should handle or tag correctly", func(t *testing.T) {
|
|
|
|
dork = &GoogleSearch{}
|
2020-02-24 19:21:12 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
result := dork.
|
|
|
|
Site("facebook.com").
|
|
|
|
Or().
|
|
|
|
Site("twitter.com").
|
|
|
|
ToString()
|
|
|
|
|
|
|
|
assert.Equal(result, "site:facebook.com OR site:twitter.com", "they should be equal")
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("should handle group tag correctly", func(t *testing.T) {
|
|
|
|
dork = &GoogleSearch{}
|
|
|
|
|
|
|
|
result := dork.
|
|
|
|
Site("linkedin.com").
|
|
|
|
Group((&GoogleSearch{}).Intext("1").Or().Intext("2").ToString()).
|
|
|
|
ToString()
|
|
|
|
|
|
|
|
assert.Equal(result, "site:linkedin.com (\"1\" OR \"2\")", "they should be equal")
|
|
|
|
})
|
2020-02-24 21:00:37 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
t.Run("should handle rrrrr tag correctly", func(t *testing.T) {
|
|
|
|
dork = &GoogleSearch{}
|
2020-02-24 21:00:37 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
result := dork.
|
|
|
|
Site("linkedin.com").
|
|
|
|
Group((&GoogleSearch{}).Intext("1").Or().Intext("2").ToString()).
|
|
|
|
Intitle("jordan").
|
|
|
|
ToString()
|
2020-02-24 21:00:37 +00:00
|
|
|
|
2020-02-27 18:47:17 +00:00
|
|
|
assert.Equal(result, "site:linkedin.com (\"1\" OR \"2\") intitle:\"jordan\"", "they should be equal")
|
|
|
|
})
|
2020-02-24 21:00:37 +00:00
|
|
|
}
|