Search in sources :

Example 41 with MockImapServer

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

the class RealImapConnectionTest method open_authPlain.

@Test
public void open_authPlain() 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");
    postAuthenticationDialogRequestingCapabilities(server);
    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 42 with MockImapServer

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

the class RealImapConnectionTest method open_withNoCapabilitiesInInitialResponse_shouldIssuePreAuthCapabilitiesCommand.

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

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

the class RealImapConnectionTest method open_withPostAuthCapabilityResponse_shouldNotIssueCapabilityCommand.

@Test
public void open_withPostAuthCapabilityResponse_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("2 OK [CAPABILITY IDLE]");
    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 44 with MockImapServer

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

the class RealImapConnectionTest method open_withNegativeResponseToCompressionCommand_shouldContinue.

@Test
public void open_withNegativeResponseToCompressionCommand_shouldContinue() throws Exception {
    settings.setAuthType(AuthType.PLAIN);
    settings.setUseCompression(true);
    MockImapServer server = new MockImapServer();
    simplePreAuthAndLoginDialog(server, "COMPRESS=DEFLATE");
    server.expect("3 COMPRESS DEFLATE");
    server.output("3 NO");
    simplePostAuthenticationDialog(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 45 with MockImapServer

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

the class RealImapConnectionTest method open_withNegativeResponseToStartTlsCommand_shouldThrow.

@Test
public void open_withNegativeResponseToStartTlsCommand_shouldThrow() throws Exception {
    settings.setAuthType(AuthType.PLAIN);
    settings.setConnectionSecurity(ConnectionSecurity.STARTTLS_REQUIRED);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "STARTTLS");
    server.expect("2 STARTTLS");
    server.output("2 NO");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Expected exception");
    } catch (NegativeImapResponseException e) {
        assertEquals(e.getMessage(), "Command: STARTTLS; response: #2# [NO]");
    }
    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)

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