k-9/k9mail/src/test/java/com/fsck/k9/mail/store/imap/ImapStoreUriTest.java

153 lines
5.9 KiB
Java
Raw Normal View History

2014-12-18 03:33:09 -05:00
package com.fsck.k9.mail.store.imap;
2011-12-01 00:31:18 -05:00
2014-12-22 11:33:48 -05:00
2011-12-01 00:31:18 -05:00
import java.util.HashMap;
import java.util.Map;
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;
import org.junit.Test;
2011-12-01 00:31:18 -05:00
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
2014-12-22 11:33:48 -05:00
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";
ServerSettings settings = RemoteStore.decodeStoreUri(uri);
2011-12-01 00:31:18 -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-22 11:33:48 -05:00
@Test
public void testDecodeStoreUriImapNoExtras() {
2011-12-01 00:31:18 -05:00
String uri = "imap://PLAIN:user:pass@server:143/";
ServerSettings settings = RemoteStore.decodeStoreUri(uri);
2011-12-01 00:31:18 -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-22 11:33:48 -05:00
@Test
public void testDecodeStoreUriImapPrefixOnly() {
2011-12-01 00:31:18 -05:00
String uri = "imap://PLAIN:user:pass@server:143/customPathPrefix";
ServerSettings settings = RemoteStore.decodeStoreUri(uri);
2011-12-01 00:31:18 -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-22 11:33:48 -05:00
@Test
public void testDecodeStoreUriImapEmptyPrefix() {
2011-12-01 00:31:18 -05:00
String uri = "imap://PLAIN:user:pass@server:143/0%7C";
ServerSettings settings = RemoteStore.decodeStoreUri(uri);
2011-12-01 00:31:18 -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-22 11:33:48 -05:00
@Test
public void testDecodeStoreUriImapAutodetectAndPrefix() {
2011-12-01 00:31:18 -05:00
String uri = "imap://PLAIN:user:pass@server:143/1%7CcustomPathPrefix";
ServerSettings settings = RemoteStore.decodeStoreUri(uri);
2011-12-01 00:31:18 -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-22 11:33:48 -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(ServerSettings.Type.IMAP, "server", 143,
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra);
2011-12-01 00:31:18 -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-22 11:33:48 -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(ServerSettings.Type.IMAP, "server", 143,
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra);
2011-12-01 00:31:18 -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-22 11:33:48 -05:00
@Test
public void testCreateStoreUriImapNoExtra() {
ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143,
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null);
2011-12-01 00:31:18 -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-22 11:33:48 -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(ServerSettings.Type.IMAP, "server", 143,
ConnectionSecurity.NONE, AuthType.PLAIN, "user", "pass", null, extra);
2011-12-01 00:31:18 -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);
}
@Test
public void testCreateDecodeStoreUriWithSpecialCharactersInUsernameAndPassword() {
ServerSettings settings = new ServerSettings(ServerSettings.Type.IMAP, "server", 143,
ConnectionSecurity.NONE, AuthType.PLAIN, "user@doma:n", "p@ssw:rd%", null, null);
String uri = RemoteStore.createStoreUri(settings);
assertEquals("imap://PLAIN:user%2540doma%253An:p%2540ssw%253Ard%2525@server:143/1%7C", uri);
ServerSettings outSettings = RemoteStore.decodeStoreUri(uri);
assertEquals("user@doma:n", outSettings.username);
assertEquals("p@ssw:rd%", outSettings.password);
}
2011-12-01 00:31:18 -05:00
}