2014-12-18 03:33:09 -05:00
|
|
|
package com.fsck.k9.mail.store.imap;
|
2011-12-01 00:31:18 -05:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2014-02-13 17:18:16 -05:00
|
|
|
|
|
|
|
import com.fsck.k9.mail.AuthType;
|
2011-12-01 00:31:18 -05:00
|
|
|
import com.fsck.k9.mail.ConnectionSecurity;
|
|
|
|
import com.fsck.k9.mail.ServerSettings;
|
2014-12-18 03:33:09 -05:00
|
|
|
import com.fsck.k9.mail.store.RemoteStore;
|
2014-12-11 22:23:32 -05:00
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
import org.junit.Test;
|
2011-12-01 00:31:18 -05:00
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
|
|
|
|
|
public class ImapStoreUriTest {
|
|
|
|
@Test public void testDecodeStoreUriImapAllExtras() {
|
2011-12-01 00:31:18 -05:00
|
|
|
String uri = "imap://PLAIN:user:pass@server:143/0%7CcustomPathPrefix";
|
2014-12-11 22:23:32 -05:00
|
|
|
ServerSettings settings = RemoteStore.decodeStoreUri(uri);
|
2011-12-01 00:31:18 -05:00
|
|
|
|
2014-02-13 17:18:16 -05:00
|
|
|
assertEquals(AuthType.PLAIN, settings.authenticationType);
|
2011-12-01 00:31:18 -05:00
|
|
|
assertEquals("user", settings.username);
|
|
|
|
assertEquals("pass", settings.password);
|
|
|
|
assertEquals("server", settings.host);
|
|
|
|
assertEquals(143, settings.port);
|
|
|
|
assertEquals("false", settings.getExtra().get("autoDetectNamespace"));
|
|
|
|
assertEquals("customPathPrefix", settings.getExtra().get("pathPrefix"));
|
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testDecodeStoreUriImapNoExtras() {
|
2011-12-01 00:31:18 -05:00
|
|
|
String uri = "imap://PLAIN:user:pass@server:143/";
|
2014-12-11 22:23:32 -05:00
|
|
|
ServerSettings settings = RemoteStore.decodeStoreUri(uri);
|
2011-12-01 00:31:18 -05:00
|
|
|
|
2014-02-13 17:18:16 -05:00
|
|
|
assertEquals(AuthType.PLAIN, settings.authenticationType);
|
2011-12-01 00:31:18 -05:00
|
|
|
assertEquals("user", settings.username);
|
|
|
|
assertEquals("pass", settings.password);
|
|
|
|
assertEquals("server", settings.host);
|
|
|
|
assertEquals(143, settings.port);
|
|
|
|
assertEquals("true", settings.getExtra().get("autoDetectNamespace"));
|
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testDecodeStoreUriImapPrefixOnly() {
|
2011-12-01 00:31:18 -05:00
|
|
|
String uri = "imap://PLAIN:user:pass@server:143/customPathPrefix";
|
2014-12-11 22:23:32 -05:00
|
|
|
ServerSettings settings = RemoteStore.decodeStoreUri(uri);
|
2011-12-01 00:31:18 -05:00
|
|
|
|
2014-02-13 17:18:16 -05:00
|
|
|
assertEquals(AuthType.PLAIN, settings.authenticationType);
|
2011-12-01 00:31:18 -05:00
|
|
|
assertEquals("user", settings.username);
|
|
|
|
assertEquals("pass", settings.password);
|
|
|
|
assertEquals("server", settings.host);
|
|
|
|
assertEquals(143, settings.port);
|
|
|
|
assertEquals("false", settings.getExtra().get("autoDetectNamespace"));
|
|
|
|
assertEquals("customPathPrefix", settings.getExtra().get("pathPrefix"));
|
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testDecodeStoreUriImapEmptyPrefix() {
|
2011-12-01 00:31:18 -05:00
|
|
|
String uri = "imap://PLAIN:user:pass@server:143/0%7C";
|
2014-12-11 22:23:32 -05:00
|
|
|
ServerSettings settings = RemoteStore.decodeStoreUri(uri);
|
2011-12-01 00:31:18 -05:00
|
|
|
|
2014-02-13 17:18:16 -05:00
|
|
|
assertEquals(AuthType.PLAIN, settings.authenticationType);
|
2011-12-01 00:31:18 -05:00
|
|
|
assertEquals("user", settings.username);
|
|
|
|
assertEquals("pass", settings.password);
|
|
|
|
assertEquals("server", settings.host);
|
|
|
|
assertEquals(143, settings.port);
|
|
|
|
assertEquals("false", settings.getExtra().get("autoDetectNamespace"));
|
|
|
|
assertEquals("", settings.getExtra().get("pathPrefix"));
|
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testDecodeStoreUriImapAutodetectAndPrefix() {
|
2011-12-01 00:31:18 -05:00
|
|
|
String uri = "imap://PLAIN:user:pass@server:143/1%7CcustomPathPrefix";
|
2014-12-11 22:23:32 -05:00
|
|
|
ServerSettings settings = RemoteStore.decodeStoreUri(uri);
|
2011-12-01 00:31:18 -05:00
|
|
|
|
2014-02-13 17:18:16 -05:00
|
|
|
assertEquals(AuthType.PLAIN, settings.authenticationType);
|
2011-12-01 00:31:18 -05:00
|
|
|
assertEquals("user", settings.username);
|
|
|
|
assertEquals("pass", settings.password);
|
|
|
|
assertEquals("server", settings.host);
|
|
|
|
assertEquals(143, settings.port);
|
|
|
|
assertEquals("true", settings.getExtra().get("autoDetectNamespace"));
|
|
|
|
assertNull(settings.getExtra().get("pathPrefix"));
|
|
|
|
}
|
|
|
|
|
2014-12-21 05:52:05 -05:00
|
|
|
@Test public void testDecodeStoreUriWithColonsInUsernameAndPassword() {
|
|
|
|
String uri = "imap://PLAIN:a%3Auser:password%3Ahas%3Acolons@foo.com:993";
|
|
|
|
ServerSettings settings = RemoteStore.decodeStoreUri(uri);
|
|
|
|
assertEquals(AuthType.PLAIN, settings.authenticationType);
|
|
|
|
assertEquals("a:user", settings.username);
|
|
|
|
assertEquals("password:has:colons", settings.password);
|
|
|
|
assertEquals("foo.com", settings.host);
|
|
|
|
assertEquals(993, settings.port);
|
|
|
|
}
|
2011-12-01 00:31:18 -05:00
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testCreateStoreUriImapPrefix() {
|
2011-12-01 00:31:18 -05:00
|
|
|
Map<String, String> extra = new HashMap<String, String>();
|
|
|
|
extra.put("autoDetectNamespace", "false");
|
|
|
|
extra.put("pathPrefix", "customPathPrefix");
|
|
|
|
|
|
|
|
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
2014-07-04 19:23:43 -04:00
|
|
|
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra);
|
2011-12-01 00:31:18 -05:00
|
|
|
|
2014-12-11 22:23:32 -05:00
|
|
|
String uri = RemoteStore.createStoreUri(settings);
|
2011-12-01 00:31:18 -05:00
|
|
|
|
|
|
|
assertEquals("imap://PLAIN:user:pass@server:143/0%7CcustomPathPrefix", uri);
|
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testCreateStoreUriImapEmptyPrefix() {
|
2011-12-01 00:31:18 -05:00
|
|
|
Map<String, String> extra = new HashMap<String, String>();
|
|
|
|
extra.put("autoDetectNamespace", "false");
|
|
|
|
extra.put("pathPrefix", "");
|
|
|
|
|
|
|
|
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
2014-07-04 19:23:43 -04:00
|
|
|
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra);
|
2011-12-01 00:31:18 -05:00
|
|
|
|
2014-12-11 22:23:32 -05:00
|
|
|
String uri = RemoteStore.createStoreUri(settings);
|
2011-12-01 00:31:18 -05:00
|
|
|
|
|
|
|
assertEquals("imap://PLAIN:user:pass@server:143/0%7C", uri);
|
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testCreateStoreUriImapNoExtra() {
|
2011-12-01 00:31:18 -05:00
|
|
|
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
2014-07-04 19:23:43 -04:00
|
|
|
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null);
|
2011-12-01 00:31:18 -05:00
|
|
|
|
2014-12-11 22:23:32 -05:00
|
|
|
String uri = RemoteStore.createStoreUri(settings);
|
2011-12-01 00:31:18 -05:00
|
|
|
|
|
|
|
assertEquals("imap://PLAIN:user:pass@server:143/1%7C", uri);
|
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testCreateStoreUriImapAutoDetectNamespace() {
|
2011-12-01 00:31:18 -05:00
|
|
|
Map<String, String> extra = new HashMap<String, String>();
|
|
|
|
extra.put("autoDetectNamespace", "true");
|
|
|
|
|
|
|
|
ServerSettings settings = new ServerSettings(ImapStore.STORE_TYPE, "server", 143,
|
2014-07-04 19:23:43 -04:00
|
|
|
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra);
|
2011-12-01 00:31:18 -05:00
|
|
|
|
2014-12-11 22:23:32 -05:00
|
|
|
String uri = RemoteStore.createStoreUri(settings);
|
2011-12-01 00:31:18 -05:00
|
|
|
|
|
|
|
assertEquals("imap://PLAIN:user:pass@server:143/1%7C", uri);
|
|
|
|
}
|
|
|
|
}
|