add qwant, xenforo, twingly, linkfluence, and new toutiao user agent.
add Users.CountSearch test cases. add Users.SearchOffset test cases. add more Users.Count test cases. add more Users.BulkGetByName test cases. reduce boilerplate in other tests. fix bugs in Users.CountSearch and Users.BulkGetByName
This commit is contained in:
parent
301e7c6bea
commit
4126e8ed0c
|
@ -78,7 +78,7 @@ func NewDefaultUserStore(cache UserCache) (*DefaultUserStore, error) {
|
||||||
nameExists: acc.Exists(u, "name").Prepare(),
|
nameExists: acc.Exists(u, "name").Prepare(),
|
||||||
|
|
||||||
count: acc.Count(u).Prepare(),
|
count: acc.Count(u).Prepare(),
|
||||||
countSearch: acc.Count(u).Where("(name LIKE ('%'+?+'%') OR ?='') AND (email=? OR ?='') AND (group=? OR ?=0)").Prepare(),
|
countSearch: acc.Count(u).Where("(name=? OR ?='') AND (email=? OR ?='') AND (group=? OR ?=0)").Prepare(),
|
||||||
}, acc.FirstError()
|
}, acc.FirstError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ func (s *DefaultUserStore) BulkGetByName(names []string) (list []*User, err erro
|
||||||
}
|
}
|
||||||
u.Init()
|
u.Init()
|
||||||
s.cache.Set(u)
|
s.cache.Set(u)
|
||||||
list[u.ID] = u
|
list = append(list, u)
|
||||||
}
|
}
|
||||||
if err = rows.Err(); err != nil {
|
if err = rows.Err(); err != nil {
|
||||||
return list, err
|
return list, err
|
||||||
|
|
320
gen_router.go
320
gen_router.go
|
@ -598,54 +598,58 @@ var agentMapEnum = map[string]int{
|
||||||
"exabot": 16,
|
"exabot": 16,
|
||||||
"mojeek": 17,
|
"mojeek": 17,
|
||||||
"cliqz": 18,
|
"cliqz": 18,
|
||||||
"datenbank": 19,
|
"qwant": 19,
|
||||||
"baidu": 20,
|
"datenbank": 20,
|
||||||
"sogou": 21,
|
"baidu": 21,
|
||||||
"toutiao": 22,
|
"sogou": 22,
|
||||||
"haosou": 23,
|
"toutiao": 23,
|
||||||
"duckduckgo": 24,
|
"haosou": 24,
|
||||||
"seznambot": 25,
|
"duckduckgo": 25,
|
||||||
"discord": 26,
|
"seznambot": 26,
|
||||||
"telegram": 27,
|
"discord": 27,
|
||||||
"twitter": 28,
|
"telegram": 28,
|
||||||
"facebook": 29,
|
"twitter": 29,
|
||||||
"cloudflare": 30,
|
"facebook": 30,
|
||||||
"archive_org": 31,
|
"cloudflare": 31,
|
||||||
"uptimebot": 32,
|
"archive_org": 32,
|
||||||
"slackbot": 33,
|
"uptimebot": 33,
|
||||||
"apple": 34,
|
"slackbot": 34,
|
||||||
"discourse": 35,
|
"apple": 35,
|
||||||
"mattermost": 36,
|
"discourse": 36,
|
||||||
"alexa": 37,
|
"xenforo": 37,
|
||||||
"lynx": 38,
|
"mattermost": 38,
|
||||||
"blank": 39,
|
"alexa": 39,
|
||||||
"malformed": 40,
|
"lynx": 40,
|
||||||
"suspicious": 41,
|
"blank": 41,
|
||||||
"semrush": 42,
|
"malformed": 42,
|
||||||
"dotbot": 43,
|
"suspicious": 43,
|
||||||
"ahrefs": 44,
|
"semrush": 44,
|
||||||
"proximic": 45,
|
"dotbot": 45,
|
||||||
"megaindex": 46,
|
"ahrefs": 46,
|
||||||
"majestic": 47,
|
"proximic": 47,
|
||||||
"cocolyze": 48,
|
"megaindex": 48,
|
||||||
"babbar": 49,
|
"majestic": 49,
|
||||||
"surdotly": 50,
|
"cocolyze": 50,
|
||||||
"domcop": 51,
|
"babbar": 51,
|
||||||
"netcraft": 52,
|
"surdotly": 52,
|
||||||
"blexbot": 53,
|
"domcop": 53,
|
||||||
"wappalyzer": 54,
|
"netcraft": 54,
|
||||||
"burf": 55,
|
"blexbot": 55,
|
||||||
"aspiegel": 56,
|
"wappalyzer": 56,
|
||||||
"mail_ru": 57,
|
"twingly": 57,
|
||||||
"ccbot": 58,
|
"linkfluence": 58,
|
||||||
"yacy": 59,
|
"burf": 59,
|
||||||
"zgrab": 60,
|
"aspiegel": 60,
|
||||||
"cloudsystemnetworks": 61,
|
"mail_ru": 61,
|
||||||
"maui": 62,
|
"ccbot": 62,
|
||||||
"curl": 63,
|
"yacy": 63,
|
||||||
"python": 64,
|
"zgrab": 64,
|
||||||
"headlesschrome": 65,
|
"cloudsystemnetworks": 65,
|
||||||
"awesome_bot": 66,
|
"maui": 66,
|
||||||
|
"curl": 67,
|
||||||
|
"python": 68,
|
||||||
|
"headlesschrome": 69,
|
||||||
|
"awesome_bot": 70,
|
||||||
}
|
}
|
||||||
var reverseAgentMapEnum = map[int]string{
|
var reverseAgentMapEnum = map[int]string{
|
||||||
0: "unknown",
|
0: "unknown",
|
||||||
|
@ -667,54 +671,58 @@ var reverseAgentMapEnum = map[int]string{
|
||||||
16: "exabot",
|
16: "exabot",
|
||||||
17: "mojeek",
|
17: "mojeek",
|
||||||
18: "cliqz",
|
18: "cliqz",
|
||||||
19: "datenbank",
|
19: "qwant",
|
||||||
20: "baidu",
|
20: "datenbank",
|
||||||
21: "sogou",
|
21: "baidu",
|
||||||
22: "toutiao",
|
22: "sogou",
|
||||||
23: "haosou",
|
23: "toutiao",
|
||||||
24: "duckduckgo",
|
24: "haosou",
|
||||||
25: "seznambot",
|
25: "duckduckgo",
|
||||||
26: "discord",
|
26: "seznambot",
|
||||||
27: "telegram",
|
27: "discord",
|
||||||
28: "twitter",
|
28: "telegram",
|
||||||
29: "facebook",
|
29: "twitter",
|
||||||
30: "cloudflare",
|
30: "facebook",
|
||||||
31: "archive_org",
|
31: "cloudflare",
|
||||||
32: "uptimebot",
|
32: "archive_org",
|
||||||
33: "slackbot",
|
33: "uptimebot",
|
||||||
34: "apple",
|
34: "slackbot",
|
||||||
35: "discourse",
|
35: "apple",
|
||||||
36: "mattermost",
|
36: "discourse",
|
||||||
37: "alexa",
|
37: "xenforo",
|
||||||
38: "lynx",
|
38: "mattermost",
|
||||||
39: "blank",
|
39: "alexa",
|
||||||
40: "malformed",
|
40: "lynx",
|
||||||
41: "suspicious",
|
41: "blank",
|
||||||
42: "semrush",
|
42: "malformed",
|
||||||
43: "dotbot",
|
43: "suspicious",
|
||||||
44: "ahrefs",
|
44: "semrush",
|
||||||
45: "proximic",
|
45: "dotbot",
|
||||||
46: "megaindex",
|
46: "ahrefs",
|
||||||
47: "majestic",
|
47: "proximic",
|
||||||
48: "cocolyze",
|
48: "megaindex",
|
||||||
49: "babbar",
|
49: "majestic",
|
||||||
50: "surdotly",
|
50: "cocolyze",
|
||||||
51: "domcop",
|
51: "babbar",
|
||||||
52: "netcraft",
|
52: "surdotly",
|
||||||
53: "blexbot",
|
53: "domcop",
|
||||||
54: "wappalyzer",
|
54: "netcraft",
|
||||||
55: "burf",
|
55: "blexbot",
|
||||||
56: "aspiegel",
|
56: "wappalyzer",
|
||||||
57: "mail_ru",
|
57: "twingly",
|
||||||
58: "ccbot",
|
58: "linkfluence",
|
||||||
59: "yacy",
|
59: "burf",
|
||||||
60: "zgrab",
|
60: "aspiegel",
|
||||||
61: "cloudsystemnetworks",
|
61: "mail_ru",
|
||||||
62: "maui",
|
62: "ccbot",
|
||||||
63: "curl",
|
63: "yacy",
|
||||||
64: "python",
|
64: "zgrab",
|
||||||
65: "headlesschrome",
|
65: "cloudsystemnetworks",
|
||||||
66: "awesome_bot",
|
66: "maui",
|
||||||
|
67: "curl",
|
||||||
|
68: "python",
|
||||||
|
69: "headlesschrome",
|
||||||
|
70: "awesome_bot",
|
||||||
}
|
}
|
||||||
var markToAgent = map[string]string{
|
var markToAgent = map[string]string{
|
||||||
"OPR": "opera",
|
"OPR": "opera",
|
||||||
|
@ -735,6 +743,7 @@ var markToAgent = map[string]string{
|
||||||
"Baiduspider": "baidu",
|
"Baiduspider": "baidu",
|
||||||
"Sogou": "sogou",
|
"Sogou": "sogou",
|
||||||
"ToutiaoSpider": "toutiao",
|
"ToutiaoSpider": "toutiao",
|
||||||
|
"Bytespider": "toutiao",
|
||||||
"360Spider": "haosou",
|
"360Spider": "haosou",
|
||||||
"bingbot": "bing",
|
"bingbot": "bing",
|
||||||
"BingPreview": "bing",
|
"BingPreview": "bing",
|
||||||
|
@ -743,6 +752,7 @@ var markToAgent = map[string]string{
|
||||||
"Exabot": "exabot",
|
"Exabot": "exabot",
|
||||||
"MojeekBot": "mojeek",
|
"MojeekBot": "mojeek",
|
||||||
"Cliqzbot": "cliqz",
|
"Cliqzbot": "cliqz",
|
||||||
|
"Qwantify": "qwant",
|
||||||
"netEstate": "datenbank",
|
"netEstate": "datenbank",
|
||||||
"SeznamBot": "seznambot",
|
"SeznamBot": "seznambot",
|
||||||
"CloudFlare": "cloudflare",
|
"CloudFlare": "cloudflare",
|
||||||
|
@ -757,6 +767,7 @@ var markToAgent = map[string]string{
|
||||||
"Facebot": "facebook",
|
"Facebot": "facebook",
|
||||||
"Applebot": "apple",
|
"Applebot": "apple",
|
||||||
"Discourse": "discourse",
|
"Discourse": "discourse",
|
||||||
|
"XenForo": "xenforo",
|
||||||
"mattermost": "mattermost",
|
"mattermost": "mattermost",
|
||||||
"ia_archiver": "alexa",
|
"ia_archiver": "alexa",
|
||||||
"SemrushBot": "semrush",
|
"SemrushBot": "semrush",
|
||||||
|
@ -773,6 +784,8 @@ var markToAgent = map[string]string{
|
||||||
"NetcraftSurveyAgent": "netcraft",
|
"NetcraftSurveyAgent": "netcraft",
|
||||||
"BLEXBot": "blexbot",
|
"BLEXBot": "blexbot",
|
||||||
"Wappalyzer": "wappalyzer",
|
"Wappalyzer": "wappalyzer",
|
||||||
|
"Twingly": "twingly",
|
||||||
|
"linkfluence": "linkfluence",
|
||||||
"Burf": "burf",
|
"Burf": "burf",
|
||||||
"AspiegelBot": "aspiegel",
|
"AspiegelBot": "aspiegel",
|
||||||
"PetalBot": "aspiegel",
|
"PetalBot": "aspiegel",
|
||||||
|
@ -795,18 +808,19 @@ var markToID = map[string]int{
|
||||||
"MSIE": 6,
|
"MSIE": 6,
|
||||||
"Trident": 7,
|
"Trident": 7,
|
||||||
"Edge": 5,
|
"Edge": 5,
|
||||||
"Lynx": 38,
|
"Lynx": 40,
|
||||||
"SamsungBrowser": 10,
|
"SamsungBrowser": 10,
|
||||||
"UCBrowser": 11,
|
"UCBrowser": 11,
|
||||||
"Google": 12,
|
"Google": 12,
|
||||||
"Googlebot": 12,
|
"Googlebot": 12,
|
||||||
"yandex": 13,
|
"yandex": 13,
|
||||||
"DuckDuckBot": 24,
|
"DuckDuckBot": 25,
|
||||||
"DuckDuckGo": 24,
|
"DuckDuckGo": 25,
|
||||||
"Baiduspider": 20,
|
"Baiduspider": 21,
|
||||||
"Sogou": 21,
|
"Sogou": 22,
|
||||||
"ToutiaoSpider": 22,
|
"ToutiaoSpider": 23,
|
||||||
"360Spider": 23,
|
"Bytespider": 23,
|
||||||
|
"360Spider": 24,
|
||||||
"bingbot": 14,
|
"bingbot": 14,
|
||||||
"BingPreview": 14,
|
"BingPreview": 14,
|
||||||
"msnbot": 14,
|
"msnbot": 14,
|
||||||
|
@ -814,49 +828,53 @@ var markToID = map[string]int{
|
||||||
"Exabot": 16,
|
"Exabot": 16,
|
||||||
"MojeekBot": 17,
|
"MojeekBot": 17,
|
||||||
"Cliqzbot": 18,
|
"Cliqzbot": 18,
|
||||||
"netEstate": 19,
|
"Qwantify": 19,
|
||||||
"SeznamBot": 25,
|
"netEstate": 20,
|
||||||
"CloudFlare": 30,
|
"SeznamBot": 26,
|
||||||
"archive": 31,
|
"CloudFlare": 31,
|
||||||
"Uptimebot": 32,
|
"archive": 32,
|
||||||
"Slackbot": 33,
|
"Uptimebot": 33,
|
||||||
"Slack": 33,
|
"Slackbot": 34,
|
||||||
"Discordbot": 26,
|
"Slack": 34,
|
||||||
"TelegramBot": 27,
|
"Discordbot": 27,
|
||||||
"Twitterbot": 28,
|
"TelegramBot": 28,
|
||||||
"facebookexternalhit": 29,
|
"Twitterbot": 29,
|
||||||
"Facebot": 29,
|
"facebookexternalhit": 30,
|
||||||
"Applebot": 34,
|
"Facebot": 30,
|
||||||
"Discourse": 35,
|
"Applebot": 35,
|
||||||
"mattermost": 36,
|
"Discourse": 36,
|
||||||
"ia_archiver": 37,
|
"XenForo": 37,
|
||||||
"SemrushBot": 42,
|
"mattermost": 38,
|
||||||
"DotBot": 43,
|
"ia_archiver": 39,
|
||||||
"AhrefsBot": 44,
|
"SemrushBot": 44,
|
||||||
"proximic": 45,
|
"DotBot": 45,
|
||||||
"MegaIndex": 46,
|
"AhrefsBot": 46,
|
||||||
"MJ12bot": 47,
|
"proximic": 47,
|
||||||
"mj12bot": 47,
|
"MegaIndex": 48,
|
||||||
"Cocolyzebot": 48,
|
"MJ12bot": 49,
|
||||||
"Barkrowler": 49,
|
"mj12bot": 49,
|
||||||
"SurdotlyBot": 50,
|
"Cocolyzebot": 50,
|
||||||
"DomCopBot": 51,
|
"Barkrowler": 51,
|
||||||
"NetcraftSurveyAgent": 52,
|
"SurdotlyBot": 52,
|
||||||
"BLEXBot": 53,
|
"DomCopBot": 53,
|
||||||
"Wappalyzer": 54,
|
"NetcraftSurveyAgent": 54,
|
||||||
"Burf": 55,
|
"BLEXBot": 55,
|
||||||
"AspiegelBot": 56,
|
"Wappalyzer": 56,
|
||||||
"PetalBot": 56,
|
"Twingly": 57,
|
||||||
"RU_Bot": 57,
|
"linkfluence": 58,
|
||||||
"CCBot": 58,
|
"Burf": 59,
|
||||||
"yacybot": 59,
|
"AspiegelBot": 60,
|
||||||
"zgrab": 60,
|
"PetalBot": 60,
|
||||||
"Nimbostratus": 61,
|
"RU_Bot": 61,
|
||||||
"MauiBot": 62,
|
"CCBot": 62,
|
||||||
"curl": 63,
|
"yacybot": 63,
|
||||||
"python": 64,
|
"zgrab": 64,
|
||||||
"HeadlessChrome": 65,
|
"Nimbostratus": 65,
|
||||||
"awesome_bot": 66,
|
"MauiBot": 66,
|
||||||
|
"curl": 67,
|
||||||
|
"python": 68,
|
||||||
|
"HeadlessChrome": 69,
|
||||||
|
"awesome_bot": 70,
|
||||||
}
|
}
|
||||||
/*var agentRank = map[string]int{
|
/*var agentRank = map[string]int{
|
||||||
"opera":9,
|
"opera":9,
|
||||||
|
@ -1022,7 +1040,7 @@ func (r *GenRouter) SuspiciousRequest(req *http.Request, pre string) {
|
||||||
pre = "Suspicious Request"
|
pre = "Suspicious Request"
|
||||||
}
|
}
|
||||||
r.dumpRequest(req,pre,r.suspReqLogger)
|
r.dumpRequest(req,pre,r.suspReqLogger)
|
||||||
co.AgentViewCounter.Bump(41)
|
co.AgentViewCounter.Bump(43)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isLocalHost(h string) bool {
|
func isLocalHost(h string) bool {
|
||||||
|
@ -1041,7 +1059,7 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
w.WriteHeader(200) // 400
|
w.WriteHeader(200) // 400
|
||||||
w.Write([]byte(""))
|
w.Write([]byte(""))
|
||||||
r.DumpRequest(req,"Malformed Request T"+strconv.Itoa(typ))
|
r.DumpRequest(req,"Malformed Request T"+strconv.Itoa(typ))
|
||||||
co.AgentViewCounter.Bump(40)
|
co.AgentViewCounter.Bump(42)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split the Host and Port string
|
// Split the Host and Port string
|
||||||
|
@ -1181,7 +1199,7 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
ua := strings.TrimSpace(strings.Replace(strings.TrimPrefix(req.UserAgent(),"Mozilla/5.0 ")," Safari/537.36","",-1)) // Noise, no one's going to be running this and it would require some sort of agent ranking system to determine which identifier should be prioritised over another
|
ua := strings.TrimSpace(strings.Replace(strings.TrimPrefix(req.UserAgent(),"Mozilla/5.0 ")," Safari/537.36","",-1)) // Noise, no one's going to be running this and it would require some sort of agent ranking system to determine which identifier should be prioritised over another
|
||||||
if ua == "" {
|
if ua == "" {
|
||||||
co.AgentViewCounter.Bump(39)
|
co.AgentViewCounter.Bump(41)
|
||||||
if c.Dev.DebugMode {
|
if c.Dev.DebugMode {
|
||||||
var pre string
|
var pre string
|
||||||
for _, char := range req.UserAgent() {
|
for _, char := range req.UserAgent() {
|
||||||
|
@ -1275,11 +1293,11 @@ func (r *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
if strings.Contains(ua,"rv:11") {
|
if strings.Contains(ua,"rv:11") {
|
||||||
agent = 6
|
agent = 6
|
||||||
}
|
}
|
||||||
case 60:
|
case 64:
|
||||||
w.WriteHeader(200) // 400
|
w.WriteHeader(200) // 400
|
||||||
w.Write([]byte(""))
|
w.Write([]byte(""))
|
||||||
r.DumpRequest(req,"Blocked Scanner")
|
r.DumpRequest(req,"Blocked Scanner")
|
||||||
co.AgentViewCounter.Bump(60)
|
co.AgentViewCounter.Bump(64)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -205,6 +205,7 @@
|
||||||
"exabot":"Exabot",
|
"exabot":"Exabot",
|
||||||
"mojeek":"MojeekBot",
|
"mojeek":"MojeekBot",
|
||||||
"cliqz":"Cliqzbot",
|
"cliqz":"Cliqzbot",
|
||||||
|
"qwant":"Qwant",
|
||||||
"datenbank":"Website Datenbank",
|
"datenbank":"Website Datenbank",
|
||||||
"sogou":"Sogou",
|
"sogou":"Sogou",
|
||||||
"toutiao":"Toutiao",
|
"toutiao":"Toutiao",
|
||||||
|
@ -222,6 +223,7 @@
|
||||||
"facebook":"Facebook",
|
"facebook":"Facebook",
|
||||||
"apple":"AppleBot",
|
"apple":"AppleBot",
|
||||||
"discourse":"Discourse Forum Onebox",
|
"discourse":"Discourse Forum Onebox",
|
||||||
|
"xenforo":"XenForo",
|
||||||
"mattermost":"Mattermost",
|
"mattermost":"Mattermost",
|
||||||
"alexa":"Alexa",
|
"alexa":"Alexa",
|
||||||
"lynx":"Lynx",
|
"lynx":"Lynx",
|
||||||
|
@ -239,6 +241,8 @@
|
||||||
"netcraft":"Netcraft",
|
"netcraft":"Netcraft",
|
||||||
"blexbot":"BLEXBot",
|
"blexbot":"BLEXBot",
|
||||||
"wappalyzer":"Wappalyzer",
|
"wappalyzer":"Wappalyzer",
|
||||||
|
"twingly":"Twingly",
|
||||||
|
"linkfluence":"Linkfluence",
|
||||||
"burf":"Burf.co",
|
"burf":"Burf.co",
|
||||||
"aspiegel":"Aspiegel",
|
"aspiegel":"Aspiegel",
|
||||||
"mail_ru":"Mail.ru bot",
|
"mail_ru":"Mail.ru bot",
|
||||||
|
|
107
misc_test.go
107
misc_test.go
|
@ -139,18 +139,16 @@ func userStoreTest(t *testing.T, newUserID int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Lock onto the specific error type. Is this even possible without sacrificing the detailed information in the error message?
|
// TODO: Lock onto the specific error type. Is this even possible without sacrificing the detailed information in the error message?
|
||||||
var userList map[int]*c.User
|
bulkGetMapEmpty := func(id int) {
|
||||||
userList, _ = c.Users.BulkGetMap([]int{-1})
|
userList, _ := c.Users.BulkGetMap([]int{id})
|
||||||
expectf(t, len(userList) == 0, "The userList length should be 0, not %d", len(userList))
|
expectf(t, len(userList) == 0, "The userList length should be 0, not %d", len(userList))
|
||||||
expectf(t, isCacheLengthZero(uc), "User cache length should be 0, not %d", cacheLength(uc))
|
expectf(t, isCacheLengthZero(uc), "User cache length should be 0, not %d", cacheLength(uc))
|
||||||
|
}
|
||||||
|
bulkGetMapEmpty(-1)
|
||||||
|
bulkGetMapEmpty(0)
|
||||||
|
|
||||||
userList, _ = c.Users.BulkGetMap([]int{0})
|
userList, _ := c.Users.BulkGetMap([]int{1})
|
||||||
expectf(t, len(userList) == 0, "The userList length should be 0, not %d", len(userList))
|
|
||||||
expectf(t, isCacheLengthZero(uc), "User cache length should be 0, not %d", cacheLength(uc))
|
|
||||||
|
|
||||||
userList, _ = c.Users.BulkGetMap([]int{1})
|
|
||||||
expectf(t, len(userList) == 1, "Returned map should have one result (UID #1), not %d", len(userList))
|
expectf(t, len(userList) == 1, "Returned map should have one result (UID #1), not %d", len(userList))
|
||||||
|
|
||||||
user, ok := userList[1]
|
user, ok := userList[1]
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Error("We couldn't find UID #1 in the returned map")
|
t.Error("We couldn't find UID #1 in the returned map")
|
||||||
|
@ -174,7 +172,39 @@ func userStoreTest(t *testing.T, newUserID int) {
|
||||||
expectf(t, !c.Users.Exists(newUserID), "UID #%d shouldn't exist", newUserID)
|
expectf(t, !c.Users.Exists(newUserID), "UID #%d shouldn't exist", newUserID)
|
||||||
|
|
||||||
expectf(t, isCacheLengthZero(uc), "User cache length should be 0, not %d", cacheLength(uc))
|
expectf(t, isCacheLengthZero(uc), "User cache length should be 0, not %d", cacheLength(uc))
|
||||||
expectIntToBeX(t, c.Users.Count(), 1, "The number of users should be one, not %d")
|
expectIntToBeX(t, c.Users.Count(), 1, "The number of users should be 1, not %d")
|
||||||
|
searchUser := func(name, email string, gid, count int) {
|
||||||
|
f := func(name, email string, gid, count int, m string) {
|
||||||
|
expectIntToBeX(t, c.Users.CountSearch(name, email, gid), count, "The number of users for "+m+", not %d")
|
||||||
|
}
|
||||||
|
f(name, email, 0, count, fmt.Sprintf("name '%s' and email '%s' should be %d", name, email, count))
|
||||||
|
f(name, "", 0, count, fmt.Sprintf("name '%s' should be %d", name, count))
|
||||||
|
f("", email, 0, count, fmt.Sprintf("email '%s' should be %d", email, count))
|
||||||
|
|
||||||
|
f2 := func(name, email string, gid, offset int, m string, args ...interface{}) {
|
||||||
|
ulist, err := c.Users.SearchOffset(name, email, gid, offset, 15)
|
||||||
|
expectNilErr(t, err)
|
||||||
|
expectIntToBeX(t, len(ulist), count, "The number of users for "+fmt.Sprintf(m, args...)+", not %d")
|
||||||
|
}
|
||||||
|
f2(name, email, 0, 0, "name '%s' and email '%s' should be %d", name, email, count)
|
||||||
|
f2(name, "", 0, 0, "name '%s' should be %d", name, count)
|
||||||
|
f2("", email, 0, 0, "email '%s' should be %d", email, count)
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
f2(name, email, 0, 10, "name '%s' and email '%s' should be %d", name, email, count)
|
||||||
|
f2(name, "", 0, 10, "name '%s' should be %d", name, count)
|
||||||
|
f2("", email, 0, 10, "email '%s' should be %d", email, count)
|
||||||
|
|
||||||
|
f2(name, email, 999, 0, "name '%s' and email '%s' should be %d", name, email, 0)
|
||||||
|
f2(name, "", 999, 0, "name '%s' should be %d", name, 0)
|
||||||
|
f2("", email, 999, 0, "email '%s' should be %d", email, 0)
|
||||||
|
|
||||||
|
f2(name, email, 999, 10, "name '%s' and email '%s' should be %d", name, email, 0)
|
||||||
|
f2(name, "", 999, 10, "name '%s' should be %d", name, 0)
|
||||||
|
f2("", email, 999, 10, "email '%s' should be %d", email, 0)
|
||||||
|
}
|
||||||
|
searchUser("Sam", "sam@localhost.loc", 0, 0)
|
||||||
|
// TODO: CountSearch gid test
|
||||||
|
|
||||||
awaitingActivation := 5
|
awaitingActivation := 5
|
||||||
// TODO: Write tests for the registration validators
|
// TODO: Write tests for the registration validators
|
||||||
|
@ -182,6 +212,9 @@ func userStoreTest(t *testing.T, newUserID int) {
|
||||||
expectNilErr(t, err)
|
expectNilErr(t, err)
|
||||||
expectf(t, uid == newUserID, "The UID of the new user should be %d not %d", newUserID, uid)
|
expectf(t, uid == newUserID, "The UID of the new user should be %d not %d", newUserID, uid)
|
||||||
expectf(t, c.Users.Exists(newUserID), "UID #%d should exist", newUserID)
|
expectf(t, c.Users.Exists(newUserID), "UID #%d should exist", newUserID)
|
||||||
|
expectIntToBeX(t, c.Users.Count(), 2, "The number of users should be 2, not %d")
|
||||||
|
searchUser("Sam", "sam@localhost.loc", 0, 1)
|
||||||
|
// TODO: CountSearch gid test
|
||||||
|
|
||||||
user, err = c.Users.Get(newUserID)
|
user, err = c.Users.Get(newUserID)
|
||||||
recordMustExist(t, err, "Couldn't find UID #%d", newUserID)
|
recordMustExist(t, err, "Couldn't find UID #%d", newUserID)
|
||||||
|
@ -195,7 +228,13 @@ func userStoreTest(t *testing.T, newUserID int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
userList, _ = c.Users.BulkGetMap([]int{1, uid})
|
userList, _ = c.Users.BulkGetMap([]int{1, uid})
|
||||||
expectf(t, len(userList) == 2, "Returned map should have two results, not %d", len(userList))
|
expectf(t, len(userList) == 2, "Returned map should have 2 results, not %d", len(userList))
|
||||||
|
// TODO: More tests on userList
|
||||||
|
|
||||||
|
{
|
||||||
|
userList, _ := c.Users.BulkGetByName([]string{"Admin", "Sam"})
|
||||||
|
expectf(t, len(userList) == 2, "Returned list should have 2 results, not %d", len(userList))
|
||||||
|
}
|
||||||
|
|
||||||
if uc != nil {
|
if uc != nil {
|
||||||
expectIntToBeX(t, uc.Length(), 2, "User cache length should be 2, not %d")
|
expectIntToBeX(t, uc.Length(), 2, "User cache length should be 2, not %d")
|
||||||
|
@ -327,10 +366,12 @@ func userStoreTest(t *testing.T, newUserID int) {
|
||||||
expectNilErr(t, err)
|
expectNilErr(t, err)
|
||||||
expect(t, user.Group == 6, "Someone's mutated this pointer elsewhere")
|
expect(t, user.Group == 6, "Someone's mutated this pointer elsewhere")
|
||||||
|
|
||||||
err = user.Delete()
|
expectNilErr(t, user.Delete())
|
||||||
expectNilErr(t, err)
|
|
||||||
expectf(t, !c.Users.Exists(newUserID), "UID #%d should no longer exist", newUserID)
|
expectf(t, !c.Users.Exists(newUserID), "UID #%d should no longer exist", newUserID)
|
||||||
afterUserFlush(newUserID)
|
afterUserFlush(newUserID)
|
||||||
|
expectIntToBeX(t, c.Users.Count(), 1, "The number of users should be 1, not %d")
|
||||||
|
searchUser("Sam", "sam@localhost.loc", 0, 0)
|
||||||
|
// TODO: CountSearch gid test
|
||||||
|
|
||||||
_, err = c.Users.Get(newUserID)
|
_, err = c.Users.Get(newUserID)
|
||||||
recordMustNotExist(t, err, "UID #%d shouldn't exist", newUserID)
|
recordMustNotExist(t, err, "UID #%d shouldn't exist", newUserID)
|
||||||
|
@ -1836,15 +1877,13 @@ func TestMetaStore(t *testing.T) {
|
||||||
expect(t, m == "", "meta var magic should be empty")
|
expect(t, m == "", "meta var magic should be empty")
|
||||||
recordMustNotExist(t, err, "meta var magic should not exist")
|
recordMustNotExist(t, err, "meta var magic should not exist")
|
||||||
|
|
||||||
err = c.Meta.Set("magic", "lol")
|
expectNilErr(t, c.Meta.Set("magic", "lol"))
|
||||||
expectNilErr(t, err)
|
|
||||||
|
|
||||||
m, err = c.Meta.Get("magic")
|
m, err = c.Meta.Get("magic")
|
||||||
expectNilErr(t, err)
|
expectNilErr(t, err)
|
||||||
expect(t, m == "lol", "meta var magic should be lol")
|
expect(t, m == "lol", "meta var magic should be lol")
|
||||||
|
|
||||||
err = c.Meta.Set("magic", "wha")
|
expectNilErr(t, c.Meta.Set("magic", "wha"))
|
||||||
expectNilErr(t, err)
|
|
||||||
|
|
||||||
m, err = c.Meta.Get("magic")
|
m, err = c.Meta.Get("magic")
|
||||||
expectNilErr(t, err)
|
expectNilErr(t, err)
|
||||||
|
@ -1925,19 +1964,20 @@ func TestWordFilters(t *testing.T) {
|
||||||
expect(t, c.WordFilters.EstCount() == 1, "Word filter list should not be empty")
|
expect(t, c.WordFilters.EstCount() == 1, "Word filter list should not be empty")
|
||||||
expect(t, c.WordFilters.Count() == 1, "Word filter list should not be empty")
|
expect(t, c.WordFilters.Count() == 1, "Word filter list should not be empty")
|
||||||
|
|
||||||
|
ftest := func(f *c.WordFilter, id int, find, replace string) {
|
||||||
|
expectf(t, f.ID == id, "Word filter ID should be %d, not %d", id, f.ID)
|
||||||
|
expectf(t, f.Find == find, "Word filter needle should be '%s', not '%s'", find, f.Find)
|
||||||
|
expectf(t, f.Replace == replace, "Word filter replacement should be '%s', not '%s'", replace, f.Replace)
|
||||||
|
}
|
||||||
|
|
||||||
filters, err = c.WordFilters.GetAll()
|
filters, err = c.WordFilters.GetAll()
|
||||||
expectNilErr(t, err)
|
expectNilErr(t, err)
|
||||||
expect(t, len(filters) == 1, "Word filter map should not be empty")
|
expect(t, len(filters) == 1, "Word filter map should not be empty")
|
||||||
filter := filters[1]
|
ftest(filters[1], 1, "imbecile", "lovely")
|
||||||
expect(t, filter.ID == 1, "Word filter ID should be 1")
|
|
||||||
expect(t, filter.Find == "imbecile", "Word filter needle should be imbecile")
|
|
||||||
expect(t, filter.Replace == "lovely", "Word filter replacement should be lovely")
|
|
||||||
|
|
||||||
filter, err = c.WordFilters.Get(1)
|
filter, err := c.WordFilters.Get(1)
|
||||||
expectNilErr(t, err)
|
expectNilErr(t, err)
|
||||||
expect(t, filter.ID == 1, "Word filter ID should be 1")
|
ftest(filter, 1, "imbecile", "lovely")
|
||||||
expect(t, filter.Find == "imbecile", "Word filter needle should be imbecile")
|
|
||||||
expect(t, filter.Replace == "lovely", "Word filter replacement should be lovely")
|
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
expectNilErr(t, c.WordFilters.Update(1, "b", "a"))
|
expectNilErr(t, c.WordFilters.Update(1, "b", "a"))
|
||||||
|
@ -1949,21 +1989,15 @@ func TestWordFilters(t *testing.T) {
|
||||||
filters, err = c.WordFilters.GetAll()
|
filters, err = c.WordFilters.GetAll()
|
||||||
expectNilErr(t, err)
|
expectNilErr(t, err)
|
||||||
expect(t, len(filters) == 1, "Word filter map should not be empty")
|
expect(t, len(filters) == 1, "Word filter map should not be empty")
|
||||||
filter = filters[1]
|
ftest(filters[1], 1, "b", "a")
|
||||||
expect(t, filter.ID == 1, "Word filter ID should be 1")
|
|
||||||
expect(t, filter.Find == "b", "Word filter needle should be b")
|
|
||||||
expect(t, filter.Replace == "a", "Word filter replacement should be a")
|
|
||||||
|
|
||||||
filter, err = c.WordFilters.Get(1)
|
filter, err = c.WordFilters.Get(1)
|
||||||
expectNilErr(t, err)
|
expectNilErr(t, err)
|
||||||
expect(t, filter.ID == 1, "Word filter ID should be 1")
|
ftest(filter, 1, "b", "a")
|
||||||
expect(t, filter.Find == "b", "Word filter needle should be imbecile")
|
|
||||||
expect(t, filter.Replace == "a", "Word filter replacement should be a")
|
|
||||||
|
|
||||||
// TODO: Add a test for ParseMessage relating to word filters
|
// TODO: Add a test for ParseMessage relating to word filters
|
||||||
|
|
||||||
err = c.WordFilters.Delete(1)
|
expectNilErr(t, c.WordFilters.Delete(1))
|
||||||
expectNilErr(t, err)
|
|
||||||
|
|
||||||
expect(t, c.WordFilters.Length() == 0, "Word filter list should be empty")
|
expect(t, c.WordFilters.Length() == 0, "Word filter list should be empty")
|
||||||
expect(t, c.WordFilters.EstCount() == 0, "Word filter list should be empty")
|
expect(t, c.WordFilters.EstCount() == 0, "Word filter list should be empty")
|
||||||
|
@ -2095,8 +2129,7 @@ func TestWidgets(t *testing.T) {
|
||||||
|
|
||||||
widget2.Enabled = false
|
widget2.Enabled = false
|
||||||
ewidget = &c.WidgetEdit{widget2, map[string]string{"Name": "Test", "Text": "Testing"}}
|
ewidget = &c.WidgetEdit{widget2, map[string]string{"Name": "Test", "Text": "Testing"}}
|
||||||
err = ewidget.Commit()
|
expectNilErr(t, ewidget.Commit())
|
||||||
expectNilErr(t, err)
|
|
||||||
|
|
||||||
widget2, err = c.Widgets.Get(1)
|
widget2, err = c.Widgets.Get(1)
|
||||||
expectNilErr(t, err)
|
expectNilErr(t, err)
|
||||||
|
|
|
@ -250,6 +250,7 @@ func main() {
|
||||||
"exabot",
|
"exabot",
|
||||||
"mojeek",
|
"mojeek",
|
||||||
"cliqz",
|
"cliqz",
|
||||||
|
"qwant",
|
||||||
"datenbank",
|
"datenbank",
|
||||||
"baidu",
|
"baidu",
|
||||||
"sogou",
|
"sogou",
|
||||||
|
@ -267,6 +268,7 @@ func main() {
|
||||||
"slackbot",
|
"slackbot",
|
||||||
"apple",
|
"apple",
|
||||||
"discourse",
|
"discourse",
|
||||||
|
"xenforo",
|
||||||
"mattermost",
|
"mattermost",
|
||||||
"alexa",
|
"alexa",
|
||||||
"lynx",
|
"lynx",
|
||||||
|
@ -286,6 +288,8 @@ func main() {
|
||||||
"netcraft",
|
"netcraft",
|
||||||
"blexbot",
|
"blexbot",
|
||||||
"wappalyzer",
|
"wappalyzer",
|
||||||
|
"twingly",
|
||||||
|
"linkfluence",
|
||||||
"burf",
|
"burf",
|
||||||
"aspiegel",
|
"aspiegel",
|
||||||
"mail_ru",
|
"mail_ru",
|
||||||
|
@ -333,6 +337,7 @@ func main() {
|
||||||
a("Baiduspider", "baidu")
|
a("Baiduspider", "baidu")
|
||||||
a("Sogou", "sogou")
|
a("Sogou", "sogou")
|
||||||
a("ToutiaoSpider", "toutiao")
|
a("ToutiaoSpider", "toutiao")
|
||||||
|
a("Bytespider", "toutiao")
|
||||||
a("360Spider", "haosou")
|
a("360Spider", "haosou")
|
||||||
a("bingbot", "bing")
|
a("bingbot", "bing")
|
||||||
a("BingPreview", "bing")
|
a("BingPreview", "bing")
|
||||||
|
@ -341,6 +346,7 @@ func main() {
|
||||||
a("Exabot", "exabot")
|
a("Exabot", "exabot")
|
||||||
a("MojeekBot", "mojeek")
|
a("MojeekBot", "mojeek")
|
||||||
a("Cliqzbot", "cliqz")
|
a("Cliqzbot", "cliqz")
|
||||||
|
a("Qwantify", "qwant")
|
||||||
a("netEstate", "datenbank")
|
a("netEstate", "datenbank")
|
||||||
a("SeznamBot", "seznambot")
|
a("SeznamBot", "seznambot")
|
||||||
a("CloudFlare", "cloudflare") // Track alwayson specifically in case there are other bots?
|
a("CloudFlare", "cloudflare") // Track alwayson specifically in case there are other bots?
|
||||||
|
@ -355,6 +361,7 @@ func main() {
|
||||||
a("Facebot", "facebook")
|
a("Facebot", "facebook")
|
||||||
a("Applebot", "apple")
|
a("Applebot", "apple")
|
||||||
a("Discourse", "discourse")
|
a("Discourse", "discourse")
|
||||||
|
a("XenForo", "xenforo")
|
||||||
a("mattermost", "mattermost")
|
a("mattermost", "mattermost")
|
||||||
a("ia_archiver", "alexa")
|
a("ia_archiver", "alexa")
|
||||||
|
|
||||||
|
@ -372,6 +379,8 @@ func main() {
|
||||||
a("NetcraftSurveyAgent", "netcraft")
|
a("NetcraftSurveyAgent", "netcraft")
|
||||||
a("BLEXBot", "blexbot")
|
a("BLEXBot", "blexbot")
|
||||||
a("Wappalyzer", "wappalyzer")
|
a("Wappalyzer", "wappalyzer")
|
||||||
|
a("Twingly", "twingly")
|
||||||
|
a("linkfluence", "linkfluence")
|
||||||
a("Burf", "burf")
|
a("Burf", "burf")
|
||||||
a("AspiegelBot", "aspiegel")
|
a("AspiegelBot", "aspiegel")
|
||||||
a("PetalBot", "aspiegel")
|
a("PetalBot", "aspiegel")
|
||||||
|
|
Loading…
Reference in New Issue