@@ -82,6 +82,27 @@ func TestGetLDAPError(t *testing.T) {
82
82
}
83
83
}
84
84
85
+ // TestGetLDAPErrorInvalidResponse tests that responses with an unexpected ordering or combination of children
86
+ // don't cause a panic.
87
+ func TestGetLDAPErrorInvalidResponse (t * testing.T ) {
88
+ bindResponse := ber .Encode (ber .ClassApplication , ber .TypeConstructed , ApplicationBindResponse , nil , "Bind Response" )
89
+ bindResponse .AppendChild (ber .NewString (ber .ClassUniversal , ber .TypePrimitive , ber .TagOctetString , "dc=example,dc=org" , "matchedDN" ))
90
+ bindResponse .AppendChild (ber .Encode (ber .ClassUniversal , ber .TypePrimitive , ber .TagInteger , int64 (LDAPResultInvalidCredentials ), "resultCode" ))
91
+ bindResponse .AppendChild (ber .Encode (ber .ClassUniversal , ber .TypePrimitive , ber .TagInteger , int64 (LDAPResultInvalidCredentials ), "resultCode" ))
92
+ packet := ber .NewSequence ("LDAPMessage" )
93
+ packet .AppendChild (ber .Encode (ber .ClassUniversal , ber .TypePrimitive , ber .TagInteger , int64 (0 ), "messageID" ))
94
+ packet .AppendChild (bindResponse )
95
+ err := GetLDAPError (packet )
96
+ if err == nil {
97
+ t .Errorf ("Did not get error response" )
98
+ }
99
+
100
+ ldapError := err .(* Error )
101
+ if ldapError .ResultCode != ErrorNetwork {
102
+ t .Errorf ("Got incorrect error code in LDAP error; got %v, expected %v" , ldapError .ResultCode , ErrorNetwork )
103
+ }
104
+ }
105
+
85
106
// TestGetLDAPErrorSuccess tests parsing of a result with no error (resultCode == 0).
86
107
func TestGetLDAPErrorSuccess (t * testing.T ) {
87
108
bindResponse := ber .Encode (ber .ClassApplication , ber .TypeConstructed , ApplicationBindResponse , nil , "Bind Response" )
0 commit comments