Repository: StackExchange/dnscontrol (go)

Issue:
get-zones from BIND produces invalid DS records
I have a zone file containing a DS record for a subdomain, like

```
geo		IN DS	14480 13 2 BB1C4B615CDED2B34347CF23710471934D972F1E34F53B54ED8D5F786202C73B
```

When I use `dnscontrol get-zones --format=js bind BIND domain.com` to convert this to js format, I get a DS record of the form:

```
DS('geo', '14480 13 2 BB1C4B615CDED2B34347CF23710471934D972F1E34F53B54ED8D5F786202C73B'),
 ```

but this is invalid syntax - should be separate parameters, not one string.

Despite this, preview works OK after fixing the js by hand.

Pull request:
format=js generates wrong DS() format
Fixes #2324 

Patch:
diff --git a/commands/getZones.go b/commands/getZones.go
index 3a09c526..df70c860 100644
--- a/commands/getZones.go
+++ b/commands/getZones.go
@@ -328,6 +328,8 @@ func formatDsl(zonename string, rec *models.RecordConfig, defaultTTL uint32) str
 	switch rec.Type { // #rtype_variations
 	case "CAA":
 		return makeCaa(rec, ttlop)
+	case "DS":
+		target = fmt.Sprintf("%d, %d, %d, '%s'", rec.DsKeyTag, rec.DsAlgorithm, rec.DsDigestType, rec.DsDigest)
 	case "MX":
 		target = fmt.Sprintf("%d, '%s'", rec.MxPreference, rec.GetTargetField())
 	case "NAPTR":


Test patch:
diff --git a/commands/gz_test.go b/commands/gz_test.go
index e0eb0c28..574ac27e 100644
--- a/commands/gz_test.go
+++ b/commands/gz_test.go
@@ -18,7 +18,7 @@ func TestFormatTypes(t *testing.T) {
 	  test_data/$DOMAIN.zone   zone            test_data/$DOMAIN.zone.zone
 	*/
 
-	for _, domain := range []string{"simple.com", "example.org", "apex.com"} {
+	for _, domain := range []string{"simple.com", "example.org", "apex.com", "ds.com"} {
 		t.Run(domain+"/js", func(t *testing.T) { testFormat(t, domain, "js") })
 		t.Run(domain+"/djs", func(t *testing.T) { testFormat(t, domain, "djs") })
 		t.Run(domain+"/tsv", func(t *testing.T) { testFormat(t, domain, "tsv") })
diff --git a/commands/test_data/ds.com.zone b/commands/test_data/ds.com.zone
new file mode 100644
index 00000000..49684efd
--- /dev/null
+++ b/commands/test_data/ds.com.zone
@@ -0,0 +1,4 @@
+$ORIGIN ds.com.
+$TTL 300
+@   IN SOA   ns3.serverfault.com. sysadmin.stackoverflow.com. 2020022300 3600 600 604800 1440
+geo	IN DS	14480 13 2 BB1C4B615CDED2B34347CF23710471934D972F1E34F53B54ED8D5F786202C73B
diff --git a/commands/test_data/ds.com.zone.djs b/commands/test_data/ds.com.zone.djs
new file mode 100644
index 00000000..47609004
--- /dev/null
+++ b/commands/test_data/ds.com.zone.djs
@@ -0,0 +1,7 @@
+var DSP_BIND = NewDnsProvider("bind", "BIND");
+var REG_CHANGEME = NewRegistrar("none");
+D("ds.com", REG_CHANGEME
+	, DnsProvider(DSP_BIND)
+	//, SOA('@', 'ns3.serverfault.com.', 'sysadmin.stackoverflow.com.', 2020022300, 3600, 600, 604800, 1440)
+	, DS('geo', 14480, 13, 2, 'BB1C4B615CDED2B34347CF23710471934D972F1E34F53B54ED8D5F786202C73B')
+)
diff --git a/commands/test_data/ds.com.zone.js b/commands/test_data/ds.com.zone.js
new file mode 100644
index 00000000..d812b731
--- /dev/null
+++ b/commands/test_data/ds.com.zone.js
@@ -0,0 +1,7 @@
+var DSP_BIND = NewDnsProvider("bind", "BIND");
+var REG_CHANGEME = NewRegistrar("none");
+D("ds.com", REG_CHANGEME,
+	DnsProvider(DSP_BIND),
+	//SOA('@', 'ns3.serverfault.com.', 'sysadmin.stackoverflow.com.', 2020022300, 3600, 600, 604800, 1440),
+	DS('geo', 14480, 13, 2, 'BB1C4B615CDED2B34347CF23710471934D972F1E34F53B54ED8D5F786202C73B')
+)
diff --git a/commands/test_data/ds.com.zone.tsv b/commands/test_data/ds.com.zone.tsv
new file mode 100644
index 00000000..21012c55
--- /dev/null
+++ b/commands/test_data/ds.com.zone.tsv
@@ -0,0 +1,2 @@
+ds.com	@	300	IN	SOA	ns3.serverfault.com. sysadmin.stackoverflow.com. 2020022300 3600 600 604800 1440
+geo.ds.com	geo	300	IN	DS	14480 13 2 BB1C4B615CDED2B34347CF23710471934D972F1E34F53B54ED8D5F786202C73B
diff --git a/commands/test_data/ds.com.zone.zone b/commands/test_data/ds.com.zone.zone
new file mode 100644
index 00000000..fb47c400
--- /dev/null
+++ b/commands/test_data/ds.com.zone.zone
@@ -0,0 +1,5 @@
+$ORIGIN ds.com.
+$TTL 300
+@                IN SOA   ns3.serverfault.com. sysadmin.stackoverflow.com. 2020022300 3600 600 604800 1440
+geo              IN DS    14480 13 2 BB1C4B615CDED2B34347CF23710471934D972F1E34F53B54ED8D5F786202C73B
+