(t *testing.T)
| 636 | } |
| 637 | |
| 638 | func TestSASLPlainAuth(t *testing.T) { |
| 639 | testTable := []struct { |
| 640 | name string |
| 641 | authidentity string |
| 642 | mockAuthErr KError // Mock and expect error returned from SaslAuthenticateRequest |
| 643 | mockHandshakeErr KError // Mock and expect error returned from SaslHandshakeRequest |
| 644 | expectClientErr bool // Expect an internal client-side error |
| 645 | }{ |
| 646 | { |
| 647 | name: "SASL Plain OK server response", |
| 648 | mockAuthErr: ErrNoError, |
| 649 | mockHandshakeErr: ErrNoError, |
| 650 | }, |
| 651 | { |
| 652 | name: "SASL Plain OK server response with authidentity", |
| 653 | authidentity: "authid", |
| 654 | mockAuthErr: ErrNoError, |
| 655 | mockHandshakeErr: ErrNoError, |
| 656 | }, |
| 657 | { |
| 658 | name: "SASL Plain authentication failure response", |
| 659 | mockAuthErr: ErrSASLAuthenticationFailed, |
| 660 | mockHandshakeErr: ErrNoError, |
| 661 | }, |
| 662 | { |
| 663 | name: "SASL Plain handshake failure response", |
| 664 | mockAuthErr: ErrNoError, |
| 665 | mockHandshakeErr: ErrSASLAuthenticationFailed, |
| 666 | }, |
| 667 | } |
| 668 | |
| 669 | for i, test := range testTable { |
| 670 | t.Run(test.name, func(t *testing.T) { |
| 671 | // mockBroker mocks underlying network logic and broker responses |
| 672 | mockBroker := NewMockBroker(t, 0) |
| 673 | |
| 674 | mockSASLAuthResponse := NewMockSaslAuthenticateResponse(t). |
| 675 | SetAuthBytes([]byte(`response_payload`)) |
| 676 | |
| 677 | if !errors.Is(test.mockAuthErr, ErrNoError) { |
| 678 | mockSASLAuthResponse = mockSASLAuthResponse.SetError(test.mockAuthErr) |
| 679 | } |
| 680 | |
| 681 | mockSASLHandshakeResponse := NewMockSaslHandshakeResponse(t). |
| 682 | SetEnabledMechanisms([]string{SASLTypePlaintext}) |
| 683 | |
| 684 | if !errors.Is(test.mockHandshakeErr, ErrNoError) { |
| 685 | mockSASLHandshakeResponse = mockSASLHandshakeResponse.SetError(test.mockHandshakeErr) |
| 686 | } |
| 687 | |
| 688 | mockBroker.SetHandlerByMap(map[string]MockResponse{ |
| 689 | "SaslAuthenticateRequest": mockSASLAuthResponse, |
| 690 | "SaslHandshakeRequest": mockSASLHandshakeResponse, |
| 691 | }) |
| 692 | |
| 693 | // broker executes SASL requests against mockBroker |
| 694 | broker := NewBroker(mockBroker.Addr()) |
| 695 | broker.requestRate = metrics.NilMeter{} |
nothing calls this directly
no test coverage detected