Search in sources :

Example 16 with MockImapServer

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

the class ImapConnectionTest method open_withIoExceptionDuringCompressionCommand_shouldThrow.

@Test
public void open_withIoExceptionDuringCompressionCommand_shouldThrow() throws Exception {
    settings.setAuthType(AuthType.PLAIN);
    settings.setUseCompression(true);
    MockImapServer server = new MockImapServer();
    simplePreAuthAndLoginDialog(server, "COMPRESS=DEFLATE");
    server.expect("3 COMPRESS DEFLATE");
    server.closeConnection();
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Exception expected");
    } catch (IOException ignored) {
    }
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) IOException(java.io.IOException) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 17 with MockImapServer

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

the class ImapConnectionTest method isIdleCapable_withoutIdleCapability.

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

Example 18 with MockImapServer

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

the class ImapConnectionTest method open_authExternalWithAuthenticationFailure_shouldThrow.

@Test
public void open_authExternalWithAuthenticationFailure_shouldThrow() throws Exception {
    settings.setAuthType(AuthType.EXTERNAL);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "AUTH=EXTERNAL");
    server.expect("2 AUTHENTICATE EXTERNAL " + ByteString.encodeUtf8(USERNAME).base64());
    server.output("2 NO Bad certificate");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Expected exception");
    } catch (CertificateValidationException e) {
        //FIXME: improve exception message
        assertThat(e.getMessage(), containsString("Bad certificate"));
    }
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 19 with MockImapServer

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

the class ImapConnectionTest 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 20 with MockImapServer

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

the class ImapConnectionTest method open_withNegativeResponseToStartTlsCommand_shouldThrow.

@Test
public void open_withNegativeResponseToStartTlsCommand_shouldThrow() throws Exception {
    settings.setAuthType(AuthType.PLAIN);
    settings.setConnectionSecurity(ConnectionSecurity.STARTTLS_REQUIRED);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "STARTTLS");
    server.expect("2 STARTTLS");
    server.output("2 NO");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Expected exception");
    } catch (NegativeImapResponseException e) {
        assertEquals(e.getMessage(), "Command: STARTTLS; response: #2# [NO]");
    }
    server.verifyConnectionClosed();
    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