-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
attempt to detect improper TLS config
when an io.ErrUnexpectedEOF is returned when reading a correlation ID, attempt to detect if the messages from the broker was a TLS Alert Message and decorate the returned error
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package protocol | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"io" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestReadResponseUnexpectedTLSDetection(t *testing.T) { | ||
var buf bytes.Buffer | ||
|
||
buf.Write([]byte{tlsAlertByte, 0x03, 0x03, 10, 0, 0, 0}) | ||
|
||
correlationID, _, err := ReadResponse(&buf, ApiVersions, 0) | ||
if !errors.Is(err, io.ErrUnexpectedEOF) { | ||
t.Fatalf("expected an io.ErrUnexpectedEOF from ReadResponse got %v", err) | ||
} | ||
|
||
if !strings.Contains(err.Error(), "broker appears to be expecting TLS") { | ||
t.Fatalf("expected error messae to contain %s got %s", "broker appears to be expecting TLS", err.Error()) | ||
} | ||
|
||
if correlationID != 0 { | ||
t.Fatalf("expected correlationID of 0 got %d", correlationID) | ||
} | ||
} |