mirror of
https://github.com/miekg/dns.git
synced 2025-08-14 05:26:57 +02:00
* Implement SVCB * Fix serialization and deserialization of double quotes * More effort (?) 4 months old commit * DEBUG * _ * Presentation format serialization/deserialization * _ Remove generated * Progress on presentation format parse & write * _ * Finish parsing presentation format * Regenerate * Pack unpack * Move to svcb.go Scan_rr.go and types.go should be untouched now * 🐛 Thanks ghedo * Definitions * TypeHTTPSSVC * Generated and isDuplicate * Goodbye lenient functions Now private key=value pairs have to be defined as structs too. They are no longer automatically named as KeyNNNNN * Encode/decode * Experimental svc * Read method * Implement some of the methods, use trick... to report where the error is while reading it. This should be applied to EDNS too. Todo: Find if case can only contain e := new(SVC_ALPN) and rest moved out Also fix two compile errors * Add SVC_LOCAL methods, reorder, remove alpn value, bugs * Errors * Alpn, make it build * Correct testsuite * Fully implement parser Change from keeping a state variable to reading in one iteration until the key=value pair is fully consumed * Simplify and document EDNS should be simplified too * Attempt to fix fuzzer And Alpn bug * A bug and change type values to match @ghedo's implementation * IP bug Also there are two ip duplicating patterns, one with copy, one with append. Maybe change it to be consistent. * Check for strictly increasing keys as required * Don't panic on invalid alpn * Redundant check, don't modify original array * Size calculation * Fix the fuzzer, match the style * 65535 is reserved too, don't delay errors * Check keyNNN, check for aliasform having values * IPvNHint is an array * Fix ipvNHint * Rename everything * Unrecognized keys according to the updated specification * Skip zero-length structs in generators. Fix CI * Doc cleanup * Off by one * Add parse tests * Check if private key doesn't collide with known key, invalid tests * Disallow IPv4 as IPv6. More tests. Related #1107 * Style fixes * More consistency, more tests * 🐛 Deep copy as in the documentation a := make([]net.IP, 1) a[0] = net.ParseIP("1.1.1.1").To4() b := append(make([]net.IP, 0, 1), a...) b[0] = net.ParseIP("3.1.1.1").To4() fmt.Println(a[0][0]) * Make tests readable * Move valid parse tests to different file * 🐛 One of previous commits not fully committed * Test binary single value encoding/decoding and full encode/decode * Add worst-case grows to builders, 🐛 Wrong visible character range, redundant tests * Testing improvements And don't convert to IPv4 twice * Doc update only * Document worst case allocations and ipv6 can be at most of length 39, not 40 * Redundant IP copy, consistent IPv6 behavior, fix deep copy * isDuplicate for SVCB * Optimizations * echoconfig * Svc => SVCB * Fix CI * Regenerate after REBASE (2) Rebased twice on 15th and 20th May * Rename svc, use escapeByte. * Fix parsing whitespaces between quotes, rename ECHOHOConfig * resolve Remove svcbFieldLen Use reverseInt Uppercase SVCB Rename key_value "invalid" => bad Alpn comments > 65535 check Unneeded slices * a little more read => parse IP array meaning Force pushed because forgot to change read in svcb_test.go * HTTPSSVC -> HTTPS * Use new values * mandatory code https://github.com/MikeBishop/dns-alt-svc/pull/205 * Resolve comments Rename svcb-pairs Remove SVCB_PRIVATE ranges Comment on SVCB_KEY65535 ParseError return l.token rename svcbKeyToString and svcbStringToKey privatize SVCBKeyToString, SVCBStringToKey * Refactor 1 Rename sorted, originalPairs Use append instead of copy Use svcb_RESERVED instead of 65535, with it now being private "type SVCBKey uint16" * Refactor 2 svcbKeyToString as method svcbStringToKey updated after key 0 🐛 mandatory has missing key Rename str idx < 0 * Refactor 3 Use l.token as z var key, value string Comment wrap 0: Sentences with '.' keyValue => kv * Refactor 4 * Refactor 5 len() int * Refactor 6 * Refactor 7 * Test remove parsing * Error messages * Rewrite two estimate comments * parse shouldn't modify original array 🐛 * Remove two unneeded comments * Address review comments Push 2 because can't build fuzzer python Push 3 to try again * Simplify argument duplication as per tmthrgd's suggestion And add the relevant test Force push edit: Make sorting code fit into one line * Rewrite ECHConfig and address the review * Remove the optional tab * Add To4() Check * More cleanup and fix mandatory not sorting bug
121 lines
2.5 KiB
Go
121 lines
2.5 KiB
Go
package dns
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// This tests everything valid about SVCB but parsing.
|
|
// Parsing tests belong to parse_test.go.
|
|
func TestSVCB(t *testing.T) {
|
|
svcbs := []struct {
|
|
key string
|
|
data string
|
|
}{
|
|
{`mandatory`, `alpn,key65000`},
|
|
{`alpn`, `h2,h2c`},
|
|
{`port`, `499`},
|
|
{`ipv4hint`, `3.4.3.2,1.1.1.1`},
|
|
{`no-default-alpn`, ``},
|
|
{`ipv6hint`, `1::4:4:4:4,1::3:3:3:3`},
|
|
{`echconfig`, `YUdWc2JHOD0=`},
|
|
{`key65000`, `4\ 3`},
|
|
{`key65001`, `\"\ `},
|
|
{`key65002`, ``},
|
|
{`key65003`, `=\"\"`},
|
|
{`key65004`, `\254\ \ \030\000`},
|
|
}
|
|
|
|
for _, o := range svcbs {
|
|
keyCode := svcbStringToKey(o.key)
|
|
kv := makeSVCBKeyValue(keyCode)
|
|
if kv == nil {
|
|
t.Error("failed to parse svc key: ", o.key)
|
|
continue
|
|
}
|
|
if kv.Key() != keyCode {
|
|
t.Error("key constant is not in sync: ", keyCode)
|
|
continue
|
|
}
|
|
err := kv.parse(o.data)
|
|
if err != nil {
|
|
t.Error("failed to parse svc pair: ", o.key)
|
|
continue
|
|
}
|
|
b, err := kv.pack()
|
|
if err != nil {
|
|
t.Error("failed to pack value of svc pair: ", o.key, err)
|
|
continue
|
|
}
|
|
if len(b) != int(kv.len()) {
|
|
t.Errorf("expected packed svc value %s to be of length %d but got %d", o.key, int(kv.len()), len(b))
|
|
}
|
|
err = kv.unpack(b)
|
|
if err != nil {
|
|
t.Error("failed to unpack value of svc pair: ", o.key, err)
|
|
continue
|
|
}
|
|
if str := kv.String(); str != o.data {
|
|
t.Errorf("`%s' should be equal to\n`%s', but is `%s'", o.key, o.data, str)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDecodeBadSVCB(t *testing.T) {
|
|
svcbs := []struct {
|
|
key SVCBKey
|
|
data []byte
|
|
}{
|
|
{
|
|
key: SVCB_ALPN,
|
|
data: []byte{3, 0, 0}, // There aren't three octets after 3
|
|
},
|
|
{
|
|
key: SVCB_NO_DEFAULT_ALPN,
|
|
data: []byte{0},
|
|
},
|
|
{
|
|
key: SVCB_PORT,
|
|
data: []byte{},
|
|
},
|
|
{
|
|
key: SVCB_IPV4HINT,
|
|
data: []byte{0, 0, 0},
|
|
},
|
|
{
|
|
key: SVCB_IPV6HINT,
|
|
data: []byte{0, 0, 0},
|
|
},
|
|
}
|
|
for _, o := range svcbs {
|
|
err := makeSVCBKeyValue(SVCBKey(o.key)).unpack(o.data)
|
|
if err == nil {
|
|
t.Error("accepted invalid svc value with key ", SVCBKey(o.key).String())
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCompareSVCB(t *testing.T) {
|
|
val1 := []SVCBKeyValue{
|
|
&SVCBPort{
|
|
Port: 117,
|
|
},
|
|
&SVCBAlpn{
|
|
Alpn: []string{"h2", "h3"},
|
|
},
|
|
}
|
|
val2 := []SVCBKeyValue{
|
|
&SVCBAlpn{
|
|
Alpn: []string{"h2", "h3"},
|
|
},
|
|
&SVCBPort{
|
|
Port: 117,
|
|
},
|
|
}
|
|
if !areSVCBPairArraysEqual(val1, val2) {
|
|
t.Error("svcb pairs were compared without sorting")
|
|
}
|
|
if val1[0].Key() != SVCB_PORT || val2[0].Key() != SVCB_ALPN {
|
|
t.Error("original svcb pairs were reordered during comparison")
|
|
}
|
|
}
|