Search in sources :

Example 6 with CertificateValidationException

use of com.fsck.k9.mail.CertificateValidationException in project k-9 by k9mail.

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

use of com.fsck.k9.mail.CertificateValidationException in project k-9 by k9mail.

the class ImapConnectionTest method open_authExternalWithAuthenticationFailure_shouldThrow.

@Test
public void open_authExternalWithAuthenticationFailure_shouldThrow() throws Exception {
    settings.setAuthType(AuthType.EXTERNAL);
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "AUTH=EXTERNAL");
    server.expect("2 AUTHENTICATE EXTERNAL " + ByteString.encodeUtf8(USERNAME).base64());
    server.output("2 NO Bad certificate");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail("Expected exception");
    } catch (CertificateValidationException e) {
        //FIXME: improve exception message
        assertThat(e.getMessage(), containsString("Bad certificate"));
    }
    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 8 with CertificateValidationException

use of com.fsck.k9.mail.CertificateValidationException in project k-9 by k9mail.

the class SmtpTransportTest method open_withoutAuthExternalExtension_shouldThrow.

@Test
public void open_withoutAuthExternalExtension_shouldThrow() throws Exception {
    MockSmtpServer server = new MockSmtpServer();
    server.output("220 localhost Simple Mail Transfer Service Ready");
    server.expect("EHLO localhost");
    server.output("250-localhost Hello client.localhost");
    server.output("250 AUTH");
    server.expect("QUIT");
    server.output("221 BYE");
    SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.EXTERNAL, ConnectionSecurity.NONE);
    try {
        transport.open();
        fail("Exception expected");
    } catch (CertificateValidationException e) {
        assertEquals(CertificateValidationException.Reason.MissingCapability, e.getReason());
    }
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : MockSmtpServer(com.fsck.k9.mail.transport.mockServer.MockSmtpServer) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 9 with CertificateValidationException

use of com.fsck.k9.mail.CertificateValidationException in project k-9 by k9mail.

the class MessagingControllerTest method sendPendingMessagesSynchronous_withCertificateFailure_shouldNotify.

@Test
public void sendPendingMessagesSynchronous_withCertificateFailure_shouldNotify() throws MessagingException {
    setupAccountWithMessageToSend();
    doThrow(new CertificateValidationException("Test")).when(transport).sendMessage(localMessageToSend1);
    controller.sendPendingMessagesSynchronous(account);
    verify(notificationController).showCertificateErrorNotification(account, false);
}
Also used : CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) Test(org.junit.Test)

Example 10 with CertificateValidationException

use of com.fsck.k9.mail.CertificateValidationException in project k-9 by k9mail.

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

Aggregations

CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)10 Test (org.junit.Test)5 XOAuth2ChallengeParserTest (com.fsck.k9.mail.XOAuth2ChallengeParserTest)4 MessagingException (com.fsck.k9.mail.MessagingException)3 MockImapServer (com.fsck.k9.mail.store.imap.mockserver.MockImapServer)3 IOException (java.io.IOException)3 SSLException (javax.net.ssl.SSLException)2 SuppressLint (android.annotation.SuppressLint)1 VisibleForTesting (android.support.annotation.VisibleForTesting)1 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)1 FetchProfile (com.fsck.k9.mail.FetchProfile)1 Transport (com.fsck.k9.mail.Transport)1 PeekableInputStream (com.fsck.k9.mail.filter.PeekableInputStream)1 MockSmtpServer (com.fsck.k9.mail.transport.mockServer.MockSmtpServer)1 LocalFolder (com.fsck.k9.mailstore.LocalFolder)1 LocalMessage (com.fsck.k9.mailstore.LocalMessage)1 LocalStore (com.fsck.k9.mailstore.LocalStore)1 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1