Search in sources :

Example 51 with MockImapServer

use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer in project k-9 by k9mail.

the class ImapConnectionTest method open_authXoauthWithSaslIrInvalidatesAndRetriesNewTokenOnInvalidJsonResponse.

@Test
public void open_authXoauthWithSaslIrInvalidatesAndRetriesNewTokenOnInvalidJsonResponse() throws Exception {
    settings.setAuthType(AuthType.XOAUTH2);
    when(oAuth2TokenProvider.getToken("user", OAuth2TokenProvider.OAUTH2_TIMEOUT)).thenReturn("token").thenReturn("token2");
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "SASL-IR AUTH=XOAUTH AUTH=XOAUTH2");
    server.expect("2 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING);
    server.output("+ " + XOAuth2ChallengeParserTest.INVALID_RESPONSE);
    server.expect("");
    server.output("2 NO SASL authentication failed");
    server.expect("3 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING_RETRY);
    server.output("3 OK Success");
    simplePostAuthenticationDialog(server, "4");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    imapConnection.open();
    server.verifyConnectionStillOpen();
    server.verifyInteractionCompleted();
    InOrder inOrder = inOrder(oAuth2TokenProvider);
    inOrder.verify(oAuth2TokenProvider).getToken("user", OAuth2TokenProvider.OAUTH2_TIMEOUT);
    inOrder.verify(oAuth2TokenProvider).invalidateToken("user");
    inOrder.verify(oAuth2TokenProvider).getToken("user", OAuth2TokenProvider.OAUTH2_TIMEOUT);
}
Also used : InOrder(org.mockito.InOrder) MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 52 with MockImapServer

use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer in project k-9 by k9mail.

the class ImapConnectionTest method open_authXoauthWithSaslIrThrowsExeptionOn401Response.

@Test
public void open_authXoauthWithSaslIrThrowsExeptionOn401Response() throws Exception {
    settings.setAuthType(AuthType.XOAUTH2);
    when(oAuth2TokenProvider.getToken("user", OAuth2TokenProvider.OAUTH2_TIMEOUT)).thenReturn("token").thenReturn("token2");
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "SASL-IR AUTH=XOAUTH AUTH=XOAUTH2");
    server.expect("2 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING);
    server.output("+ " + XOAuth2ChallengeParserTest.STATUS_401_RESPONSE);
    server.expect("");
    server.output("2 NO SASL authentication failed");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    try {
        imapConnection.open();
        fail();
    } catch (AuthenticationFailedException e) {
        assertEquals("Command: AUTHENTICATE XOAUTH2; response: #2# [NO, SASL authentication failed]", e.getMessage());
    }
}
Also used : AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException) MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 53 with MockImapServer

use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer in project k-9 by k9mail.

the class ImapConnectionTest method open_authXoauthWithSaslIrParsesCapabilities.

@Test
public void open_authXoauthWithSaslIrParsesCapabilities() throws Exception {
    settings.setAuthType(AuthType.XOAUTH2);
    when(oAuth2TokenProvider.getToken("user", OAuth2TokenProvider.OAUTH2_TIMEOUT)).thenReturn("token");
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "SASL-IR AUTH=XOAUTH AUTH=XOAUTH2");
    server.expect("2 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING);
    server.output("2 OK [CAPABILITY IMAP4REV1 IDLE XM-GM-EXT-1]");
    simplePostAuthenticationDialog(server);
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    imapConnection.open();
    server.verifyConnectionStillOpen();
    server.verifyInteractionCompleted();
    assertTrue(imapConnection.hasCapability("XM-GM-EXT-1"));
}
Also used : MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 54 with MockImapServer

use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer in project k-9 by k9mail.

the class ImapConnectionTest method open_authExternal.

@Test
public void open_authExternal() 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 OK Success");
    simplePostAuthenticationDialog(server);
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    imapConnection.open();
    server.verifyConnectionStillOpen();
    server.verifyInteractionCompleted();
}
Also used : MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 55 with MockImapServer

use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer in project k-9 by k9mail.

the class ImapConnectionTest method open_authXoauthWithSaslIrInvalidatesAndRetriesNewTokenOn400Response.

@Test
public void open_authXoauthWithSaslIrInvalidatesAndRetriesNewTokenOn400Response() throws Exception {
    settings.setAuthType(AuthType.XOAUTH2);
    when(oAuth2TokenProvider.getToken("user", OAuth2TokenProvider.OAUTH2_TIMEOUT)).thenReturn("token").thenReturn("token2");
    MockImapServer server = new MockImapServer();
    preAuthenticationDialog(server, "SASL-IR AUTH=XOAUTH AUTH=XOAUTH2");
    server.expect("2 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING);
    server.output("+ " + XOAuth2ChallengeParserTest.STATUS_400_RESPONSE);
    server.expect("");
    server.output("2 NO SASL authentication failed");
    server.expect("3 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING_RETRY);
    server.output("3 OK Success");
    simplePostAuthenticationDialog(server, "4");
    ImapConnection imapConnection = startServerAndCreateImapConnection(server);
    imapConnection.open();
    server.verifyConnectionStillOpen();
    server.verifyInteractionCompleted();
    InOrder inOrder = inOrder(oAuth2TokenProvider);
    inOrder.verify(oAuth2TokenProvider).getToken("user", OAuth2TokenProvider.OAUTH2_TIMEOUT);
    inOrder.verify(oAuth2TokenProvider).invalidateToken("user");
    inOrder.verify(oAuth2TokenProvider).getToken("user", OAuth2TokenProvider.OAUTH2_TIMEOUT);
}
Also used : InOrder(org.mockito.InOrder) MockImapServer(com.fsck.k9.mail.store.imap.mockserver.MockImapServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Aggregations

XOAuth2ChallengeParserTest (com.fsck.k9.mail.XOAuth2ChallengeParserTest)81 MockImapServer (com.fsck.k9.mail.store.imap.mockserver.MockImapServer)81 Test (org.junit.Test)81 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)10 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)6 MessagingException (com.fsck.k9.mail.MessagingException)4 IOException (java.io.IOException)4 InOrder (org.mockito.InOrder)3