Search in sources :

Example 26 with Transport

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

the class SmtpTransportTest method open_withoutXoauth2Extension_shouldThrow.

@Test
public void open_withoutXoauth2Extension_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 PLAIN LOGIN");
    server.expect("QUIT");
    server.output("221 BYE");
    SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.XOAUTH2, ConnectionSecurity.NONE);
    try {
        transport.open();
        fail("Exception expected");
    } catch (MessagingException e) {
        assertEquals("Authentication method XOAUTH2 is unavailable.", e.getMessage());
    }
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) MockSmtpServer(com.fsck.k9.mail.transport.mockServer.MockSmtpServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 27 with Transport

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

the class SmtpTransportTest method open_withAutomaticAuthAndNoTransportSecurityAndAuthPlainExtension_shouldThrow.

@Test
public void open_withAutomaticAuthAndNoTransportSecurityAndAuthPlainExtension_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 PLAIN LOGIN");
    server.expect("QUIT");
    server.output("221 BYE");
    SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.AUTOMATIC, ConnectionSecurity.NONE);
    try {
        transport.open();
        fail("Exception expected");
    } catch (MessagingException e) {
        assertEquals("Update your outgoing server authentication setting. AUTOMATIC auth. is unavailable.", e.getMessage());
    }
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) MockSmtpServer(com.fsck.k9.mail.transport.mockServer.MockSmtpServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 28 with Transport

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

the class SmtpTransportTest method open_withoutAuthLoginExtension_shouldConnectWithoutAuthentication.

@Test
public void open_withoutAuthLoginExtension_shouldConnectWithoutAuthentication() 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 OK");
    SmtpTransport transport = startServerAndCreateSmtpTransportWithoutPassword(server);
    transport.open();
    server.verifyConnectionStillOpen();
    server.verifyInteractionCompleted();
}
Also used : MockSmtpServer(com.fsck.k9.mail.transport.mockServer.MockSmtpServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 29 with Transport

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

the class SmtpTransportTest method open_withSupportWithEnhancedStatusCodesOnAuthFailure_shouldThrowEncodedMessage.

@Test
public void open_withSupportWithEnhancedStatusCodesOnAuthFailure_shouldThrowEncodedMessage() 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-ENHANCEDSTATUSCODES");
    server.output("250 AUTH XOAUTH2");
    server.expect("AUTH XOAUTH2 dXNlcj11c2VyAWF1dGg9QmVhcmVyIG9sZFRva2VuAQE=");
    server.output("334 " + XOAuth2ChallengeParserTest.STATUS_401_RESPONSE);
    server.expect("");
    server.output("535-5.7.1 Username and Password not accepted. Learn more at");
    server.output("535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 hx9sm5317360pbc.68");
    server.expect("QUIT");
    server.output("221 BYE");
    SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.XOAUTH2, ConnectionSecurity.NONE);
    try {
        transport.open();
        fail("Exception expected");
    } catch (AuthenticationFailedException e) {
        assertEquals("Username and Password not accepted. Learn more at http://support.google.com/mail/bin/answer.py?answer=14257 hx9sm5317360pbc.68", e.getMessage());
    }
    InOrder inOrder = inOrder(oAuth2TokenProvider);
    inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyInt());
    inOrder.verify(oAuth2TokenProvider).invalidateToken(USERNAME);
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : InOrder(org.mockito.InOrder) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException) MockSmtpServer(com.fsck.k9.mail.transport.mockServer.MockSmtpServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 30 with Transport

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

the class SmtpTransportTest method sendMessage_withNegativeReply_shouldThrow.

@Test
public void sendMessage_withNegativeReply_shouldThrow() throws Exception {
    Message message = getDefaultMessage();
    MockSmtpServer server = createServerAndSetupForPlainAuthentication();
    server.expect("MAIL FROM:<user@localhost>");
    server.output("250 OK");
    server.expect("RCPT TO:<user2@localhost>");
    server.output("250 OK");
    server.expect("DATA");
    server.output("354 End data with <CR><LF>.<CR><LF>");
    server.expect("[message data]");
    server.expect(".");
    server.output("421 4.7.0 Temporary system problem");
    server.expect("QUIT");
    server.output("221 BYE");
    server.closeConnection();
    SmtpTransport transport = startServerAndCreateSmtpTransport(server);
    try {
        transport.sendMessage(message);
        fail("Expected exception");
    } catch (NegativeSmtpReplyException e) {
        assertEquals(421, e.getReplyCode());
        assertEquals("4.7.0 Temporary system problem", e.getReplyText());
    }
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MockSmtpServer(com.fsck.k9.mail.transport.mockServer.MockSmtpServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)29 XOAuth2ChallengeParserTest (com.fsck.k9.mail.XOAuth2ChallengeParserTest)27 MockSmtpServer (com.fsck.k9.mail.transport.mockServer.MockSmtpServer)27 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)6 MessagingException (com.fsck.k9.mail.MessagingException)6 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)6 Message (com.fsck.k9.mail.Message)5 InOrder (org.mockito.InOrder)5 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)3 SuppressLint (android.annotation.SuppressLint)1 VisibleForTesting (android.support.annotation.VisibleForTesting)1 FetchProfile (com.fsck.k9.mail.FetchProfile)1 Transport (com.fsck.k9.mail.Transport)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 IOException (java.io.IOException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1