Skip to content

Commit

Permalink
Merge pull request #131 from akamai/release/v1.1.1
Browse files Browse the repository at this point in the history
Release/v1.1.1
  • Loading branch information
robertolopezlopez authored May 11, 2021
2 parents 714bc0a + 225d65d commit 0c6ee5c
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# EDGEGRID GOLANG RELEASE NOTES

## 1.1.1 (May 11, 2021)

#### BUG FIXES

* DNSv2
* Fixed parsing SVCB, HTTPS rdata.

## 1.1.0 (Feb 23, 2021)

#### FEATURES/ENHANCEMENTS:
Expand Down
20 changes: 16 additions & 4 deletions configdns-v2/record_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,19 +447,31 @@ func ParseRData(rtype string, rdata []string) map[string]interface{} {

case "SVCB":
for _, rcontent := range rdata {
parts := strings.Split(rcontent, " ")
parts := strings.SplitN(rcontent, " ", 3)
// has to be at least two fields.
if len(parts) < 2 {
break
}
fieldMap["svc_priority"], _ = strconv.Atoi(parts[0])
fieldMap["target_name"] = parts[1]
fieldMap["svc_params"] = parts[2]
if len(parts) > 2 {
fieldMap["svc_params"] = parts[2]
}
break
}

case "HTTPS":
for _, rcontent := range rdata {
parts := strings.Split(rcontent, " ")
parts := strings.SplitN(rcontent, " ", 3)
// has to be at least two fields.
if len(parts) < 2 {
break
}
fieldMap["svc_priority"], _ = strconv.Atoi(parts[0])
fieldMap["target_name"] = parts[1]
fieldMap["svc_params"] = parts[2]
if len(parts) > 2 {
fieldMap["svc_params"] = parts[2]
}
break
}

Expand Down
88 changes: 88 additions & 0 deletions configdns-v2/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,91 @@ func TestGetRecord(t *testing.T) {
assert.Equal(t, testrecord.Name, dnsTestRecordName)

}

func TestParseRDataNoParams(t *testing.T) {

rtype := "SVCB"
rdata := []string{"0 svc4.example.com."}

parsedData := ParseRData(rtype, rdata)
delete(parsedData, "target")
assert.Equal(t, len(parsedData), 2)
assert.Equal(t, parsedData["svc_priority"].(int), 0)
assert.Equal(t, parsedData["target_name"].(string), "svc4.example.com.")
}

func TestParseRDataOneParam(t *testing.T) {

rtype := "HTTPS"
// quoted
rdata := []string{"3 svc4.example.com. alpn=\"bar\""}
parsedData := ParseRData(rtype, rdata)
delete(parsedData, "target")
assert.Equal(t, len(parsedData), 3)
assert.Equal(t, parsedData["svc_priority"].(int), 3)
assert.Equal(t, parsedData["target_name"].(string), "svc4.example.com.")
assert.Equal(t, parsedData["svc_params"].(string), "alpn=\"bar\"")

// unquoted
rdata = []string{"3 svc4.example.com. alpn=bar"}
parsedData = ParseRData(rtype, rdata)
delete(parsedData, "target")
assert.Equal(t, len(parsedData), 3)
assert.Equal(t, parsedData["svc_priority"].(int), 3)
assert.Equal(t, parsedData["target_name"].(string), "svc4.example.com.")
assert.Equal(t, parsedData["svc_params"].(string), "alpn=bar")
}

func TestParseRDataMultipleParams(t *testing.T) {

rtype := "SVCB"
// quoted
rdata := []string{"3 svc4.example.com. alpn=\"bar\" port=\"8080\""}
parsedData := ParseRData(rtype, rdata)
delete(parsedData, "target")
assert.Equal(t, len(parsedData), 3)
assert.Equal(t, parsedData["svc_priority"].(int), 3)
assert.Equal(t, parsedData["target_name"].(string), "svc4.example.com.")
assert.Equal(t, parsedData["svc_params"].(string), "alpn=\"bar\" port=\"8080\"")

// unquoted
rdata = []string{"3 svc4.example.com. alpn=bar port=8080"}
parsedData = ParseRData(rtype, rdata)
delete(parsedData, "target")
assert.Equal(t, len(parsedData), 3)
assert.Equal(t, parsedData["svc_priority"].(int), 3)
assert.Equal(t, parsedData["target_name"].(string), "svc4.example.com.")
assert.Equal(t, parsedData["svc_params"].(string), "alpn=bar port=8080")

// mixed
rdata = []string{"3 svc4.example.com. alpn=bar port=\"8080\""}
parsedData = ParseRData(rtype, rdata)
delete(parsedData, "target")
assert.Equal(t, len(parsedData), 3)
assert.Equal(t, parsedData["svc_priority"].(int), 3)
assert.Equal(t, parsedData["target_name"].(string), "svc4.example.com.")
assert.Equal(t, parsedData["svc_params"].(string), "alpn=bar port=\"8080\"")
}

func TestParseRDataParamNoVal(t *testing.T) {

rtype := "HTTPS"

rdata := []string{"3 svc4.example.com. alpn"}
parsedData := ParseRData(rtype, rdata)
delete(parsedData, "target")
assert.Equal(t, len(parsedData), 3)
assert.Equal(t, parsedData["svc_priority"].(int), 3)
assert.Equal(t, parsedData["target_name"].(string), "svc4.example.com.")
assert.Equal(t, parsedData["svc_params"].(string), "alpn")
}

func TestParseRDataMissingFields(t *testing.T) {

rtype := "SVCB"

rdata := []string{"svc4.example.com."}
parsedData := ParseRData(rtype, rdata)
delete(parsedData, "target")
assert.Equal(t, len(parsedData), 0)
}

0 comments on commit 0c6ee5c

Please sign in to comment.