From 763f630282364abd90f89dfc67d53b34e1cb3d24 Mon Sep 17 00:00:00 2001 From: Owen Smith Date: Fri, 1 Aug 2014 23:07:32 +0100 Subject: [PATCH 1/3] Make tests use actual tab chars --- resolver_test.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/resolver_test.go b/resolver_test.go index f3113bd..6a67c8d 100644 --- a/resolver_test.go +++ b/resolver_test.go @@ -105,7 +105,7 @@ func TestNameToKeyConverter(t *testing.T) { func TestAuthorityRoot(t *testing.T) { resolver.etcdPrefix = "TestAuthorityRoot/" - client.Set("TestAuthorityRoot/net/disco/.SOA", "ns1.disco.net.\\tadmin.disco.net.\\t3600\\t600\\t86400\\t10", 0) + client.Set("TestAuthorityRoot/net/disco/.SOA", "ns1.disco.net.\tadmin.disco.net.\t3600\t600\t86400\t10", 0) query := new(dns.Msg) query.SetQuestion("disco.net.", dns.TypeA) @@ -167,7 +167,7 @@ func TestAuthorityRoot(t *testing.T) { func TestAuthorityDomain(t *testing.T) { resolver.etcdPrefix = "TestAuthorityDomain/" - client.Set("TestAuthorityDomain/net/disco/.SOA", "ns1.disco.net.\\tadmin.disco.net.\\t3600\\t600\\t86400\\t10", 0) + client.Set("TestAuthorityDomain/net/disco/.SOA", "ns1.disco.net.\tadmin.disco.net.\t3600\t600\t86400\t10", 0) query := new(dns.Msg) query.SetQuestion("bar.disco.net.", dns.TypeA) @@ -226,8 +226,8 @@ func TestAuthorityDomain(t *testing.T) { func TestAuthoritySubdomain(t *testing.T) { resolver.etcdPrefix = "TestAuthoritySubdomain/" - client.Set("TestAuthoritySubdomain/net/disco/.SOA", "ns1.disco.net.\\tadmin.disco.net.\\t3600\\t600\\t86400\\t10", 0) - client.Set("TestAuthoritySubdomain/net/disco/bar/.SOA", "ns1.bar.disco.net.\\tbar.disco.net.\\t3600\\t600\\t86400\\t10", 0) + client.Set("TestAuthoritySubdomain/net/disco/.SOA", "ns1.disco.net.\tadmin.disco.net.\t3600\t600\t86400\t10", 0) + client.Set("TestAuthoritySubdomain/net/disco/bar/.SOA", "ns1.bar.disco.net.\tbar.disco.net.\t3600\t600\t86400\t10", 0) query := new(dns.Msg) query.SetQuestion("foo.bar.disco.net.", dns.TypeA) @@ -291,7 +291,7 @@ func TestAuthoritySubdomain(t *testing.T) { func TestAnswerQuestionA(t *testing.T) { resolver.etcdPrefix = "TestAnswerQuestionA/" client.Set("TestAnswerQuestionA/net/disco/bar/.A", "1.2.3.4", 0) - client.Set("TestAnswerQuestionA/net/disco/.SOA", "ns1.disco.net.\\tadmin.disco.net.\\t3600\\t600\\t86400\\t10", 0) + client.Set("TestAnswerQuestionA/net/disco/.SOA", "ns1.disco.net.\tadmin.disco.net.\t3600\t600\t86400\t10", 0) query := new(dns.Msg) query.SetQuestion("bar.disco.net.", dns.TypeA) @@ -331,7 +331,7 @@ func TestAnswerQuestionA(t *testing.T) { func TestAnswerQuestionAAAA(t *testing.T) { resolver.etcdPrefix = "TestAnswerQuestionAAAA/" client.Set("TestAnswerQuestionAAAA/net/disco/bar/.AAAA", "::1", 0) - client.Set("TestAnswerQuestionAAAA/net/disco/.SOA", "ns1.disco.net.\\tadmin.disco.net.\\t3600\\t600\\t86400\\t10", 0) + client.Set("TestAnswerQuestionAAAA/net/disco/.SOA", "ns1.disco.net.\tadmin.disco.net.\t3600\t600\t86400\t10", 0) query := new(dns.Msg) query.SetQuestion("bar.disco.net.", dns.TypeAAAA) @@ -563,7 +563,7 @@ func TestLookupAnswerForNS(t *testing.T) { func TestLookupAnswerForSOA(t *testing.T) { resolver.etcdPrefix = "TestLookupAnswerForSOA/" - client.Set("TestLookupAnswerForSOA/net/disco/.SOA", "ns1.disco.net.\\tadmin.disco.net.\\t3600\\t600\\t86400\\t10", 0) + client.Set("TestLookupAnswerForSOA/net/disco/.SOA", "ns1.disco.net.\tadmin.disco.net.\t3600\t600\t86400\t10", 0) records, _ := resolver.LookupAnswersForType("disco.net.", dns.TypeSOA) @@ -677,7 +677,7 @@ func TestLookupAnswerForSRV(t *testing.T) { resolver.etcdPrefix = "TestLookupAnswerForSRV/" client.Set("TestLookupAnswerForSRV/net/disco/_tcp/_http/.SRV", - "100\\t100\\t80\\tsome-webserver.disco.net", + "100\t100\t80\tsome-webserver.disco.net", 0) records, _ := resolver.LookupAnswersForType("_http._tcp.disco.net.", dns.TypeSRV) @@ -712,13 +712,13 @@ func TestLookupAnswerForSRVInvalidValues(t *testing.T) { var bad_vals_map = map[string]string { "wrong-delimiter": "10 10 80 foo.disco.net", - "not-enough-fields": "0\\t0", - "neg-int-priority": "-10\\t10\\t80\\tfoo.disco.net", - "neg-int-weight": "10\\t-10\\t80\\tfoo.disco.net", - "neg-int-port": "10\\t10\\t-80\\tfoo.disco.net", - "large-int-priority": "65536\\t10\\t80\\tfoo.disco.net", - "large-int-weight": "10\\t65536\\t80\\tfoo.disco.net", - "large-int-port": "10\\t10\\t65536\\tfoo.disco.net"} + "not-enough-fields": "0\t0", + "neg-int-priority": "-10\t10\t80\tfoo.disco.net", + "neg-int-weight": "10\t-10\t80\tfoo.disco.net", + "neg-int-port": "10\t10\t-80\tfoo.disco.net", + "large-int-priority": "65536\t10\t80\tfoo.disco.net", + "large-int-weight": "10\t65536\t80\tfoo.disco.net", + "large-int-port": "10\t10\t65536\tfoo.disco.net"} for name, value := range bad_vals_map { From 1e9f666edebc2d22a2bf33624717833466035408 Mon Sep 17 00:00:00 2001 From: Owen Smith Date: Fri, 1 Aug 2014 23:07:59 +0100 Subject: [PATCH 2/3] Split on tab characters, not '\t'. Fixes #16 --- resolver.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resolver.go b/resolver.go index da5887a..e795b5c 100644 --- a/resolver.go +++ b/resolver.go @@ -367,7 +367,7 @@ var converters = map[uint16]func (node *etcd.Node, header dns.RR_Header) (rr dns }, dns.TypeSRV: func (node *etcd.Node, header dns.RR_Header) (rr dns.RR, err error) { - parts := strings.SplitN(node.Value, "\\t", 4) + parts := strings.SplitN(node.Value, "\t", 4) if len(parts) != 4 { err = &NodeConversionError{ @@ -404,7 +404,7 @@ var converters = map[uint16]func (node *etcd.Node, header dns.RR_Header) (rr dns }, dns.TypeSOA: func (node *etcd.Node, header dns.RR_Header) (rr dns.RR, err error) { - parts := strings.SplitN(node.Value, "\\t", 6) + parts := strings.SplitN(node.Value, "\t", 6) if len(parts) < 6 { err = &NodeConversionError{ From 39f43ce8a9e62dfefb73601031b226f37d5195ca Mon Sep 17 00:00:00 2001 From: Owen Smith Date: Fri, 1 Aug 2014 23:19:52 +0100 Subject: [PATCH 3/3] Update README to be clear about tabs in the SOA example --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1c78543..ac3ecc3 100644 --- a/README.md +++ b/README.md @@ -126,21 +126,23 @@ If you're not familiar with the DNS specification, to behave *correctly* as an a #### SOA ```shell -curl -L http://127.0.0.1:4001/v2/keys/net/discodns/.SOA -XPUT -d value="ns1.discodns.net.\tadmin.discodns.net.\t3600\t600\t86400\t10" +curl -L http://127.0.0.1:4001/v2/keys/net/discodns/.SOA -XPUT -d value=$'ns1.discodns.net.\tadmin.discodns.net.\t3600\t600\t86400\t10' {"action":"set","node":{"key":"/net/discodns/.SOA","value":"...","modifiedIndex":11,"createdIndex":11}} ``` Let's break out the value and see what we've got. ``` -ns1.discodns.net \t << - This is the root, master nameserver for this delegated domain -admin.discodns.net \t << - This is the "admin" email address, note the first segment is actually the user (`admin@discodns.net`) -3600 \t << - Time in seconds for any secondary DNS servers to cache the zone (used with `AXFR`) -600 \t << - Interval in seconds for any secondary DNS servers to re-try in the event of a failed zone update -86400 \t << - Expiry time in seconds for any secondary DNS server to drop the zone data (too old) -10 << - Minimum TTL that applies to all DNS entries in the zone +ns1.discodns.net << - This is the root, master nameserver for this delegated domain +admin.discodns.net << - This is the "admin" email address, note the first segment is actually the user (`admin@discodns.net`) +3600 << - Time in seconds for any secondary DNS servers to cache the zone (used with `AXFR`) +600 << - Interval in seconds for any secondary DNS servers to re-try in the event of a failed zone update +86400 << - Expiry time in seconds for any secondary DNS server to drop the zone data (too old) +10 << - Minimum TTL that applies to all DNS entries in the zone ``` +These are all tab-separated in the PUT request body. (The `$''` is just a convenience to neatly escape tabs in bash; you could use regular bash strings, with `\u0009` or `%09` for the tab chars, too) + **Note:** If you're familiar with SOA records, you'll probably notice a value missing from above. The "Serial Number" (should be in the 3rd position) is actually filled in automatically by discodns, because it uses the current index of the etcd cluster to describe the current version of the zone. (TODO). #### NS