Search in sources :

Example 21 with MockImapServer

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

the class ImapConnectionTest method open_withStartTlsCapability_shouldIssueStartTlsCommand.

@Test
public void open_withStartTlsCapability_shouldIssueStartTlsCommand() 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 [CAPABILITY IMAP4REV1 NAMESPACE]");
    server.startTls();
    server.expect("3 CAPABILITY");
    server.output("* CAPABILITY IMAP4 IMAP4REV1 NAMESPACE");
    server.output("3 OK");
    server.expect("4 LOGIN \"" + USERNAME + "\" \"" + PASSWORD + "\"");
    server.output("4 OK LOGIN completed");
    server.expect("5 NAMESPACE");
    server.output("* NAMESPACE ((\"\" \"/\")) NIL NIL");
    server.output("5 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 22 with MockImapServer

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

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

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

the class RealImapConnectionTest method open_authXoauthWithSaslIrParsesCapabilities.

@Test
public void open_authXoauthWithSaslIrParsesCapabilities() 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("2 OK [CAPABILITY IMAP4REV1 IDLE XM-GM-EXT-1]");
    simplePostAuthenticationDialog(server, 3);
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    imapConnection.open();
    server.verifyConnectionStillOpen();
    server.verifyInteractionCompleted();
    assertTrue(imapConnection.hasCapability("XM-GM-EXT-1"));
}
Also used : MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 24 with MockImapServer

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

the class RealImapConnectionTest method open_authExternalWithoutAuthExternalCapability_shouldThrow.

@Test
public void open_authExternalWithoutAuthExternalCapability_shouldThrow() throws Exception {
    settings.setAuthType(AuthType.EXTERNAL);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "AUTH=PLAIN");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Expected exception");
    } catch (CertificateValidationException e) {
        assertEquals(Reason.MissingCapability, e.getReason());
    }
    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 25 with MockImapServer

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

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

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