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/size_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/size_test.go')
-rw-r--r-- | goldap/size_test.go | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/goldap/size_test.go b/goldap/size_test.go new file mode 100644 index 0000000..eef6e53 --- /dev/null +++ b/goldap/size_test.go @@ -0,0 +1,85 @@ +package message + +import ( + "testing" +) + +func TestSizeLDAPMessage(t *testing.T) { + + var testData = getLDAPMessageTestData() + for i, test := range testData { + message, err := ReadLDAPMessage(&test.bytes) + if err != nil { + t.Errorf("#%d error at offset %d (%s): %s", i, test.bytes.offset, test.bytes.DumpCurrentBytes(), err) + } + size := message.size() + expected := len(test.bytes.bytes) + if size != expected { + t.Errorf("#%d: wrong size, GOT: %d, EXPECTED: %d", i, size, expected) + } + } +} + +type tagAndLengthTestData struct { + tag int + length int + expectedSize int +} + +func getSizeTagAndLengthTestData() (ret []tagAndLengthTestData) { + return []tagAndLengthTestData{ + // Length between 0 and 127 are encoded on one byte + { + tag: tagSequence, + length: 0, + expectedSize: 2, + }, + { + tag: tagSequence, + length: 127, + expectedSize: 2, + }, + // Length between 128 and 255 are encoded on two bytes + { + tag: tagSequence, + length: 128, + expectedSize: 3, + }, + { + tag: tagSequence, + length: 255, + expectedSize: 3, + }, + // Length between 256 (2^8) and 65535 (2^16-1) are encoded on three bytes + { + tag: tagSequence, + length: 256, + expectedSize: 4, + }, + { + tag: tagSequence, + length: 65535, + expectedSize: 4, + }, + // Length between 65536 (2^16) and 16777215 (2^24-1) are encoded on four bytes + { + tag: tagSequence, + length: 65536, + expectedSize: 5, + }, + { + tag: tagSequence, + length: 16777215, + expectedSize: 5, + }, + } +} +func TestSizeTagAndLength(t *testing.T) { + for i, test := range getSizeTagAndLengthTestData() { + size := sizeTagAndLength(test.tag, test.length) + if test.expectedSize != size { + t.Errorf("#%d: wrong size, GOT: %d, EXPECTED: %d", i, size, test.expectedSize) + } + } + +} |