MCPcopy
hub / github.com/IBM/sarama / TestSASLReadTimeout

Function TestSASLReadTimeout

broker_test.go:760–806  ·  view source on GitHub ↗

TestSASLReadTimeout ensures that the broker connection won't block forever if the remote end never responds after the handshake

(t *testing.T)

Source from the content-addressed store, hash-verified

758// TestSASLReadTimeout ensures that the broker connection won't block forever
759// if the remote end never responds after the handshake
760func TestSASLReadTimeout(t *testing.T) {
761 mockBroker := NewMockBroker(t, 0)
762 defer mockBroker.Close()
763
764 mockSASLAuthResponse := NewMockSaslAuthenticateResponse(t).
765 SetAuthBytes([]byte(`response_payload`))
766
767 mockBroker.SetHandlerByMap(map[string]MockResponse{
768 "SaslAuthenticateRequest": mockSASLAuthResponse,
769 })
770
771 broker := NewBroker(mockBroker.Addr())
772 {
773 broker.requestRate = metrics.NilMeter{}
774 broker.outgoingByteRate = metrics.NilMeter{}
775 broker.incomingByteRate = metrics.NilMeter{}
776 broker.requestSize = metrics.NilHistogram{}
777 broker.responseSize = metrics.NilHistogram{}
778 broker.responseRate = metrics.NilMeter{}
779 broker.requestLatency = metrics.NilHistogram{}
780 broker.requestsInFlight = metrics.NilCounter{}
781 }
782
783 conf := NewTestConfig()
784 {
785 conf.Net.ReadTimeout = time.Millisecond
786 conf.Net.SASL.Mechanism = SASLTypePlaintext
787 conf.Net.SASL.User = "token"
788 conf.Net.SASL.Password = "password"
789 conf.Net.SASL.Version = SASLHandshakeV1
790 conf.Net.SASL.Enable = true
791 conf.Version = V1_0_0_0
792 }
793
794 err := broker.Open(conf)
795 if err != nil {
796 t.Fatal(err)
797 }
798 t.Cleanup(func() { _ = broker.Close() })
799
800 _, err = broker.Connected()
801
802 var nerr net.Error
803 if !(errors.As(err, &nerr) && nerr.Timeout()) {
804 t.Errorf("should never happen - expected read timeout got: %v", err)
805 }
806}
807
808func TestGSSAPIKerberosAuth_Authorize(t *testing.T) {
809 testTable := []struct {

Callers

nothing calls this directly

Calls 14

CloseMethod · 0.95
SetHandlerByMapMethod · 0.95
AddrMethod · 0.95
OpenMethod · 0.95
CloseMethod · 0.95
ConnectedMethod · 0.95
NewMockBrokerFunction · 0.85
NewBrokerFunction · 0.85
SetAuthBytesMethod · 0.80
FatalMethod · 0.80
NewTestConfigFunction · 0.70

Tested by

no test coverage detected