Search in sources :

Example 16 with AuthenticationFailedException

use of com.fsck.k9.mail.AuthenticationFailedException in project k-9 by k9mail.

the class ImapConnectionTest method open_authXoauthWithSaslIrWithOldTokenThrowsExceptionIfRetryFails.

@Test
public void open_authXoauthWithSaslIrWithOldTokenThrowsExceptionIfRetryFails() 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("+ r3j3krj3irj3oir3ojo");
    server.expect("");
    server.output("2 NO SASL authentication failed");
    server.expect("3 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING_RETRY);
    server.output("+ 433ba3a3a");
    server.expect("");
    server.output("3 NO SASL authentication failed");
    simplePostAuthenticationDialog(server);
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail();
    } catch (AuthenticationFailedException e) {
        assertEquals("Command: AUTHENTICATE XOAUTH2; response: #3# [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 17 with AuthenticationFailedException

use of com.fsck.k9.mail.AuthenticationFailedException in project k-9 by k9mail.

the class SmtpTransportTest method open_withXoauth2Extension_shouldThrowOn401Response.

@Test
public void open_withXoauth2Extension_shouldThrowOn401Response() throws Exception {
    MockSmtpServer server = new MockSmtpServer();
    server.output("220 localhost Simple Mail Transfer Service Ready");
    server.expect("EHLO localhost");
    server.output("250-localhost Hello client.localhost");
    server.output("250 AUTH XOAUTH2");
    server.expect("AUTH XOAUTH2 dXNlcj11c2VyAWF1dGg9QmVhcmVyIG9sZFRva2VuAQE=");
    server.output("334 " + XOAuth2ChallengeParserTest.STATUS_401_RESPONSE);
    server.expect("");
    server.output("535-5.7.1 Username and Password not accepted. Learn more at");
    server.output("535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 hx9sm5317360pbc.68");
    server.expect("QUIT");
    server.output("221 BYE");
    SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.XOAUTH2, ConnectionSecurity.NONE);
    try {
        transport.open();
        fail("Exception expected");
    } catch (AuthenticationFailedException e) {
        assertEquals("5.7.1 Username and Password not accepted. Learn more at " + "5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 hx9sm5317360pbc.68", e.getMessage());
    }
    InOrder inOrder = inOrder(oAuth2TokenProvider);
    inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyInt());
    inOrder.verify(oAuth2TokenProvider).invalidateToken(USERNAME);
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : InOrder(org.mockito.InOrder) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException) MockSmtpServer(com.fsck.k9.mail.transport.mockServer.MockSmtpServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 18 with AuthenticationFailedException

use of com.fsck.k9.mail.AuthenticationFailedException in project k-9 by k9mail.

the class SmtpTransportTest method before.

@Before
public void before() throws AuthenticationFailedException {
    socketFactory = new TestTrustedSocketFactory();
    oAuth2TokenProvider = mock(OAuth2TokenProvider.class);
    when(oAuth2TokenProvider.getToken(eq(USERNAME), anyInt())).thenReturn("oldToken").thenReturn("newToken");
}
Also used : OAuth2TokenProvider(com.fsck.k9.mail.oauth.OAuth2TokenProvider) TestTrustedSocketFactory(com.fsck.k9.mail.helpers.TestTrustedSocketFactory) Before(org.junit.Before)

Example 19 with AuthenticationFailedException

use of com.fsck.k9.mail.AuthenticationFailedException in project k-9 by k9mail.

the class SmtpTransportTest method open_withSupportWithEnhancedStatusCodesOnAuthFailure_shouldThrowEncodedMessage.

@Test
public void open_withSupportWithEnhancedStatusCodesOnAuthFailure_shouldThrowEncodedMessage() throws Exception {
    MockSmtpServer server = new MockSmtpServer();
    server.output("220 localhost Simple Mail Transfer Service Ready");
    server.expect("EHLO localhost");
    server.output("250-localhost Hello client.localhost");
    server.output("250-ENHANCEDSTATUSCODES");
    server.output("250 AUTH XOAUTH2");
    server.expect("AUTH XOAUTH2 dXNlcj11c2VyAWF1dGg9QmVhcmVyIG9sZFRva2VuAQE=");
    server.output("334 " + XOAuth2ChallengeParserTest.STATUS_401_RESPONSE);
    server.expect("");
    server.output("535-5.7.1 Username and Password not accepted. Learn more at");
    server.output("535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 hx9sm5317360pbc.68");
    server.expect("QUIT");
    server.output("221 BYE");
    SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.XOAUTH2, ConnectionSecurity.NONE);
    try {
        transport.open();
        fail("Exception expected");
    } catch (AuthenticationFailedException e) {
        assertEquals("Username and Password not accepted. Learn more at http://support.google.com/mail/bin/answer.py?answer=14257 hx9sm5317360pbc.68", e.getMessage());
    }
    InOrder inOrder = inOrder(oAuth2TokenProvider);
    inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyInt());
    inOrder.verify(oAuth2TokenProvider).invalidateToken(USERNAME);
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : InOrder(org.mockito.InOrder) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException) MockSmtpServer(com.fsck.k9.mail.transport.mockServer.MockSmtpServer) 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