Search in sources :

Example 26 with MockImapServer

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

the class RealImapConnectionTest method open_withUntaggedPostAuthCapabilityResponse_shouldNotIssueCapabilityCommand.

@Test
public void open_withUntaggedPostAuthCapabilityResponse_shouldNotIssueCapabilityCommand() 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("* CAPABILITY IMAP4rev1 UNSELECT IDLE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS " + "ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS LITERAL- SPECIAL-USE " + "APPENDLIMIT=35651584");
    server.output("2 OK");
    simplePostAuthenticationDialog(server, 3);
    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)

Example 27 with MockImapServer

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

the class RealImapConnectionTest method sendContinuation.

@Test
public void sendContinuation() throws Exception {
    settings.setAuthType(AuthType.PLAIN);
    MockImapServer server = new MockImapServer();
    simpleOpenDialog(server, "IDLE");
    server.expect("4 IDLE");
    server.output("+ idling");
    server.expect("DONE");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    imapConnection.open();
    imapConnection.sendCommand("IDLE", false);
    imapConnection.readResponse();
    imapConnection.sendContinuation("DONE");
    server.waitForInteractionToComplete();
    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 28 with MockImapServer

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

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

Example 29 with MockImapServer

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

the class RealImapConnectionTest method open_authPlainFailureAndDisconnect_shouldThrow.

@Test
public void open_authPlainFailureAndDisconnect_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 [UNAVAILABLE] Maximum number of connections from user+IP exceeded");
    server.closeConnection();
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Expected exception");
    } catch (NegativeImapResponseException e) {
        assertThat(e.getMessage(), containsString("Maximum number of connections from user+IP exceeded"));
    }
    assertFalse(imapConnection.isConnected());
    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)

Example 30 with MockImapServer

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

the class RealImapConnectionTest method open_withIoExceptionDuringListCommand_shouldThrow.

@Test
public void open_withIoExceptionDuringListCommand_shouldThrow() throws Exception {
    settings.setAuthType(AuthType.PLAIN);
    MockImapServer server = new MockImapServer();
    simplePreAuthAndLoginDialog(server, "");
    server.expect("3 LIST \"\" \"\"");
    server.output("* Now what?");
    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)

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