public ServerSettings newPassword(String newPassword) { return new ServerSettings(type, host, port, connectionSecurity, authenticationType, username, newPassword, clientCertificateAlias); }
private ServerSettings createServerSettings() { return new ServerSettings( "pop3", "server", 12345, ConnectionSecurity.SSL_TLS_REQUIRED, AuthType.PLAIN, "user", "password", null); } }
@Test public void createTransportUri_canEncodeSmtpSslUri() { ServerSettings serverSettings = new ServerSettings( "smtp", "server", 123456, ConnectionSecurity.SSL_TLS_REQUIRED, AuthType.EXTERNAL, "user", "password", "clientCert"); String result = SmtpTransportUriCreator.createSmtpUri(serverSettings); assertEquals("smtp+ssl+://user:clientCert:EXTERNAL@server:123456", result); }
@Test public void createTransportUri_canEncodeSmtpTlsUri() { ServerSettings serverSettings = new ServerSettings( "smtp", "server", 123456, ConnectionSecurity.STARTTLS_REQUIRED, AuthType.PLAIN, "user", "password", "clientCert"); String result = SmtpTransportUriCreator.createSmtpUri(serverSettings); assertEquals("smtp+tls+://user:password:PLAIN@server:123456", result); }
@Test public void createTransportUri_canEncodeSmtpUri() { ServerSettings serverSettings = new ServerSettings( "smtp", "server", 123456, ConnectionSecurity.NONE, AuthType.CRAM_MD5, "user", "password", "clientCert"); String result = SmtpTransportUriCreator.createSmtpUri(serverSettings); assertEquals("smtp://user:password:CRAM_MD5@server:123456", result); } }
@Test public void testCreateStoreUriImapEmptyPrefix() { Map<String, String> extra = new HashMap<>(); extra.put("autoDetectNamespace", "false"); extra.put("pathPrefix", ""); ServerSettings settings = new ServerSettings("imap", "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra); String uri = ImapStoreUriCreator.create(settings); assertEquals("imap://PLAIN:user:pass@server:143/0%7C", uri); }
@Test public void testCreateStoreUriImapPrefix() { Map<String, String> extra = new HashMap<>(); extra.put("autoDetectNamespace", "false"); extra.put("pathPrefix", "customPathPrefix"); ServerSettings settings = new ServerSettings("imap", "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra); String uri = ImapStoreUriCreator.create(settings); assertEquals("imap://PLAIN:user:pass@server:143/0%7CcustomPathPrefix", uri); }
@Test public void testCreateStoreUriImapAutoDetectNamespace() { Map<String, String> extra = new HashMap<>(); extra.put("autoDetectNamespace", "true"); ServerSettings settings = new ServerSettings("imap", "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra); String uri = ImapStoreUriCreator.create(settings); assertEquals("imap://PLAIN:user:pass@server:143/1%7C", uri); }
@Test public void encodeThenDecode() { ServerSettings serverSettings = new ServerSettings( "smtp", "server", 123456, ConnectionSecurity.STARTTLS_REQUIRED, AuthType.CRAM_MD5, "user", "password", null); String uri = SmtpTransportUriCreator.createSmtpUri(serverSettings); ServerSettings decodedSettings = SmtpTransportUriDecoder.decodeSmtpUri(uri); assertEquals(serverSettings, decodedSettings); }
@Test public void encodeThenDecode_externalAuth_preservesCert() { ServerSettings serverSettings = new ServerSettings( "smtp", "server", 123456, ConnectionSecurity.NONE, AuthType.EXTERNAL, "username", null, "clientcert"); String uri = SmtpTransportUriCreator.createSmtpUri(serverSettings); ServerSettings decodedSettings = SmtpTransportUriDecoder.decodeSmtpUri(uri); assertEquals(serverSettings, decodedSettings); }
@Test public void testCreateStoreUriImapNoExtra() { ServerSettings settings = new ServerSettings("imap", "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null); String uri = ImapStoreUriCreator.create(settings); assertEquals("imap://PLAIN:user:pass@server:143/1%7C", uri); }
@Test public void createUri_withSettingsWithTLS_shouldProvideSSLUri() { ServerSettings serverSettings = new ServerSettings("webdav", "example.org", 123456, ConnectionSecurity.SSL_TLS_REQUIRED, AuthType.PLAIN, "user", "password", null); String result = WebDavStoreUriCreator.create(serverSettings); assertEquals("webdav+ssl+://user:password@example.org:123456/%7C%7C", result); } }
@Test public void createUri_withSTARTTLSRequired_shouldProduceTLSUri() { ServerSettings settings = new ServerSettings("pop3", "server", 12345, ConnectionSecurity.STARTTLS_REQUIRED, AuthType.PLAIN, "user", "password", null); String uri = Pop3StoreUriCreator.create(settings); assertEquals(uri, "pop3+tls+://PLAIN:user:password@server:12345"); }
@Test public void createUri_withNONE_shouldProducePop3Uri() { ServerSettings settings = new ServerSettings("pop3", "server", 12345, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "password", null); String uri = Pop3StoreUriCreator.create(settings); assertEquals(uri, "pop3://PLAIN:user:password@server:12345"); }
@Test public void createUri_withPLAIN_shouldProducePlainAuthUri() { ServerSettings settings = new ServerSettings("pop3", "server", 12345, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "password", null); String uri = Pop3StoreUriCreator.create(settings); assertEquals(uri, "pop3://PLAIN:user:password@server:12345"); }
@Test public void createUri_withEXTERNAL_shouldProduceExternalAuthUri() { ServerSettings settings = new ServerSettings("pop3", "server", 12345, ConnectionSecurity.NONE, AuthType.EXTERNAL, "user", "password", "clientCert"); String uri = Pop3StoreUriCreator.create(settings); assertEquals(uri, "pop3://EXTERNAL:user:clientCert@server:12345"); }
@Test public void createUri_withSSLTLS_required_shouldProduceSSLUri() { ServerSettings settings = new ServerSettings("pop3", "server", 12345, ConnectionSecurity.SSL_TLS_REQUIRED, AuthType.PLAIN, "user", "password", null); String uri = Pop3StoreUriCreator.create(settings); assertEquals(uri, "pop3+ssl+://PLAIN:user:password@server:12345"); }
@Test public void createUri_withCRAMMD5_shouldProduceCRAMMD5AuthUri() { ServerSettings settings = new ServerSettings("pop3", "server", 12345, ConnectionSecurity.NONE, AuthType.CRAM_MD5, "user", "password", "clientCert"); String uri = Pop3StoreUriCreator.create(settings); assertEquals(uri, "pop3://CRAM_MD5:user:password@server:12345"); } }
@Test public void createUri_withSetting_shouldProvideUri() { ServerSettings serverSettings = new ServerSettings("webdav", "example.org", 123456, ConnectionSecurity.NONE, AuthType.PLAIN, "user", "password", null); String result = WebDavStoreUriCreator.create(serverSettings); assertEquals("webdav://user:password@example.org:123456/%7C%7C", result); }
@Test public void testCreateDecodeStoreUriWithSpecialCharactersInUsernameAndPassword() { ServerSettings settings = new ServerSettings("imap", "server", 143, ConnectionSecurity.NONE, AuthType.PLAIN, "user@doma:n", "p@ssw:rd%", null, null); String uri = ImapStoreUriCreator.create(settings); assertEquals("imap://PLAIN:user%2540doma%253An:p%2540ssw%253Ard%2525@server:143/1%7C", uri); ServerSettings outSettings = ImapStoreUriDecoder.decode(uri); assertEquals("user@doma:n", outSettings.username); assertEquals("p@ssw:rd%", outSettings.password); } }