2017-07-10 20:51:25 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2020-05-29 18:19:16 +00:00
|
|
|
func TestDenylist(t *testing.T) {
|
2017-07-10 20:51:25 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
complex := []string{
|
|
|
|
"/a",
|
|
|
|
"/b/c",
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
desc string
|
|
|
|
prefixes []string
|
|
|
|
path string
|
|
|
|
block bool
|
|
|
|
}{
|
|
|
|
{"nothing blocked root", nil, "/", false},
|
|
|
|
{"nothing blocked path", nil, "/a", false},
|
|
|
|
{"exact match 1", complex, "/a", true},
|
|
|
|
{"exact match 2", complex, "/b/c", true},
|
|
|
|
{"subpath", complex, "/a/b", true},
|
|
|
|
{"longer prefix", complex, "/apple", true},
|
|
|
|
{"longer subpath", complex, "/b/c/d", true},
|
|
|
|
{"partial prefix", complex, "/b/d", false},
|
|
|
|
{"no match", complex, "/c", false},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.desc, func(t *testing.T) {
|
2020-05-29 18:19:16 +00:00
|
|
|
denylist := NewDenylist(tt.prefixes)
|
|
|
|
if got, want := denylist.Block(tt.path), tt.block; got != want {
|
2017-07-10 20:51:25 +00:00
|
|
|
t.Fatalf("got %v want %v", got, want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|