"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "msg_helpers_test.go" between
dns-1.1.47.tar.gz and dns-1.1.48.tar.gz

About: GO DNS implements a DNS library in Go.

msg_helpers_test.go  (dns-1.1.47):msg_helpers_test.go  (dns-1.1.48)
skipping to change at line 22 skipping to change at line 22
// the other code paths. // the other code paths.
func TestPackDataNsec(t *testing.T) { func TestPackDataNsec(t *testing.T) {
type args struct { type args struct {
bitmap []uint16 bitmap []uint16
msg []byte msg []byte
off int off int
} }
tests := []struct { tests := []struct {
name string name string
args args args args
want int wantOff int
wantBytes []byte
wantErr bool wantErr bool
wantErrMsg string wantErrMsg string
}{ }{
{ {
name: "overflow", name: "overflow",
args: args{ args: args{
bitmap: []uint16{ bitmap: []uint16{
8962, 8963, 8970, 8971, 8978, 8979, 8962, 8963, 8970, 8971, 8978, 8979,
8986, 8987, 8994, 8995, 9002, 9003, 8986, 8987, 8994, 8995, 9002, 9003,
9010, 9011, 9018, 9019, 9026, 9027, 9010, 9011, 9018, 9019, 9026, 9027,
skipping to change at line 47 skipping to change at line 48
48, 48, 48, 48, 0, 0, 0, 48, 48, 48, 48, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 50, 1, 0, 0, 0, 0, 0, 0, 50,
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
0, 54, 48, 48, 48, 48, 0, 54, 48, 48, 48, 48,
0, 19, 48, 48, 0, 19, 48, 48,
}, },
off: 48, off: 48,
}, },
wantErr: true, wantErr: true,
wantErrMsg: "dns: overflow packing nsec", wantErrMsg: "dns: overflow packing nsec",
want: 31, wantOff: 48,
}, },
{ {
name: "disordered nsec bits", name: "disordered nsec bits",
args: args{ args: args{
bitmap: []uint16{ bitmap: []uint16{
8962, 8962,
0, 1,
}, },
msg: []byte{ msg: []byte{
48, 48, 48, 48, 0, 0, 0, 1, 0, 0, 0, 0, 48, 48, 48, 48, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 50, 48, 48, 48, 48, 48, 48, 0, 54, 48, 0, 0, 50, 48, 48, 48, 48, 48, 48, 0, 54, 48,
48, 48, 48, 0, 19, 48, 48, 48, 48, 48, 48 , 0, 48, 48, 48, 0, 19, 48, 48, 48, 48, 48, 48 , 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 50, 48, 48, 0, 0, 1, 0, 0, 0, 0, 0, 0, 50, 48, 48,
48, 48, 48, 48, 0, 54, 48, 48, 48, 48, 0, 19, 48, 48, 48, 48, 0, 54, 48, 48, 48, 48, 0, 19,
48, 48, 48, 48, 48, 48, 0, 0, 0, 1, 0, 0, 48, 48, 48, 48, 48, 48, 0, 0, 0, 1, 0, 0,
0, 0, 0, 0, 50, 48, 48, 48, 48, 48, 48, 0 , 0, 0, 0, 0, 50, 48, 48, 48, 48, 48, 48, 0 ,
54, 48, 48, 48, 48, 0, 19, 48, 48, 48, 48 , 48, 54, 48, 48, 48, 48, 0, 19, 48, 48, 48, 48 , 48,
48, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 50, 48, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 50,
48, 48, 48, 48, 48, 48, 0, 54, 48, 48, 48 , 48, 48, 48, 48, 48, 48, 48, 0, 54, 48, 48, 48 , 48,
0, 19, 48, 48, 48, 48, 48, 48, 0, 0, 0, 1 , 0, 19, 48, 48, 48, 48, 48, 48, 0, 0, 0, 1 ,
0, 0, 0, 0, 0, 0, 50, 48, 48, 48, 48, 48, 0, 0, 0, 0, 0, 0, 50, 48, 48, 48, 48, 48,
48, 0, 54, 48, 48, 48, 48, 0, 19, 48, 48, 48, 0, 54, 48, 48, 48, 48, 0, 19, 48, 48,
}, },
off: 0, off: 0,
}, },
wantErr: true, wantErr: true,
wantErrMsg: "dns: nsec bits out of order", wantErrMsg: "dns: nsec bits out of order",
want: 155, wantOff: 155,
}, },
{ {
name: "simple message with only one window", name: "simple message with only one window",
args: args{ args: args{
bitmap: []uint16{ bitmap: []uint16{
0, 1,
}, },
msg: []byte{ msg: []byte{
48, 48, 48, 48, 0, 0, 48, 48, 48, 48, 0, 0,
0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 50, 48, 48, 48, 0, 0, 50, 48, 48, 48,
48, 48, 48, 0, 54, 48, 48, 48, 48, 0, 54, 48,
48, 48, 48, 0, 19, 48, 48, 48, 48, 48, 0, 19, 48, 48,
}, },
off: 0, off: 0,
}, },
wantErr: false, wantErr: false,
want: 3, wantOff: 3,
wantBytes: []byte{0, 1, 64},
},
{
name: "multiple types",
args: args{
bitmap: []uint16{
TypeNS, TypeSOA, TypeRRSIG, TypeDNSKEY, T
ypeNSEC3PARAM,
},
msg: []byte{
48, 48, 48, 48, 0, 0,
0, 1, 0, 0, 0, 0,
0, 0, 50, 48, 48, 48,
48, 48, 48, 0, 54, 48,
48, 48, 48, 0, 19, 48, 48,
},
off: 0,
},
wantErr: false,
wantOff: 9,
wantBytes: []byte{0, 7, 34, 0, 0, 0, 0, 2, 144},
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got, err := packDataNsec(tt.args.bitmap, tt.args.msg, tt. args.off) gotOff, err := packDataNsec(tt.args.bitmap, tt.args.msg, tt.args.off)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("packDataNsec() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("packDataNsec() error = %v, wantErr %v", err, tt.wantErr)
return return
} }
if err != nil && tt.wantErrMsg != err.Error() { if err != nil && tt.wantErrMsg != err.Error() {
t.Errorf("packDataNsec() error msg = %v, wantErrM sg %v", err.Error(), tt.wantErrMsg) t.Errorf("packDataNsec() error msg = %v, wantErrM sg %v", err.Error(), tt.wantErrMsg)
return return
} }
if got != tt.want { if gotOff != tt.wantOff {
t.Errorf("packDataNsec() = %v, want %v", got, tt. t.Errorf("packDataNsec() = %v, want off %v", gotO
want) ff, tt.wantOff)
}
if err == nil && tt.args.off < len(tt.args.msg) && gotOff
< len(tt.args.msg) {
if want, got := tt.wantBytes, tt.args.msg[tt.args
.off:gotOff]; !bytes.Equal(got, want) {
t.Errorf("packDataNsec() = %v, want bytes
%v", got, want)
}
} }
}) })
} }
} }
func TestPackDataNsecDirtyBuffer(t *testing.T) {
zeroBuf := []byte{0, 0, 0, 0, 0, 0, 0, 0, 0}
dirtyBuf := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}
off1, _ := packDataNsec([]uint16{TypeNS, TypeSOA, TypeRRSIG}, zeroBuf, 0)
off2, _ := packDataNsec([]uint16{TypeNS, TypeSOA, TypeRRSIG}, dirtyBuf, 0
)
if off1 != off2 {
t.Errorf("off1 %v != off2 %v", off1, off2)
}
if !bytes.Equal(zeroBuf[:off1], dirtyBuf[:off2]) {
t.Errorf("dirty buffer differs from zero buffer: %v, %v", zeroBuf
[:off1], dirtyBuf[:off2])
}
}
func BenchmarkPackDataNsec(b *testing.B) {
benches := []struct {
name string
types []uint16
}{
{"empty", nil},
{"typical", []uint16{TypeNS, TypeSOA, TypeRRSIG, TypeDNSKEY, Type
NSEC3PARAM}},
{"multiple_windows", []uint16{1, 300, 350, 10000, 20000}},
}
for _, bb := range benches {
b.Run(bb.name, func(b *testing.B) {
buf := make([]byte, 100)
for n := 0; n < b.N; n++ {
packDataNsec(bb.types, buf, 0)
}
})
}
}
func TestUnpackString(t *testing.T) { func TestUnpackString(t *testing.T) {
msg := []byte("\x00abcdef\x0f\\\"ghi\x04mmm\x7f") msg := []byte("\x00abcdef\x0f\\\"ghi\x04mmm\x7f")
msg[0] = byte(len(msg) - 1) msg[0] = byte(len(msg) - 1)
got, _, err := unpackString(msg, 0) got, _, err := unpackString(msg, 0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if want := `abcdef\015\\\"ghi\004mmm\127`; want != got { if want := `abcdef\015\\\"ghi\004mmm\127`; want != got {
 End of changes. 9 change blocks. 
11 lines changed or deleted 75 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)