aboutsummaryrefslogtreecommitdiff
path: root/goldap/message_test.go
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2021-07-07 01:49:33 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2021-09-16 13:09:26 +0200
commit563fc272a36c8be317fbe95c8308ca2dfa29c3aa (patch)
tree0b6f9a6a15516e7234fc928ecbebbd32d3154074 /goldap/message_test.go
parentaa912b5ceb24cb8772709171ea9589b0771bbe54 (diff)
downloadbottin-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/message_test.go')
-rw-r--r--goldap/message_test.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/goldap/message_test.go b/goldap/message_test.go
new file mode 100644
index 0000000..9d10d98
--- /dev/null
+++ b/goldap/message_test.go
@@ -0,0 +1,76 @@
+package message
+
+import (
+ "testing"
+ "fmt"
+)
+
+func toHex(b []byte) (r string) {
+ r = "[ "
+ for _, e := range b {
+ r += fmt.Sprintf("0x%x ", e)
+ }
+ return r + "]"
+}
+
+func TestMessageID(t *testing.T) {
+ m := NewLDAPMessageWithProtocolOp(UnbindRequest{})
+ m.SetMessageID(128)
+ buf, err := m.Write()
+ if err != nil {
+ t.Errorf("marshalling failed with %v", err)
+ }
+ t.Logf("%v", toHex(buf.Bytes()))
+
+ ret, err := ReadLDAPMessage(NewBytes(0, buf.Bytes()))
+ if err != nil {
+ t.Errorf("unmarshalling failed with %v", err)
+ }
+ if _, ok := ret.ProtocolOp().(UnbindRequest); !ok {
+ t.Errorf("should be an unbind request")
+ }
+ if ret.MessageID() != 128 {
+ t.Errorf("Expect message id 128, got %d", ret.MessageID())
+ }
+ t.Log("Done, marshal/unmarshall worked")
+}
+
+func TestSearchEntry(t *testing.T) {
+ m := NewLDAPMessageWithProtocolOp(SearchResultEntry{
+ objectName:"cn=êige€nbgtz,ou=users,dc=deuxfleurs,dc=fr",
+ attributes: PartialAttributeList{
+ PartialAttribute{
+ type_:"displayname",
+ vals:[]AttributeValue{"êiGe€NBgTZ"},
+ },
+ PartialAttribute{
+ type_:"objectclass",
+ vals:[]AttributeValue{"inetOrgPerson"},
+ },
+ PartialAttribute{
+ type_:"objectclass",
+ vals:[]AttributeValue{"organizationalPerson"},
+ },
+ PartialAttribute{
+ type_:"objectclass",
+ vals:[]AttributeValue{"person"},
+ },
+ PartialAttribute{
+ type_:"objectclass",
+ vals:[]AttributeValue{"top"},
+ },
+ PartialAttribute{
+ type_:"structuralobjectclass",
+ vals:[]AttributeValue{"inetOrgPerson"},
+ },
+ },
+ })
+ m.SetMessageID(24)
+ buf, err := m.Write()
+ if err != nil {
+ t.Errorf("marshalling failed with %v", err)
+ }
+ if buf.Bytes()[0] != 0x30 {
+ t.Logf("Malformed message: %v", toHex(buf.Bytes()))
+ }
+}