Search in sources :

Example 36 with MockImapServer

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

the class RealImapConnectionTest method open_authCramMd5.

@Test
public void open_authCramMd5() 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 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 37 with MockImapServer

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

the class RealImapConnectionTest method open_authXoauthWithSaslIrInvalidatesAndRetriesNewTokenOnMissingStatusJsonResponse.

@Test
public void open_authXoauthWithSaslIrInvalidatesAndRetriesNewTokenOnMissingStatusJsonResponse() 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.MISSING_STATUS_RESPONSE);
    server.expect("");
    server.output("2 NO SASL authentication failed");
    server.expect("3 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING_RETRY);
    server.output("3 OK Success");
    requestCapabilities(server, 4);
    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 38 with MockImapServer

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

the class RealImapConnectionTest method open_authCramMd5WithoutAuthCramMd5Capability_shouldThrow.

@Test
public void open_authCramMd5WithoutAuthCramMd5Capability_shouldThrow() throws Exception {
    settings.setAuthType(AuthType.CRAM_MD5);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "AUTH=PLAIN");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Expected exception");
    } catch (MessagingException e) {
        assertEquals("Server doesn't support encrypted passwords using CRAM-MD5.", 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 39 with MockImapServer

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

the class RealImapConnectionTest 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");
    server.output("3 OK");
    server.expect("4 LOGIN \"" + USERNAME + "\" \"" + PASSWORD + "\"");
    server.output("4 OK [CAPABILITY NAMESPACE] 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 40 with MockImapServer

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

the class RealImapConnectionTest method open_authXoauthWithSaslIrThrowsExeptionOn401Response.

@Test
public void open_authXoauthWithSaslIrThrowsExeptionOn401Response() 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_401_RESPONSE);
    server.expect("");
    server.output("2 NO SASL authentication failed");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail();
    } catch (AuthenticationFailedException e) {
        assertEquals("Command: AUTHENTICATE XOAUTH2; response: #2# [NO, SASL authentication failed]", e.getMessage());
    }
}
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