Merge pull request #6360 from thundernest/fix_SmtpResponseParser_logging

Clear log buffer before reading EHLO response
This commit is contained in:
cketti 2022-10-10 15:27:32 +02:00 committed by GitHub
commit 2f1b59235d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View file

@ -33,6 +33,8 @@ internal class SmtpResponseParser(
}
fun readHelloResponse(): SmtpHelloResponse {
logBuffer.clear()
val replyCode = readReplyCode()
if (replyCode != 250) {

View file

@ -219,6 +219,30 @@ class SmtpResponseParserTest {
.isEqualTo("Ignoring EHLO keyword line: KEYWORD para${"\t"}meter")
}
@Test
fun `error in EHLO response after successfully reading greeting`() {
val input = """
220 Greeting
INVALID
""".toPeekableInputStream()
val parser = SmtpResponseParser(logger, input)
parser.readGreeting()
assertFailsWithMessage("Unexpected character: I (73)") {
parser.readHelloResponse()
}
assertThat(logger.logEntries).containsExactly(
LogEntry(
throwable = null,
message = """
SMTP response data on parser error:
I
""".trimIndent()
)
)
}
@Test
fun `positive response`() {
val input = "200 OK".toPeekableInputStream()