use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer in project k-9 by k9mail.
the class ImapConnectionTest method open_authPlainAndLoginFallbackWithAuthenticationFailure_shouldThrow.
@Test
public void open_authPlainAndLoginFallbackWithAuthenticationFailure_shouldThrow() throws Exception {
settings.setAuthType(AuthType.PLAIN);
MockImapServer server = new MockImapServer();
preAuthenticationDialog(server, "AUTH=PLAIN");
server.expect("2 AUTHENTICATE PLAIN");
server.output("+");
server.expect(ByteString.encodeUtf8("\000" + USERNAME + "\000" + PASSWORD).base64());
server.output("2 NO Login Failure");
server.expect("3 LOGIN \"" + USERNAME + "\" \"" + PASSWORD + "\"");
server.output("3 NO Go away");
ImapConnection imapConnection = startServerAndCreateImapConnection(server);
try {
imapConnection.open();
fail("Expected exception");
} catch (AuthenticationFailedException e) {
//FIXME: improve exception message
assertThat(e.getMessage(), containsString("Go away"));
}
server.verifyConnectionClosed();
server.verifyInteractionCompleted();
}
use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer in project k-9 by k9mail.
the class ImapConnectionTest method open_withCompressDeflateCapability_shouldEnableCompression.
@Test
public void open_withCompressDeflateCapability_shouldEnableCompression() throws Exception {
settings.setUseCompression(true);
MockImapServer server = new MockImapServer();
simplePreAuthAndLoginDialog(server, "COMPRESS=DEFLATE");
server.expect("3 COMPRESS DEFLATE");
server.output("3 OK");
server.enableCompression();
simplePostAuthenticationDialog(server, "4");
ImapConnection imapConnection = startServerAndCreateImapConnection(server);
imapConnection.open();
server.verifyConnectionStillOpen();
server.verifyInteractionCompleted();
}
use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer in project k-9 by k9mail.
the class ImapConnectionTest method open_authXoauthWithSaslIrWithOldTokenThrowsExceptionIfRetryFails.
@Test
public void open_authXoauthWithSaslIrWithOldTokenThrowsExceptionIfRetryFails() 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("+ r3j3krj3irj3oir3ojo");
server.expect("");
server.output("2 NO SASL authentication failed");
server.expect("3 AUTHENTICATE XOAUTH2 " + XOAUTH_STRING_RETRY);
server.output("+ 433ba3a3a");
server.expect("");
server.output("3 NO SASL authentication failed");
simplePostAuthenticationDialog(server);
ImapConnection imapConnection = startServerAndCreateImapConnection(server);
try {
imapConnection.open();
fail();
} catch (AuthenticationFailedException e) {
assertEquals("Command: AUTHENTICATE XOAUTH2; response: #3# [NO, SASL authentication failed]", e.getMessage());
}
}
use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer in project k-9 by k9mail.
the class ImapConnectionTest method isConnected_afterOpenAndClose_shouldReturnFalse.
@Test
public void isConnected_afterOpenAndClose_shouldReturnFalse() throws Exception {
MockImapServer server = new MockImapServer();
ImapConnection imapConnection = simpleOpen(server);
imapConnection.close();
boolean result = imapConnection.isConnected();
assertFalse(result);
server.verifyConnectionClosed();
server.shutdown();
}
use of com.fsck.k9.mail.store.imap.mockserver.MockImapServer in project k-9 by k9mail.
the class ImapConnectionTest method open_authExternalWithoutAuthExternalCapability_shouldThrow.
@Test
public void open_authExternalWithoutAuthExternalCapability_shouldThrow() throws Exception {
settings.setAuthType(AuthType.EXTERNAL);
MockImapServer server = new MockImapServer();
preAuthenticationDialog(server, "AUTH=PLAIN");
ImapConnection imapConnection = startServerAndCreateImapConnection(server);
try {
imapConnection.open();
fail("Expected exception");
} catch (CertificateValidationException e) {
assertEquals(Reason.MissingCapability, e.getReason());
}
server.verifyConnectionClosed();
server.verifyInteractionCompleted();
}
Aggregations