Skip to content

Commit

Permalink
Use AuthenticationFailedException when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
cketti committed Nov 27, 2023
1 parent 5815506 commit 122eac0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,11 @@ class RealImapConnectionTest {
}
val imapConnection = startServerAndCreateImapConnection(server, authType = AuthType.EXTERNAL)

// FIXME: improve exception message
assertFailure {
imapConnection.open()
}.isInstanceOf<CertificateValidationException>()
.message().isNotNull().contains("Bad certificate")
}.isInstanceOf<AuthenticationFailedException>()
.prop(AuthenticationFailedException::messageFromServer)
.isEqualTo("Bad certificate")

server.verifyConnectionClosed()
server.verifyInteractionCompleted()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -319,8 +318,7 @@ class Pop3ConnectionTest {

assertFailure {
createAndOpenPop3Connection(settings)
}.isInstanceOf<CertificateValidationException>()
.hasMessage("POP3 client certificate authentication failed: -ERR Invalid certificate")
}.isInstanceOf<AuthenticationFailedException>()

server.verifyInteractionCompleted()
}
Expand Down

0 comments on commit 122eac0

Please sign in to comment.