private String errorMessageForCertificateException(CertificateValidationException e) { switch (e.getReason()) { case Expired: return getString(R.string.client_certificate_expired, e.getAlias(), e.getMessage()); case MissingCapability: return getString(R.string.auth_external_error); case RetrievalFailure: return getString(R.string.client_certificate_retrieval_failure, e.getAlias()); case UseMessage: return e.getMessage(); case Unknown: default: return ""; } }
@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(); }
@Test public void open_withoutAuthExternalExtension_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"); server.expect("QUIT"); server.output("221 BYE"); SmtpTransport transport = startServerAndCreateSmtpTransport(server, AuthType.EXTERNAL, ConnectionSecurity.NONE); try { transport.open(); fail("Exception expected"); } catch (CertificateValidationException e) { assertEquals(CertificateValidationException.Reason.MissingCapability, e.getReason()); } server.verifyConnectionClosed(); server.verifyInteractionCompleted(); }
@Test public void open_withAuthTypeExternalAndNoCapability_throwsCVE() throws IOException, MessagingException { settings.setAuthType(AuthType.EXTERNAL); MockPop3Server server = new MockPop3Server(); server.output("+OK POP3 server greeting"); server.expect("AUTH"); server.output("+OK Listing of supported mechanisms follows"); server.output("PLAIN"); server.output("CRAM-MD5"); server.output("."); server.expect("CAPA"); server.output("+OK Listing of supported mechanisms follows"); server.output("PLAIN"); server.output("CRAM-MD5"); server.output("EXTERNAL"); server.output("."); try { startServerAndCreateOpenConnection(server); fail("CVE expected"); } catch (CertificateValidationException e) { assertEquals(Reason.MissingCapability, e.getReason()); } server.verifyConnectionStillOpen(); server.verifyInteractionCompleted(); }