diff options
author | 2023-08-14 14:01:13 -0400 | |
---|---|---|
committer | 2023-08-14 11:01:13 -0700 | |
commit | 90d55611a2efbcbdd58c63ecae9f979af4668587 (patch) | |
tree | 29ff3fdcdad38be0f4fdefbd9f351d23795dceff /plugin/dnstap/setup_test.go | |
parent | eec26e59c63954bd410965ab8fa4663e03e1d9a1 (diff) | |
download | coredns-90d55611a2efbcbdd58c63ecae9f979af4668587.tar.gz coredns-90d55611a2efbcbdd58c63ecae9f979af4668587.tar.zst coredns-90d55611a2efbcbdd58c63ecae9f979af4668587.zip |
Plugin dnstap: add support for "extra" field in payload (#6226)
* dnstap: add 'extra' field
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
* dnstap: add setup_test for 'extra' field
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
* udnstap: update document and test
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
* dnstap: update setup_test for more coverage
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
* dnstap: add TapMessageWithMetadata function to Dnstap
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
* dnstap: adapt dnstap and forward plugins to use TapMessageWithMetadata
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
* change TapMessageWithMetadata function
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
* tab inconsistency fix
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
* fix replacer to support empty state
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
* add replacer test for empty status parameter
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
* dnstap: update unit test for 'extra' field
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
* clean up code
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
* gofmt fix & static analysis fix
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
* dnstap: refactor
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
---------
Signed-off-by: chenyuheng <chenyuheng99@qq.com>
Diffstat (limited to 'plugin/dnstap/setup_test.go')
-rw-r--r-- | plugin/dnstap/setup_test.go | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/plugin/dnstap/setup_test.go b/plugin/dnstap/setup_test.go index 029a4a73b..83659638d 100644 --- a/plugin/dnstap/setup_test.go +++ b/plugin/dnstap/setup_test.go @@ -10,11 +10,12 @@ import ( ) type results struct { - endpoint string - full bool - proto string - identity []byte - version []byte + endpoint string + full bool + proto string + identity []byte + version []byte + extraFormat string } func TestConfig(t *testing.T) { @@ -24,27 +25,33 @@ func TestConfig(t *testing.T) { fail bool expect []results }{ - {"dnstap dnstap.sock full", false, []results{{"dnstap.sock", true, "unix", []byte(hostname), []byte("-")}}}, - {"dnstap unix://dnstap.sock", false, []results{{"dnstap.sock", false, "unix", []byte(hostname), []byte("-")}}}, - {"dnstap tcp://127.0.0.1:6000", false, []results{{"127.0.0.1:6000", false, "tcp", []byte(hostname), []byte("-")}}}, - {"dnstap tcp://[::1]:6000", false, []results{{"[::1]:6000", false, "tcp", []byte(hostname), []byte("-")}}}, - {"dnstap tcp://example.com:6000", false, []results{{"example.com:6000", false, "tcp", []byte(hostname), []byte("-")}}}, - {"dnstap", true, []results{{"fail", false, "tcp", []byte(hostname), []byte("-")}}}, - {"dnstap dnstap.sock full {\nidentity NAME\nversion VER\n}\n", false, []results{{"dnstap.sock", true, "unix", []byte("NAME"), []byte("VER")}}}, - {"dnstap dnstap.sock {\nidentity NAME\nversion VER\n}\n", false, []results{{"dnstap.sock", false, "unix", []byte("NAME"), []byte("VER")}}}, - {"dnstap {\nidentity NAME\nversion VER\n}\n", true, []results{{"fail", false, "tcp", []byte("NAME"), []byte("VER")}}}, + {"dnstap dnstap.sock full", false, []results{{"dnstap.sock", true, "unix", []byte(hostname), []byte("-"), ""}}}, + {"dnstap unix://dnstap.sock", false, []results{{"dnstap.sock", false, "unix", []byte(hostname), []byte("-"), ""}}}, + {"dnstap tcp://127.0.0.1:6000", false, []results{{"127.0.0.1:6000", false, "tcp", []byte(hostname), []byte("-"), ""}}}, + {"dnstap tcp://[::1]:6000", false, []results{{"[::1]:6000", false, "tcp", []byte(hostname), []byte("-"), ""}}}, + {"dnstap tcp://example.com:6000", false, []results{{"example.com:6000", false, "tcp", []byte(hostname), []byte("-"), ""}}}, + {"dnstap", true, []results{{"fail", false, "tcp", []byte(hostname), []byte("-"), ""}}}, + {"dnstap dnstap.sock full {\nidentity NAME\nversion VER\n}\n", false, []results{{"dnstap.sock", true, "unix", []byte("NAME"), []byte("VER"), ""}}}, + {"dnstap dnstap.sock full {\nidentity NAME\nversion VER\nextra EXTRA\n}\n", false, []results{{"dnstap.sock", true, "unix", []byte("NAME"), []byte("VER"), "EXTRA"}}}, + {"dnstap dnstap.sock {\nidentity NAME\nversion VER\nextra EXTRA\n}\n", false, []results{{"dnstap.sock", false, "unix", []byte("NAME"), []byte("VER"), "EXTRA"}}}, + {"dnstap {\nidentity NAME\nversion VER\nextra EXTRA\n}\n", true, []results{{"fail", false, "tcp", []byte("NAME"), []byte("VER"), "EXTRA"}}}, {`dnstap dnstap.sock full { identity NAME version VER + extra EXTRA } dnstap tcp://127.0.0.1:6000 { identity NAME2 version VER2 + extra EXTRA2 }`, false, []results{ - {"dnstap.sock", true, "unix", []byte("NAME"), []byte("VER")}, - {"127.0.0.1:6000", false, "tcp", []byte("NAME2"), []byte("VER2")}, + {"dnstap.sock", true, "unix", []byte("NAME"), []byte("VER"), "EXTRA"}, + {"127.0.0.1:6000", false, "tcp", []byte("NAME2"), []byte("VER2"), "EXTRA2"}, }}, - {"dnstap tls://127.0.0.1:6000", false, []results{{"127.0.0.1:6000", false, "tls", []byte(hostname), []byte("-")}}}, + {"dnstap tls://127.0.0.1:6000", false, []results{{"127.0.0.1:6000", false, "tls", []byte(hostname), []byte("-"), ""}}}, + {"dnstap dnstap.sock {\nidentity\n}\n", true, []results{{"dnstap.sock", false, "unix", []byte(hostname), []byte("-"), ""}}}, + {"dnstap dnstap.sock {\nversion\n}\n", true, []results{{"dnstap.sock", false, "unix", []byte(hostname), []byte("-"), ""}}}, + {"dnstap dnstap.sock {\nextra\n}\n", true, []results{{"dnstap.sock", false, "unix", []byte(hostname), []byte("-"), ""}}}, } for i, tc := range tests { c := caddy.NewTestController("dns", tc.in) @@ -75,6 +82,9 @@ func TestConfig(t *testing.T) { if x := string(tap.Version); x != string(tc.expect[i].version) { t.Errorf("Test %d: expected version %s, got %s", i, tc.expect[i].version, x) } + if x := tap.ExtraFormat; x != tc.expect[i].extraFormat { + t.Errorf("Test %d: expected extra format %s, got %s", i, tc.expect[i].extraFormat, x) + } } } } |