Search in sources :

Example 11 with OAuth2TokenProvider

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

the class SmtpTransportTest method open_withXoauth2Extension_shouldThrowOn401Response.

@Test
public void open_withXoauth2Extension_shouldThrowOn401Response() 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.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("5.7.1 Username and Password not accepted. Learn more at " + "5.7.1 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 12 with OAuth2TokenProvider

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

the class SmtpTransportTest method before.

@Before
public void before() throws AuthenticationFailedException {
    socketFactory = new TestTrustedSocketFactory();
    oAuth2TokenProvider = mock(OAuth2TokenProvider.class);
    when(oAuth2TokenProvider.getToken(eq(USERNAME), anyInt())).thenReturn("oldToken").thenReturn("newToken");
}
Also used : OAuth2TokenProvider(com.fsck.k9.mail.oauth.OAuth2TokenProvider) TestTrustedSocketFactory(com.fsck.k9.mail.helpers.TestTrustedSocketFactory) Before(org.junit.Before)

Example 13 with OAuth2TokenProvider

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

the class SmtpTransportTest method SmtpTransport_withInvalidTransportUri_shouldThrow.

@Test(expected = MessagingException.class)
public void SmtpTransport_withInvalidTransportUri_shouldThrow() throws Exception {
    StoreConfig storeConfig = createStoreConfigWithTransportUri("smpt://");
    new SmtpTransport(storeConfig, socketFactory, oAuth2TokenProvider);
}
Also used : StoreConfig(com.fsck.k9.mail.store.StoreConfig) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 14 with OAuth2TokenProvider

use of com.fsck.k9.mail.oauth.OAuth2TokenProvider 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 15 with OAuth2TokenProvider

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

the class ImapStoreTest method setUp.

@Before
public void setUp() throws Exception {
    storeConfig = createStoreConfig();
    TrustedSocketFactory trustedSocketFactory = mock(TrustedSocketFactory.class);
    ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
    OAuth2TokenProvider oauth2TokenProvider = mock(OAuth2TokenProvider.class);
    imapStore = new TestImapStore(storeConfig, trustedSocketFactory, connectivityManager, oauth2TokenProvider);
}
Also used : TrustedSocketFactory(com.fsck.k9.mail.ssl.TrustedSocketFactory) ConnectivityManager(android.net.ConnectivityManager) OAuth2TokenProvider(com.fsck.k9.mail.oauth.OAuth2TokenProvider) Before(org.junit.Before)

Aggregations

XOAuth2ChallengeParserTest (com.fsck.k9.mail.XOAuth2ChallengeParserTest)10 Test (org.junit.Test)10 InOrder (org.mockito.InOrder)8 MockSmtpServer (com.fsck.k9.mail.transport.mockServer.MockSmtpServer)5 OAuth2TokenProvider (com.fsck.k9.mail.oauth.OAuth2TokenProvider)4 ConnectivityManager (android.net.ConnectivityManager)3 StoreConfig (com.fsck.k9.mail.store.StoreConfig)3 MockImapServer (com.fsck.k9.mail.store.imap.mockserver.MockImapServer)3 Before (org.junit.Before)3 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)2 TestTrustedSocketFactory (com.fsck.k9.mail.helpers.TestTrustedSocketFactory)2 MessagingException (com.fsck.k9.mail.MessagingException)1 ServerSettings (com.fsck.k9.mail.ServerSettings)1 Store (com.fsck.k9.mail.Store)1 DefaultTrustedSocketFactory (com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory)1 TrustedSocketFactory (com.fsck.k9.mail.ssl.TrustedSocketFactory)1 ImapStore (com.fsck.k9.mail.store.imap.ImapStore)1 Pop3Store (com.fsck.k9.mail.store.pop3.Pop3Store)1 WebDavStore (com.fsck.k9.mail.store.webdav.WebDavStore)1 Matchers.anyString (org.mockito.Matchers.anyString)1