func TestGetLDAPError(t *testing.T) {
	diagnosticMessage := "Detailed error message"
	bindResponse := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationBindResponse, nil, "Bind Response")
	bindResponse.AppendChild(ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, int64(LDAPResultInvalidCredentials), "resultCode"))
	bindResponse.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, "dc=example,dc=org", "matchedDN"))
	bindResponse.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, diagnosticMessage, "diagnosticMessage"))
	packet := ber.NewSequence("LDAPMessage")
	packet.AppendChild(ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, int64(0), "messageID"))
	packet.AppendChild(bindResponse)
	err := GetLDAPError(packet)
	if err == nil {
		t.Errorf("Did not get error response")
	}

	ldapError := err.(*Error)
	if ldapError.ResultCode != LDAPResultInvalidCredentials {
		t.Errorf("Got incorrect error code in LDAP error; got %v, expected %v", ldapError.ResultCode, LDAPResultInvalidCredentials)
	}
	if ldapError.Err.Error() != diagnosticMessage {
		t.Errorf("Got incorrect error message in LDAP error; got %v, expected %v", ldapError.Err.Error(), diagnosticMessage)
	}
}
// TestGetLDAPError tests parsing of result with a error response.
TestGetLDAPError tests parsing of result with a error response.
// TestGetLDAPError tests parsing of result with a error response .
func TestGetLDAPError(t *testing.T) {
	diagnosticMessage := "Detailed error message"
	bindResponse := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationBindResponse, nil, "Bind Response")
	bindResponse.AppendChild(ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, int64(LDAPResultInvalidCredentials), "resultCode"))
	bindResponse.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, "dc=example,dc=org", "matchedDN"))
	bindResponse.AppendChild(ber.NewString(ber.ClassUniversal, ber.TypePrimitive, ber.TagOctetString, diagnosticMessage, "diagnosticMessage"))
	packet := ber.NewSequence("LDAPMessage")
	packet.AppendChild(ber.Encode(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, int64(0), "messageID"))
	packet.AppendChild(bindResponse)
	err := GetLDAPError(packet)
	if err == nil {
		t.Errorf("Did not get error response")
	}
	ldapError := err.(*Error)
	if ldapError.ResultCode != LDAPResultInvalidCredentials {
		t.Errorf("Got incorrect error code in LDAP error; got %v, expected %v", ldapError.ResultCode, LDAPResultInvalidCredentials)
	}
	if ldapError.Err.Error() != diagnosticMessage {
		t.Errorf("Got incorrect error message in LDAP error; got %v, expected %v", ldapError.Err.Error(), diagnosticMessage)
	}
}
func TestGetLDAPError ( t * testing . T ) { diagnosticMessage := " " bindResponse := ber . Encode ( ber . ClassApplication , ber . TypeConstructed , ApplicationBindResponse , nil , " " ) bindResponse . AppendChild ( ber . Encode ( ber . ClassUniversal , ber . TypePrimitive , ber . TagInteger , int64 ( LDAPResultInvalidCredentials ) , " " ) ) bindResponse . AppendChild ( ber . NewString ( ber . ClassUniversal , ber . TypePrimitive , ber . TagOctetString , " " , " " ) ) bindResponse . AppendChild ( ber . NewString ( ber . ClassUniversal , ber . TypePrimitive , ber . TagOctetString , diagnosticMessage , " " ) ) packet := ber . NewSequence ( " " ) packet . AppendChild ( ber . Encode ( ber . ClassUniversal , ber . TypePrimitive , ber . TagInteger , int64 ( 0 ) , " " ) ) packet . AppendChild ( bindResponse ) err := GetLDAPError ( packet ) if err == nil { t . Errorf ( " " ) } ldapError := err . ( * Error ) if ldapError . ResultCode != LDAPResultInvalidCredentials { t . Errorf ( " " , ldapError . ResultCode , LDAPResultInvalidCredentials ) } if ldapError . Err . Error ( ) != diagnosticMessage { t . Errorf ( " " , ldapError . Err . Error ( ) , diagnosticMessage ) } }
TestGetLDAPError tests parsing of result with a error response.
TestGetLDAPError tests parsing of result with a error response .