feat: implement intitle method
parent
b8acb0aa51
commit
ecf6a7262a
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
Package dorkgen is a Go package to generate dork requests for popular search engines such as Google, DuckDuckGo and Bing.
|
||||||
|
It allows you to define requests programmatically and convert them into string.
|
||||||
|
You can use it as following:
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "github.com/sundowndev/dorkgen"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
dork := &dorkgen.GoogleSearch{}
|
||||||
|
// dork := &dorkgen.DuckDuckGo{}
|
||||||
|
// dork := &dorkgen.Bing{}
|
||||||
|
|
||||||
|
dork.Site("example.com").Intext("text").ToString()
|
||||||
|
// returns: site:example.com "text"
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
package dorkgen
|
|
@ -1,8 +1,8 @@
|
||||||
package dorkgen
|
package dorkgen
|
||||||
|
|
||||||
// EngineFactory is the main interface for
|
// engineFactory is the main interface for
|
||||||
// search engine implementations.
|
// search engine implementations.
|
||||||
type EngineFactory interface {
|
type engineFactory interface {
|
||||||
Site(string) *GoogleSearch
|
Site(string) *GoogleSearch
|
||||||
ToString() string
|
ToString() string
|
||||||
ToURL() string
|
ToURL() string
|
||||||
|
|
|
@ -14,11 +14,12 @@ const (
|
||||||
relatedTag = "related:"
|
relatedTag = "related:"
|
||||||
extTag = "ext:"
|
extTag = "ext:"
|
||||||
excludeTag = "-"
|
excludeTag = "-"
|
||||||
|
intitleTag = "intitle:"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GoogleSearch is the Google implementation for Dorkgen
|
// GoogleSearch is the Google implementation for Dorkgen
|
||||||
type GoogleSearch struct {
|
type GoogleSearch struct {
|
||||||
EngineFactory
|
engineFactory
|
||||||
tags []string
|
tags []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,3 +110,9 @@ func (e *GoogleSearch) Group(value string) *GoogleSearch {
|
||||||
e.tags = append(e.tags, "("+value+")")
|
e.tags = append(e.tags, "("+value+")")
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Intitle ...
|
||||||
|
func (e *GoogleSearch) Intitle(value string) *GoogleSearch {
|
||||||
|
e.tags = append(e.tags, concat(intitleTag, value, true))
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
|
@ -8,87 +8,90 @@ import (
|
||||||
|
|
||||||
var dork *GoogleSearch
|
var dork *GoogleSearch
|
||||||
|
|
||||||
func TestToUrl(t *testing.T) {
|
func TestInit(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
t.Run("should convert to URL correctly", func(t *testing.T) {
|
||||||
dork = &GoogleSearch{}
|
dork = &GoogleSearch{}
|
||||||
|
|
||||||
result := dork.
|
result := dork.
|
||||||
Site("example.com").
|
Site("example.com").
|
||||||
ToURL()
|
ToURL()
|
||||||
|
|
||||||
assert.Equal(t, result, "https://www.google.com/search?q=site%3Aexample.com", "they should be equal")
|
assert.Equal(result, "https://www.google.com/search?q=site%3Aexample.com", "they should be equal")
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestSite(t *testing.T) {
|
t.Run("should handle site tag correctly", func(t *testing.T) {
|
||||||
dork = &GoogleSearch{}
|
dork = &GoogleSearch{}
|
||||||
|
|
||||||
result := dork.
|
result := dork.
|
||||||
Site("example.com").
|
Site("example.com").
|
||||||
ToString()
|
ToString()
|
||||||
|
|
||||||
assert.Equal(t, result, "site:example.com", "they should be equal")
|
assert.Equal(result, "site:example.com", "they should be equal")
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestIntext(t *testing.T) {
|
t.Run("should handle intext tag correctly", func(t *testing.T) {
|
||||||
dork = &GoogleSearch{}
|
dork = &GoogleSearch{}
|
||||||
|
|
||||||
result := dork.
|
result := dork.
|
||||||
Intext("text").
|
Intext("text").
|
||||||
ToString()
|
ToString()
|
||||||
|
|
||||||
assert.Equal(t, result, "\"text\"", "they should be equal")
|
assert.Equal(result, "\"text\"", "they should be equal")
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestInurl(t *testing.T) {
|
t.Run("should handle inurl tag correctly", func(t *testing.T) {
|
||||||
dork = &GoogleSearch{}
|
dork = &GoogleSearch{}
|
||||||
|
|
||||||
result := dork.
|
result := dork.
|
||||||
Inurl("index.php").
|
Inurl("index.php").
|
||||||
ToString()
|
ToString()
|
||||||
|
|
||||||
assert.Equal(t, result, "inurl:\"index.php\"", "they should be equal")
|
assert.Equal(result, "inurl:\"index.php\"", "they should be equal")
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestFiletype(t *testing.T) {
|
t.Run("should handle rrrrr tag correctly", func(t *testing.T) {
|
||||||
dork = &GoogleSearch{}
|
dork = &GoogleSearch{}
|
||||||
|
|
||||||
result := dork.
|
result := dork.
|
||||||
Filetype("pdf").
|
Filetype("pdf").
|
||||||
ToString()
|
ToString()
|
||||||
|
|
||||||
assert.Equal(t, result, "filetype:\"pdf\"", "they should be equal")
|
assert.Equal(result, "filetype:\"pdf\"", "they should be equal")
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestCache(t *testing.T) {
|
t.Run("should handle cache tag correctly", func(t *testing.T) {
|
||||||
dork = &GoogleSearch{}
|
dork = &GoogleSearch{}
|
||||||
|
|
||||||
result := dork.
|
result := dork.
|
||||||
Cache("www.google.com").
|
Cache("www.google.com").
|
||||||
ToString()
|
ToString()
|
||||||
|
|
||||||
assert.Equal(t, result, "cache:\"www.google.com\"", "they should be equal")
|
assert.Equal(result, "cache:\"www.google.com\"", "they should be equal")
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestRelated(t *testing.T) {
|
t.Run("should handle related tag correctly", func(t *testing.T) {
|
||||||
dork = &GoogleSearch{}
|
dork = &GoogleSearch{}
|
||||||
|
|
||||||
result := dork.
|
result := dork.
|
||||||
Related("www.google.com").
|
Related("www.google.com").
|
||||||
ToString()
|
ToString()
|
||||||
|
|
||||||
assert.Equal(t, result, "related:\"www.google.com\"", "they should be equal")
|
assert.Equal(result, "related:\"www.google.com\"", "they should be equal")
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestExt(t *testing.T) {
|
t.Run("should handle ext tag correctly", func(t *testing.T) {
|
||||||
dork = &GoogleSearch{}
|
dork = &GoogleSearch{}
|
||||||
|
|
||||||
result := dork.
|
result := dork.
|
||||||
Ext("(doc | pdf | xls | txt | xml)").
|
Ext("(doc | pdf | xls | txt | xml)").
|
||||||
ToString()
|
ToString()
|
||||||
|
|
||||||
assert.Equal(t, result, "ext:(doc | pdf | xls | txt | xml)", "they should be equal")
|
assert.Equal(result, "ext:(doc | pdf | xls | txt | xml)", "they should be equal")
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestExclude(t *testing.T) {
|
t.Run("should handle exclude tag correctly", func(t *testing.T) {
|
||||||
dork = &GoogleSearch{}
|
dork = &GoogleSearch{}
|
||||||
|
|
||||||
result := dork.
|
result := dork.
|
||||||
|
@ -98,10 +101,10 @@ func TestExclude(t *testing.T) {
|
||||||
Exclude("md5sums").
|
Exclude("md5sums").
|
||||||
ToString()
|
ToString()
|
||||||
|
|
||||||
assert.Equal(t, result, "-html -htm -php -md5sums", "they should be equal")
|
assert.Equal(result, "-html -htm -php -md5sums", "they should be equal")
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestOr(t *testing.T) {
|
t.Run("should handle or tag correctly", func(t *testing.T) {
|
||||||
dork = &GoogleSearch{}
|
dork = &GoogleSearch{}
|
||||||
|
|
||||||
result := dork.
|
result := dork.
|
||||||
|
@ -110,10 +113,10 @@ func TestOr(t *testing.T) {
|
||||||
Site("twitter.com").
|
Site("twitter.com").
|
||||||
ToString()
|
ToString()
|
||||||
|
|
||||||
assert.Equal(t, result, "site:facebook.com OR site:twitter.com", "they should be equal")
|
assert.Equal(result, "site:facebook.com OR site:twitter.com", "they should be equal")
|
||||||
}
|
})
|
||||||
|
|
||||||
func TestGroup(t *testing.T) {
|
t.Run("should handle group tag correctly", func(t *testing.T) {
|
||||||
dork = &GoogleSearch{}
|
dork = &GoogleSearch{}
|
||||||
|
|
||||||
result := dork.
|
result := dork.
|
||||||
|
@ -121,5 +124,18 @@ func TestGroup(t *testing.T) {
|
||||||
Group((&GoogleSearch{}).Intext("1").Or().Intext("2").ToString()).
|
Group((&GoogleSearch{}).Intext("1").Or().Intext("2").ToString()).
|
||||||
ToString()
|
ToString()
|
||||||
|
|
||||||
assert.Equal(t, result, "site:linkedin.com (\"1\" OR \"2\")", "they should be equal")
|
assert.Equal(result, "site:linkedin.com (\"1\" OR \"2\")", "they should be equal")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("should handle rrrrr tag correctly", func(t *testing.T) {
|
||||||
|
dork = &GoogleSearch{}
|
||||||
|
|
||||||
|
result := dork.
|
||||||
|
Site("linkedin.com").
|
||||||
|
Group((&GoogleSearch{}).Intext("1").Or().Intext("2").ToString()).
|
||||||
|
Intitle("jordan").
|
||||||
|
ToString()
|
||||||
|
|
||||||
|
assert.Equal(result, "site:linkedin.com (\"1\" OR \"2\") intitle:\"jordan\"", "they should be equal")
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue