Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
854 B

package agent
import (
"testing"
)
func TestDenylist(t *testing.T) {
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) {
denylist := NewDenylist(tt.prefixes)
if got, want := denylist.Block(tt.path), tt.block; got != want {
t.Fatalf("got %v want %v", got, want)
}
})
}
}