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

Function TestKip368ReAuthenticationSuccess

broker_test.go:978–1060  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

976}
977
978func TestKip368ReAuthenticationSuccess(t *testing.T) {
979 sessionLifetimeMs := int64(100)
980
981 mockBroker := NewMockBroker(t, 0)
982
983 countSaslAuthRequests := func() (count int) {
984 for _, rr := range mockBroker.History() {
985 switch rr.Request.(type) {
986 case *SaslAuthenticateRequest:
987 count++
988 }
989 }
990 return
991 }
992
993 mockSASLAuthResponse := NewMockSaslAuthenticateResponse(t).
994 SetAuthBytes([]byte(`response_payload`)).
995 SetSessionLifetimeMs(sessionLifetimeMs)
996
997 mockSASLHandshakeResponse := NewMockSaslHandshakeResponse(t).
998 SetEnabledMechanisms([]string{SASLTypePlaintext})
999
1000 mockApiVersions := NewMockApiVersionsResponse(t)
1001
1002 mockBroker.SetHandlerByMap(map[string]MockResponse{
1003 "SaslAuthenticateRequest": mockSASLAuthResponse,
1004 "SaslHandshakeRequest": mockSASLHandshakeResponse,
1005 "ApiVersionsRequest": mockApiVersions,
1006 })
1007
1008 broker := NewBroker(mockBroker.Addr())
1009
1010 conf := NewTestConfig()
1011 conf.Net.SASL.Enable = true
1012 conf.Net.SASL.Mechanism = SASLTypePlaintext
1013 conf.Net.SASL.Version = SASLHandshakeV1
1014 conf.Net.SASL.AuthIdentity = "authid"
1015 conf.Net.SASL.User = "token"
1016 conf.Net.SASL.Password = "password"
1017
1018 broker.conf = conf
1019 broker.conf.Version = V2_2_0_0
1020
1021 err := broker.Open(conf)
1022 if err != nil {
1023 t.Fatal(err)
1024 }
1025 t.Cleanup(func() { _ = broker.Close() })
1026
1027 connected, err := broker.Connected()
1028 if err != nil || !connected {
1029 t.Fatal(err)
1030 }
1031
1032 actualSaslAuthRequests := countSaslAuthRequests()
1033 if actualSaslAuthRequests != 1 {
1034 t.Fatalf("unexpected number of SaslAuthRequests during initial authentication: %d", actualSaslAuthRequests)
1035 }

Callers

nothing calls this directly

Calls 15

HistoryMethod · 0.95
SetHandlerByMapMethod · 0.95
AddrMethod · 0.95
OpenMethod · 0.95
CloseMethod · 0.95
ConnectedMethod · 0.95
ApiVersionsMethod · 0.95
CloseMethod · 0.95
NewMockBrokerFunction · 0.85

Tested by

no test coverage detected