Search in sources :

Example 66 with MockImapServer

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

the class RealImapConnectionTest method open_withNamespaceCapability_shouldIssueNamespaceCommand.

@Test
public void open_withNamespaceCapability_shouldIssueNamespaceCommand() throws Exception {
    MockImapServer server = new MockImapServer();
    simplePreAuthAndLoginDialog(server, "NAMESPACE");
    server.expect("3 NAMESPACE");
    server.output("* NAMESPACE ((\"\" \"/\")) NIL NIL");
    server.output("3 OK command completed");
    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 67 with MockImapServer

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

the class RealImapConnectionTest method open_withStartTlsButWithoutStartTlsCapability_shouldThrow.

@Test
public void open_withStartTlsButWithoutStartTlsCapability_shouldThrow() throws Exception {
    settings.setConnectionSecurity(ConnectionSecurity.STARTTLS_REQUIRED);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server);
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Expected exception");
    } catch (CertificateValidationException e) {
        // FIXME: CertificateValidationException seems wrong
        assertEquals("STARTTLS connection security not available", e.getMessage());
    }
    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 68 with MockImapServer

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

the class RealImapConnectionTest method open_authXoauthWithSaslIrInvalidatesAndRetriesNewTokenOn400Response.

@Test
public void open_authXoauthWithSaslIrInvalidatesAndRetriesNewTokenOn400Response() 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("+ " + XOAuth2ChallengeParserTest.STATUS_400_RESPONSE);
    server.expect("");
    server.output("2 NO SASL authentication failed");
    server.expect("3 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING_RETRY);
    server.output("3 OK Success");
    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 69 with MockImapServer

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

the class RealImapConnectionTest method open_withUntaggedCapabilityAfterStartTls_shouldNotThrow.

@Test
public void open_withUntaggedCapabilityAfterStartTls_shouldNotThrow() throws Exception {
    settings.setAuthType(AuthType.PLAIN);
    settings.setConnectionSecurity(ConnectionSecurity.STARTTLS_REQUIRED);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "STARTTLS LOGINDISABLED");
    server.expect("2 STARTTLS");
    server.output("2 OK Begin TLS negotiation now");
    server.startTls();
    server.output("* CAPABILITY IMAP4REV1 IMAP4");
    server.expect("3 CAPABILITY");
    server.output("* CAPABILITY IMAP4 IMAP4REV1");
    server.output("3 OK");
    server.expect("4 LOGIN \"" + USERNAME + "\" \"" + PASSWORD + "\"");
    server.output("4 OK [CAPABILITY IMAP4REV1] LOGIN completed");
    simplePostAuthenticationDialog(server, 5);
    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 70 with MockImapServer

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

the class RealImapConnectionTest method executeSingleCommand_withNoResponse_shouldThrowNegativeImapResponseException.

@Test
public void executeSingleCommand_withNoResponse_shouldThrowNegativeImapResponseException() throws Exception {
    MockImapServer server = new MockImapServer();
    simpleOpenDialog(server, "");
    server.expect("4 CREATE Folder");
    server.output("4 NO Folder exists");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.executeSimpleCommand("CREATE Folder");
        fail("Expected exception");
    } catch (NegativeImapResponseException e) {
        assertEquals("Folder exists", e.getLastResponse().getString(1));
    }
    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