Search in sources :

Example 11 with AuthenticationFailedException

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;
        }
    }
}
Also used : AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException)

Example 12 with AuthenticationFailedException

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();
}
Also used : AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException) MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 13 with AuthenticationFailedException

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();
}
Also used : AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException) MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 14 with AuthenticationFailedException

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());
    }
}
Also used : AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException) MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 15 with AuthenticationFailedException

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();
}
Also used : AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException) MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Aggregations

AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)17 Test (org.junit.Test)10 XOAuth2ChallengeParserTest (com.fsck.k9.mail.XOAuth2ChallengeParserTest)9 MockImapServer (com.fsck.k9.mail.store.imap.mockserver.MockImapServer)5 MessagingException (com.fsck.k9.mail.MessagingException)4 MockSmtpServer (com.fsck.k9.mail.transport.mockServer.MockSmtpServer)4 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)3 SuppressLint (android.annotation.SuppressLint)2 VisibleForTesting (android.support.annotation.VisibleForTesting)2 LocalFolder (com.fsck.k9.mailstore.LocalFolder)2 LocalMessage (com.fsck.k9.mailstore.LocalMessage)2 LocalStore (com.fsck.k9.mailstore.LocalStore)2 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)2 IOException (java.io.IOException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 InOrder (org.mockito.InOrder)2 FetchProfile (com.fsck.k9.mail.FetchProfile)1 Folder (com.fsck.k9.mail.Folder)1 Message (com.fsck.k9.mail.Message)1 Store (com.fsck.k9.mail.Store)1