diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt index daba1f44762..536ee578c40 100644 --- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt +++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt @@ -521,14 +521,7 @@ internal class RealImapConnection( val command = Commands.AUTHENTICATE_EXTERNAL + " " + Base64.encode(settings.username) executeSimpleCommand(command, false) } catch (e: NegativeImapResponseException) { - /* - * Provide notification to the user of a problem authenticating - * using client certificates. We don't use an - * AuthenticationFailedException because that would trigger a - * "Username or password incorrect" notification in - * AccountSetupCheckSettings. - */ - throw CertificateValidationException(e.message) + throw handleAuthenticationFailure(e) } } diff --git a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapConnectionTest.kt b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapConnectionTest.kt index 7ce7782c1f4..3ed3022c37d 100644 --- a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapConnectionTest.kt +++ b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapConnectionTest.kt @@ -520,11 +520,11 @@ class RealImapConnectionTest { } val imapConnection = startServerAndCreateImapConnection(server, authType = AuthType.EXTERNAL) - // FIXME: improve exception message assertFailure { imapConnection.open() - }.isInstanceOf() - .message().isNotNull().contains("Bad certificate") + }.isInstanceOf() + .prop(AuthenticationFailedException::messageFromServer) + .isEqualTo("Bad certificate") server.verifyConnectionClosed() server.verifyInteractionCompleted() diff --git a/mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store/pop3/Pop3Connection.java b/mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store/pop3/Pop3Connection.java index bbcca763081..b59bcdeffcd 100644 --- a/mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store/pop3/Pop3Connection.java +++ b/mail/protocols/pop3/src/main/java/com/fsck/k9/mail/store/pop3/Pop3Connection.java @@ -312,15 +312,7 @@ private void authExternal() throws MessagingException, IOException { String.format("AUTH EXTERNAL %s", Base64.encode(settings.getUsername())), false); } catch (Pop3ErrorResponse e) { - /* - * Provide notification to the user of a problem authenticating - * using client certificates. We don't use an - * AuthenticationFailedException because that would trigger a - * "Username or password incorrect" notification in - * AccountSetupCheckSettings. - */ - throw new CertificateValidationException( - "POP3 client certificate authentication failed: " + e.getMessage(), e); + throw new AuthenticationFailedException("AUTH EXTERNAL failed", e, e.getResponseText()); } } diff --git a/mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store/pop3/Pop3ConnectionTest.kt b/mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store/pop3/Pop3ConnectionTest.kt index 3a1b150197e..7f091bf1785 100644 --- a/mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store/pop3/Pop3ConnectionTest.kt +++ b/mail/protocols/pop3/src/test/java/com/fsck/k9/mail/store/pop3/Pop3ConnectionTest.kt @@ -1,7 +1,6 @@ package com.fsck.k9.mail.store.pop3 import assertk.assertFailure -import assertk.assertions.hasMessage import assertk.assertions.isEqualTo import assertk.assertions.isInstanceOf import assertk.assertions.prop @@ -319,8 +318,7 @@ class Pop3ConnectionTest { assertFailure { createAndOpenPop3Connection(settings) - }.isInstanceOf() - .hasMessage("POP3 client certificate authentication failed: -ERR Invalid certificate") + }.isInstanceOf() server.verifyInteractionCompleted() }