Search in sources :

Example 31 with MockImapServer

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

the class RealImapConnectionTest method open_withCapabilitiesInInitialResponse_shouldNotIssuePreAuthCapabilitiesCommand.

@Test
public void open_withCapabilitiesInInitialResponse_shouldNotIssuePreAuthCapabilitiesCommand() throws Exception {
    settings.setAuthType(AuthType.PLAIN);
    MockImapServer server = new MockImapServer();
    server.output("* OK [CAPABILITY IMAP4 IMAP4REV1 AUTH=PLAIN]");
    server.expect("1 AUTHENTICATE PLAIN");
    server.output("+");
    server.expect(ByteString.encodeUtf8("\000" + USERNAME + "\000" + PASSWORD).base64());
    server.output("1 OK Success");
    postAuthenticationDialogRequestingCapabilities(server, 2);
    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 32 with MockImapServer

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

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

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

the class RealImapConnectionTest method open_authPlainWithLoginDisabled_shouldThrow.

@Test
public void open_authPlainWithLoginDisabled_shouldThrow() throws Exception {
    settings.setAuthType(AuthType.PLAIN);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "LOGINDISABLED");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Expected exception");
    } catch (MessagingException e) {
        assertEquals("Server doesn't support unencrypted passwords using AUTH=PLAIN and LOGIN is disabled.", e.getMessage());
    }
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 34 with MockImapServer

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

the class RealImapConnectionTest 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)

Example 35 with MockImapServer

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

the class RealImapConnectionTest method open_withNoPostAuthCapabilityResponse_shouldIssueCapabilityCommand.

@Test
public void open_withNoPostAuthCapabilityResponse_shouldIssueCapabilityCommand() 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 OK Success");
    server.expect("3 CAPABILITY");
    server.output("* CAPABILITY IDLE");
    server.output("3 OK CAPABILITY Completed");
    simplePostAuthenticationDialog(server, 4);
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    imapConnection.open();
    server.verifyConnectionStillOpen();
    server.verifyInteractionCompleted();
    assertTrue(imapConnection.isIdleCapable());
}
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