From 38ee83e45b4de7edf89bf9f0ef629eb4c6ad0fa8 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Thu, 12 May 2016 23:56:07 -0400 Subject: Moving to glide --- vendor/github.com/go-ldap/ldap/conn_test.go | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 vendor/github.com/go-ldap/ldap/conn_test.go (limited to 'vendor/github.com/go-ldap/ldap/conn_test.go') diff --git a/vendor/github.com/go-ldap/ldap/conn_test.go b/vendor/github.com/go-ldap/ldap/conn_test.go new file mode 100644 index 000000000..8394e5339 --- /dev/null +++ b/vendor/github.com/go-ldap/ldap/conn_test.go @@ -0,0 +1,53 @@ +package ldap + +import ( + "net" + "net/http" + "net/http/httptest" + "testing" + "time" + + "gopkg.in/asn1-ber.v1" +) + +func TestUnresponsiveConnection(t *testing.T) { + // The do-nothing server that accepts requests and does nothing + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + })) + defer ts.Close() + c, err := net.Dial(ts.Listener.Addr().Network(), ts.Listener.Addr().String()) + if err != nil { + t.Fatalf("error connecting to localhost tcp: %v", err) + } + + // Create an Ldap connection + conn := NewConn(c, false) + conn.SetTimeout(time.Millisecond) + conn.Start() + defer conn.Close() + + // Mock a packet + messageID := conn.nextMessageID() + packet := ber.Encode(ber.ClassUniversal, ber.TypeConstructed, ber.TagSequence, nil, "LDAP Request") + packet.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, messageID, "MessageID")) + bindRequest := ber.Encode(ber.ClassApplication, ber.TypeConstructed, ApplicationBindRequest, nil, "Bind Request") + bindRequest.AppendChild(ber.NewInteger(ber.ClassUniversal, ber.TypePrimitive, ber.TagInteger, 3, "Version")) + packet.AppendChild(bindRequest) + + // Send packet and test response + channel, err := conn.sendMessage(packet) + if err != nil { + t.Fatalf("error sending message: %v", err) + } + packetResponse, ok := <-channel + if !ok { + t.Fatalf("no PacketResponse in response channel") + } + packet, err = packetResponse.ReadPacket() + if err == nil { + t.Fatalf("expected timeout error") + } + if err.Error() != "ldap: connection timed out" { + t.Fatalf("unexpected error: %v", err) + } +} -- cgit v1.2.3-1-g7c22