diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2021-07-07 01:49:33 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2021-09-16 13:09:26 +0200 |
commit | 563fc272a36c8be317fbe95c8308ca2dfa29c3aa (patch) | |
tree | 0b6f9a6a15516e7234fc928ecbebbd32d3154074 /goldap/asn1_test.go | |
parent | aa912b5ceb24cb8772709171ea9589b0771bbe54 (diff) | |
download | bottin-563fc272a36c8be317fbe95c8308ca2dfa29c3aa.tar.gz bottin-563fc272a36c8be317fbe95c8308ca2dfa29c3aa.zip |
Vendor goldap, fix ASN.1 BER integer and length encoding
- Add tests for goldap to prevent regressions
- Disable reconnection for our functional tests
Diffstat (limited to 'goldap/asn1_test.go')
-rw-r--r-- | goldap/asn1_test.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/goldap/asn1_test.go b/goldap/asn1_test.go new file mode 100644 index 0000000..eb11d29 --- /dev/null +++ b/goldap/asn1_test.go @@ -0,0 +1,54 @@ +package message + +import ( + "testing" + "bytes" +) + +func TestSizeInt64(t *testing.T) { + s := sizeInt64(0) + if s != 1 { + t.Errorf("computed size is %d, expected 1", s) + } + + s = sizeInt64(127) + if s != 1 { + t.Errorf("computed size is %d, expected 1", s) + } + + s = sizeInt64(128) + if s != 2 { + t.Errorf("computed size is %d, expected 2", s) + } + + s = sizeInt64(50000) + if s != 3 { + t.Errorf("computed size is %d, expected 3", s) + } + + s = sizeInt64(-12345) + if s != 2 { + t.Errorf("computed size is %d, expected 2", s) + } +} + +func TestWriteInt64(t *testing.T) { + vtests := []int64{0, 127, 128, 50000, -12345} + expsize := []int{1, 1, 2, 3, 2} + expresult := [][]byte{{0x00}, {0x7F}, {0x00, 0x80}, {0x00, 0xc3, 0x50}, {0xcf, 0xc7}} + + for idx, v := range vtests { + fs := sizeInt64(v) + b := NewBytes(fs, make([]byte, fs)) + t.Log("computing", v) + s := writeInt64(b, v) + if s != expsize[idx] { + t.Errorf("computed size is %d, expected %d", s, expsize[idx]) + } + if !bytes.Equal(b.Bytes(), expresult[idx]) { + t.Errorf("wrong computed bytes, got %v, expected %v", b.Bytes(), expresult[idx]) + } + a, e := parseInt64(b.Bytes()) + t.Log("parse", a, e) + } +} |