plugin/rewrite - extend edns0 local variable support with metadata (#1928)

* - add support of metadata values for edns0 local variables

* - comments from review.

* - simplify label check. Add UT

* - enhance check for Labels, add UT
- remove IsMetadataSet

* - edns0 variable - if variable is not found just ignore the rewrite.
This commit is contained in:
Francois Tur
2018-07-08 03:18:01 -04:00
committed by Miek Gieben
parent 6ec1978340
commit 7745462430
9 changed files with 132 additions and 22 deletions

View File

@@ -30,8 +30,8 @@ func (m *testHandler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns
func TestMetadataServeDNS(t *testing.T) {
expectedMetadata := []testProvider{
testProvider{"test/key1": func() string { return "testvalue1" }},
testProvider{"test/key2": func() string { return "two" }, "test/key3": func() string { return "testvalue3" }},
{"test/key1": func() string { return "testvalue1" }},
{"test/key2": func() string { return "two" }, "test/key3": func() string { return "testvalue3" }},
}
// Create fake Providers based on expectedMetadata
providers := []Provider{}
@@ -52,6 +52,9 @@ func TestMetadataServeDNS(t *testing.T) {
for _, expected := range expectedMetadata {
for label, expVal := range expected {
if !IsLabel(label) {
t.Errorf("Expected label %s is not considered a valid label", label)
}
val := ValueFunc(nctx, label)
if val() != expVal() {
t.Errorf("Expected value %s for %s, but got %s", expVal(), label, val())
@@ -59,3 +62,26 @@ func TestMetadataServeDNS(t *testing.T) {
}
}
}
func TestLabelFormat(t *testing.T) {
labels := []struct {
label string
isValid bool
}{
{"plugin/LABEL", true},
{"p/LABEL", true},
{"plugin/L", true},
{"LABEL", false},
{"plugin.LABEL", false},
{"/NO-PLUGIN-NOT-ACCEPTED", false},
{"ONLY-PLUGIN-NOT-ACCEPTED/", false},
{"PLUGIN/LABEL/SUB-LABEL", false},
{"/", false},
}
for _, test := range labels {
if IsLabel(test.label) != test.isValid {
t.Errorf("Label %v is expected to have this validaty : %v - and has the opposite", test.label, test.isValid)
}
}
}