Search in sources :

Example 46 with MockImapServer

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

the class RealImapConnectionTest method isIdleCapable_withIdleCapability.

@Test
public void isIdleCapable_withIdleCapability() throws Exception {
    MockImapServer server = new MockImapServer();
    ImapConnection imapConnection = simpleOpenWithCapabilities(server, "IDLE");
    boolean result = imapConnection.isIdleCapable();
    assertTrue(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 47 with MockImapServer

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

the class RealImapConnectionTest 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 48 with MockImapServer

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

the class RealImapConnectionTest method isConnected_afterOpen_shouldReturnTrue.

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

Example 49 with MockImapServer

use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer 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 50 with MockImapServer

use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer 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)

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