93 lines
2.1 KiB
Go
93 lines
2.1 KiB
Go
package middleware
|
|
|
|
import "testing"
|
|
|
|
func TestShouldSuppressAccessLogMsg(t *testing.T) {
|
|
probeLine := "| 127.0.0.1| 404 | 221.723µs| nomatch| GET /middleware/security_probe.go"
|
|
if !shouldSuppressAccessLogMsg(probeLine) {
|
|
t.Fatalf("probe access line should be suppressed")
|
|
}
|
|
|
|
rootLine := "| 127.0.0.1| 404 | 219.710µs| nomatch| GET /"
|
|
if !shouldSuppressAccessLogMsg(rootLine) {
|
|
t.Fatalf("root 404 access line should be suppressed")
|
|
}
|
|
|
|
normalLine := "| 127.0.0.1| 200 | 1.649ms| match| GET /auth/login r:/auth/login"
|
|
if shouldSuppressAccessLogMsg(normalLine) {
|
|
t.Fatalf("normal access line should not be suppressed")
|
|
}
|
|
}
|
|
|
|
func TestIsScannerProbe(t *testing.T) {
|
|
probes := []string{
|
|
"/config.js",
|
|
"/config.json",
|
|
"/config.yaml",
|
|
"/config.php",
|
|
"/config/config.js",
|
|
"/database.sql",
|
|
"/.env",
|
|
"/demo/.env",
|
|
"/sendgrid.env",
|
|
"/config.env",
|
|
"/.env.lithic",
|
|
"/credentials",
|
|
"/credentials.json",
|
|
"/credentials.ini",
|
|
"/secrets.json",
|
|
"/lithic.json",
|
|
"/sardine.json",
|
|
"/phpinfo",
|
|
"/phpinfo.php",
|
|
"/info.php",
|
|
"/wp-config.php",
|
|
"/wp-config.php.bak",
|
|
"/wp-content/debug.log",
|
|
"/wp-login.php",
|
|
"/vendor/composer/installed.json",
|
|
"/docker-compose.yml",
|
|
"/composer.json",
|
|
"/gitconfig",
|
|
"/runtime-config.js",
|
|
"/settings.json",
|
|
"/index.js",
|
|
"/config/aws.yml",
|
|
"/v1/.env",
|
|
"/demo/../.env",
|
|
"/middleware",
|
|
"/middleware/security_probe.go",
|
|
"/controllers/backend_reimburse.go",
|
|
"/routers",
|
|
"/routers/spa.go",
|
|
"/models/reimburse.go",
|
|
"/services/approval/engine.go",
|
|
"/scripts/uidmigrate/migrate_uid.go",
|
|
"/conf/app.conf",
|
|
}
|
|
for _, p := range probes {
|
|
if !IsScannerProbe(p) {
|
|
t.Errorf("IsScannerProbe(%q) = false, want true", p)
|
|
}
|
|
}
|
|
|
|
normal := []string{
|
|
"/",
|
|
"/favicon.ico",
|
|
"/backend/reimbursements",
|
|
"/platform/menu/1",
|
|
"/site/setting",
|
|
"/site/news/1",
|
|
"/uploads/logo.png",
|
|
"/themes/default/index.html",
|
|
"/static/js/app.js",
|
|
"/news",
|
|
"/page/about",
|
|
}
|
|
for _, p := range normal {
|
|
if IsScannerProbe(p) {
|
|
t.Errorf("IsScannerProbe(%q) = true, want false", p)
|
|
}
|
|
}
|
|
}
|