Search in sources :

Example 76 with MockImapServer

use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer in project k-9 by k9mail.

the class RealImapConnectionTest method close_afterOpen_shouldCloseConnection.

@Test
public void close_afterOpen_shouldCloseConnection() throws Exception {
    MockImapServer server = new MockImapServer();
    ImapConnection imapConnection = simpleOpen(server);
    imapConnection.close();
    server.verifyConnectionClosed();
    server.shutdown();
}
Also used : MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 77 with MockImapServer

use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer in project k-9 by k9mail.

the class RealImapConnectionTest method open_authPlainWithAuthenticationFailure_shouldFallbackToLogin.

@Test
public void open_authPlainWithAuthenticationFailure_shouldFallbackToLogin() 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 OK LOGIN completed");
    postAuthenticationDialogRequestingCapabilities(server, 4);
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    imapConnection.open();
    server.verifyConnectionStillOpen();
    server.verifyInteractionCompleted();
}
Also used : MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 78 with MockImapServer

use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer in project k-9 by k9mail.

the class RealImapConnectionTest method open_authXoauthWithSaslIr.

@Test
public void open_authXoauthWithSaslIr() throws Exception {
    settings.setAuthType(AuthType.XOAUTH2);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "SASL-IR AUTH=XOAUTH AUTH=XOAUTH2");
    server.expect("2 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING);
    server.output("2 OK Success");
    postAuthenticationDialogRequestingCapabilities(server);
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    imapConnection.open();
    server.verifyConnectionStillOpen();
    server.verifyInteractionCompleted();
}
Also used : MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 79 with MockImapServer

use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer in project k-9 by k9mail.

the class RealImapConnectionTest method open_authXoauthWithSaslIrWithOldTokenThrowsExceptionIfRetryFails.

@Test
public void open_authXoauthWithSaslIrWithOldTokenThrowsExceptionIfRetryFails() throws Exception {
    settings.setAuthType(AuthType.XOAUTH2);
    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");
    postAuthenticationDialogRequestingCapabilities(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 80 with MockImapServer

use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer in project k-9 by k9mail.

the class RealImapConnectionTest method open_withCompressDeflateCapability_shouldEnableCompression.

@Test
public void open_withCompressDeflateCapability_shouldEnableCompression() throws Exception {
    settings.setUseCompression(true);
    MockImapServer server = new MockImapServer();
    simplePreAuthAndLoginDialog(server, "COMPRESS=DEFLATE");
    server.expect("3 COMPRESS DEFLATE");
    server.output("3 OK");
    server.enableCompression();
    simplePostAuthenticationDialog(server, 4);
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    imapConnection.open();
    server.verifyConnectionStillOpen();
    server.verifyInteractionCompleted();
}
Also used : MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Aggregations

XOAuth2ChallengeParserTest (com.fsck.k9.mail.XOAuth2ChallengeParserTest)81 MockImapServer (com.fsck.k9.mail.store.imap.mockserver.MockImapServer)81 Test (org.junit.Test)81 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)10 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)6 MessagingException (com.fsck.k9.mail.MessagingException)4 IOException (java.io.IOException)4 InOrder (org.mockito.InOrder)3