use of com.fsck.k9.mail.AuthenticationFailedException in project k-9 by k9mail.
the class SmtpTransport method saslAuthLogin.
// C: AUTH LOGIN
// S: 334 VXNlcm5hbWU6
// C: d2VsZG9u
// S: 334 UGFzc3dvcmQ6
// C: dzNsZDBu
// S: 235 2.0.0 OK Authenticated
//
// Lines 2-5 of the conversation contain base64-encoded information. The same conversation, with base64 strings decoded, reads:
//
//
// C: AUTH LOGIN
// S: 334 Username:
// C: weldon
// S: 334 Password:
// C: w3ld0n
// S: 235 2.0.0 OK Authenticated
private void saslAuthLogin(String username, String password) throws MessagingException, AuthenticationFailedException, IOException {
try {
executeCommand("AUTH LOGIN");
executeSensitiveCommand(Base64.encode(username));
executeSensitiveCommand(Base64.encode(password));
} catch (NegativeSmtpReplyException exception) {
if (exception.getReplyCode() == SMTP_AUTHENTICATION_FAILURE_ERROR_CODE) {
// Authentication credentials invalid
throw new AuthenticationFailedException("AUTH LOGIN failed (" + exception.getMessage() + ")");
} else {
throw exception;
}
}
}
use of com.fsck.k9.mail.AuthenticationFailedException in project k-9 by k9mail.
the class ImapConnectionTest method open_authCramMd5WithAuthenticationFailure_shouldThrow.
@Test
public void open_authCramMd5WithAuthenticationFailure_shouldThrow() throws Exception {
settings.setAuthType(AuthType.CRAM_MD5);
MockImapServer server = new MockImapServer();
preAuthenticationDialog(server, "AUTH=CRAM-MD5");
server.expect("2 AUTHENTICATE CRAM-MD5");
server.output("+ " + ByteString.encodeUtf8("<0000.000000000@example.org>").base64());
server.expect("dXNlciA2ZjdiOTcyYjk5YTI4NDk4OTRhN2YyMmE3MGRhZDg0OQ==");
server.output("2 NO Who are you?");
ImapConnection imapConnection = startServerAndCreateImapConnection(server);
try {
imapConnection.open();
fail("Expected exception");
} catch (AuthenticationFailedException e) {
//FIXME: improve exception message
assertThat(e.getMessage(), containsString("Who are you?"));
}
server.verifyConnectionClosed();
server.verifyInteractionCompleted();
}
use of com.fsck.k9.mail.AuthenticationFailedException in project k-9 by k9mail.
the class ImapConnectionTest method open_authPlainWithByeResponseAndConnectionClose_shouldThrowAuthenticationFailedException.
@Test
public void open_authPlainWithByeResponseAndConnectionClose_shouldThrowAuthenticationFailedException() throws Exception {
settings.setAuthType(AuthType.PLAIN);
MockImapServer server = new MockImapServer();
preAuthenticationDialog(server, "AUTH=PLAIN");
server.expect("2 AUTHENTICATE PLAIN");
server.output("+");
server.expect(ByteString.encodeUtf8("\000" + USERNAME + "\000" + PASSWORD).base64());
server.output("* BYE Go away");
server.output("2 NO Login Failure");
server.closeConnection();
ImapConnection imapConnection = startServerAndCreateImapConnection(server);
try {
imapConnection.open();
fail("Expected exception");
} catch (AuthenticationFailedException e) {
//FIXME: improve exception message
assertThat(e.getMessage(), containsString("Login Failure"));
}
server.verifyConnectionClosed();
server.verifyInteractionCompleted();
}
use of com.fsck.k9.mail.AuthenticationFailedException in project k-9 by k9mail.
the class ImapConnectionTest method open_authXoauthWithSaslIrThrowsExeptionOn401Response.
@Test
public void open_authXoauthWithSaslIrThrowsExeptionOn401Response() throws Exception {
settings.setAuthType(AuthType.XOAUTH2);
when(oAuth2TokenProvider.getToken("user", OAuth2TokenProvider.OAUTH2_TIMEOUT)).thenReturn("token").thenReturn("token2");
MockImapServer server = new MockImapServer();
preAuthenticationDialog(server, "SASL-IR AUTH=XOAUTH AUTH=XOAUTH2");
server.expect("2 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING);
server.output("+ " + XOAuth2ChallengeParserTest.STATUS_401_RESPONSE);
server.expect("");
server.output("2 NO SASL authentication failed");
ImapConnection imapConnection = startServerAndCreateImapConnection(server);
try {
imapConnection.open();
fail();
} catch (AuthenticationFailedException e) {
assertEquals("Command: AUTHENTICATE XOAUTH2; response: #2# [NO, SASL authentication failed]", e.getMessage());
}
}
use of com.fsck.k9.mail.AuthenticationFailedException in project k-9 by k9mail.
the class ImapConnectionTest method open_authPlainAndLoginFallbackWithAuthenticationFailure_shouldThrow.
@Test
public void open_authPlainAndLoginFallbackWithAuthenticationFailure_shouldThrow() throws Exception {
settings.setAuthType(AuthType.PLAIN);
MockImapServer server = new MockImapServer();
preAuthenticationDialog(server, "AUTH=PLAIN");
server.expect("2 AUTHENTICATE PLAIN");
server.output("+");
server.expect(ByteString.encodeUtf8("\000" + USERNAME + "\000" + PASSWORD).base64());
server.output("2 NO Login Failure");
server.expect("3 LOGIN \"" + USERNAME + "\" \"" + PASSWORD + "\"");
server.output("3 NO Go away");
ImapConnection imapConnection = startServerAndCreateImapConnection(server);
try {
imapConnection.open();
fail("Expected exception");
} catch (AuthenticationFailedException e) {
//FIXME: improve exception message
assertThat(e.getMessage(), containsString("Go away"));
}
server.verifyConnectionClosed();
server.verifyInteractionCompleted();
}
Aggregations