Search in sources :

Example 6 with MockSmtpServer

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

the class SmtpTransportTest method open_withAuthExternalExtension.

@Test
public void open_withAuthExternalExtension() 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 EXTERNAL");
    server.expect("AUTH EXTERNAL dXNlcg==");
    server.output("235 2.7.0 Authentication successful");
    SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.EXTERNAL, 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)

Example 7 with MockSmtpServer

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

the class SmtpTransportTest method open_withXoauth2Extension_shouldInvalidateAndRetryOnInvalidJsonResponse.

@Test
public void open_withXoauth2Extension_shouldInvalidateAndRetryOnInvalidJsonResponse() 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 XOAUTH2");
    server.expect("AUTH XOAUTH2 dXNlcj11c2VyAWF1dGg9QmVhcmVyIG9sZFRva2VuAQE=");
    server.output("334 " + XOAuth2ChallengeParserTest.INVALID_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("AUTH XOAUTH2 dXNlcj11c2VyAWF1dGg9QmVhcmVyIG5ld1Rva2VuAQE=");
    server.output("235 2.7.0 Authentication successful");
    SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.XOAUTH2, ConnectionSecurity.NONE);
    transport.open();
    InOrder inOrder = inOrder(oAuth2TokenProvider);
    inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyInt());
    inOrder.verify(oAuth2TokenProvider).invalidateToken(USERNAME);
    inOrder.verify(oAuth2TokenProvider).getToken(eq(USERNAME), anyInt());
    server.verifyConnectionStillOpen();
    server.verifyInteractionCompleted();
}
Also used : InOrder(org.mockito.InOrder) MockSmtpServer(com.fsck.k9.mail.transport.mockServer.MockSmtpServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 8 with MockSmtpServer

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

the class SmtpTransportTest method open_withoutLoginAndPlainAuthExtensions_shouldThrow.

@Test
public void open_withoutLoginAndPlainAuthExtensions_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.PLAIN, ConnectionSecurity.NONE);
    try {
        transport.open();
        fail("Exception expected");
    } catch (MessagingException e) {
        assertEquals("Authentication methods SASL PLAIN and LOGIN are unavailable.", e.getMessage());
    }
    server.verifyConnectionStillOpen();
    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 9 with MockSmtpServer

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

the class SmtpTransportTest method startServerAndCreateSmtpTransport.

private SmtpTransport startServerAndCreateSmtpTransport(MockSmtpServer server, AuthType authenticationType, ConnectionSecurity connectionSecurity, String password) throws IOException, MessagingException {
    server.start();
    String host = server.getHost();
    int port = server.getPort();
    ServerSettings serverSettings = new ServerSettings(Type.SMTP, host, port, connectionSecurity, authenticationType, USERNAME, password, CLIENT_CERTIFICATE_ALIAS);
    String uri = SmtpTransport.createUri(serverSettings);
    StoreConfig storeConfig = createStoreConfigWithTransportUri(uri);
    return new TestSmtpTransport(storeConfig, socketFactory, oAuth2TokenProvider);
}
Also used : ServerSettings(com.fsck.k9.mail.ServerSettings) StoreConfig(com.fsck.k9.mail.store.StoreConfig) Matchers.anyString(org.mockito.Matchers.anyString)

Example 10 with MockSmtpServer

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

the class SmtpTransportTest method open_withEhloFailing_shouldTryHelo.

@Test
public void open_withEhloFailing_shouldTryHelo() throws Exception {
    MockSmtpServer server = new MockSmtpServer();
    server.output("220 localhost Simple Mail Transfer Service Ready");
    server.expect("EHLO localhost");
    server.output("502 5.5.1, Unrecognized command.");
    server.expect("HELO localhost");
    server.output("250 localhost");
    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)

Aggregations

MockSmtpServer (com.fsck.k9.mail.transport.mockServer.MockSmtpServer)28 XOAuth2ChallengeParserTest (com.fsck.k9.mail.XOAuth2ChallengeParserTest)27 Test (org.junit.Test)27 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)6 Message (com.fsck.k9.mail.Message)5 MessagingException (com.fsck.k9.mail.MessagingException)5 InOrder (org.mockito.InOrder)5 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)4 Matchers.anyString (org.mockito.Matchers.anyString)2 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)1 ServerSettings (com.fsck.k9.mail.ServerSettings)1 StoreConfig (com.fsck.k9.mail.store.StoreConfig)1