Search in sources :

Example 31 with MockSmtpServer

use of com.fsck.k9.mail.transport.mockServer.MockSmtpServer 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 [127.0.0.1]");
    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 32 with MockSmtpServer

use of com.fsck.k9.mail.transport.mockServer.MockSmtpServer 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 [127.0.0.1]");
    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 33 with MockSmtpServer

use of com.fsck.k9.mail.transport.mockServer.MockSmtpServer in project k-9 by k9mail.

the class SmtpTransportTest method open__shouldProvideHostname.

@Test
public void open__shouldProvideHostname() throws Exception {
    MockSmtpServer server = new MockSmtpServer();
    server.output("220 localhost Simple Mail Transfer Service Ready");
    server.expect("EHLO [127.0.0.1]");
    server.output("250-localhost Hello client.localhost");
    server.output("250 OK");
    SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.PLAIN, ConnectionSecurity.NONE, null);
    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 34 with MockSmtpServer

use of com.fsck.k9.mail.transport.mockServer.MockSmtpServer 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 [127.0.0.1]");
    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), anyLong());
    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 35 with MockSmtpServer

use of com.fsck.k9.mail.transport.mockServer.MockSmtpServer in project k-9 by k9mail.

the class SmtpTransportTest method open_withManyExtensions_shouldParseAll.

@Test
public void open_withManyExtensions_shouldParseAll() throws Exception {
    MockSmtpServer server = new MockSmtpServer();
    server.output("220 smtp.gmail.com ESMTP x25sm19117693wrx.27 - gsmtp");
    server.expect("EHLO [127.0.0.1]");
    server.output("250-smtp.gmail.com at your service, [86.147.34.216]");
    server.output("250-SIZE 35882577");
    server.output("250-8BITMIME");
    server.output("250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH");
    server.output("250-ENHANCEDSTATUSCODES");
    server.output("250-PIPELINING");
    server.output("250-CHUNKING");
    server.output("250 SMTPUTF8");
    server.expect("AUTH XOAUTH2 dXNlcj11c2VyAWF1dGg9QmVhcmVyIG9sZFRva2VuAQE=");
    server.output("235 2.7.0 Authentication successful");
    SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.XOAUTH2, ConnectionSecurity.NONE);
    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)

Aggregations

MockSmtpServer (com.fsck.k9.mail.transport.mockServer.MockSmtpServer)35 XOAuth2ChallengeParserTest (com.fsck.k9.mail.XOAuth2ChallengeParserTest)34 Test (org.junit.Test)34 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)12 Message (com.fsck.k9.mail.Message)11 MessagingException (com.fsck.k9.mail.MessagingException)5 InOrder (org.mockito.InOrder)5 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)1 ServerSettings (com.fsck.k9.mail.ServerSettings)1