Resolve build warnings; part 5

Remove dependence upon URIs for creating the host auth structure

Change-Id: I92dee36fa329a8976b76bbd4991ed3469c6475f2
This commit is contained in:
Todd Kennedy 2011-02-04 09:29:13 -08:00
parent d25610356d
commit 040ddf60cf
21 changed files with 1002 additions and 541 deletions

View File

@ -103,6 +103,10 @@
*** setRecipient(com.android.emailcommon.mail.Message$RecipientType, com.android.emailcommon.mail.Address); *** setRecipient(com.android.emailcommon.mail.Message$RecipientType, com.android.emailcommon.mail.Address);
} }
-keepclasseswithmembers class com.android.emailcommon.internet.MimeHeader {
*** writeToString();
}
-keepclasseswithmembers class com.android.emailcommon.internet.MimeMessage { -keepclasseswithmembers class com.android.emailcommon.internet.MimeMessage {
<init>(); <init>();
<init>(java.io.InputStream); <init>(java.io.InputStream);

View File

@ -32,8 +32,10 @@ import com.android.emailcommon.mail.Message.RecipientType;
import com.android.emailcommon.provider.EmailContent; import com.android.emailcommon.provider.EmailContent;
import com.android.emailcommon.provider.EmailContent.Attachment; import com.android.emailcommon.provider.EmailContent.Attachment;
import com.android.emailcommon.provider.EmailContent.AttachmentColumns; import com.android.emailcommon.provider.EmailContent.AttachmentColumns;
import com.android.emailcommon.provider.EmailContent.HostAuth;
import com.android.emailcommon.provider.EmailContent.Mailbox; import com.android.emailcommon.provider.EmailContent.Mailbox;
import com.android.emailcommon.utility.AttachmentUtilities; import com.android.emailcommon.utility.AttachmentUtilities;
import com.android.emailcommon.utility.Utility;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@ -48,6 +50,7 @@ import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -519,8 +522,20 @@ public class LegacyConversions {
result.mSecuritySyncKey = null; result.mSecuritySyncKey = null;
result.mSignature = fromAccount.mSignature; result.mSignature = fromAccount.mSignature;
result.setStoreUri(context, fromAccount.getStoreUri()); try {
result.setSenderUri(context, fromAccount.getSenderUri()); HostAuth recvAuth = result.getOrCreateHostAuthRecv(context);
Utility.setHostAuthFromString(recvAuth, fromAccount.getStoreUri());
} catch (URISyntaxException e) {
result.mHostAuthRecv = new HostAuth();
Log.w(Logging.LOG_TAG, e);
}
try {
HostAuth sendAuth = result.getOrCreateHostAuthSend(context);
Utility.setHostAuthFromString(sendAuth, fromAccount.getSenderUri());
} catch (URISyntaxException e) {
result.mHostAuthSend = new HostAuth();
Log.w(Logging.LOG_TAG, e);
}
return result; return result;
} }

View File

@ -219,20 +219,16 @@ public class VendorPolicyLoader {
params.putString(FIND_PROVIDER, domain); params.putString(FIND_PROVIDER, domain);
Bundle out = getPolicy(FIND_PROVIDER, params); Bundle out = getPolicy(FIND_PROVIDER, params);
if (out != null && !out.isEmpty()) { if (out != null && !out.isEmpty()) {
try { Provider p = new Provider();
Provider p = new Provider(); p.id = null;
p.id = null; p.label = null;
p.label = null; p.domain = domain;
p.domain = domain; p.incomingUriTemplate = out.getString(FIND_PROVIDER_IN_URI);
p.incomingUriTemplate = new URI(out.getString(FIND_PROVIDER_IN_URI)); p.incomingUsernameTemplate = out.getString(FIND_PROVIDER_IN_USER);
p.incomingUsernameTemplate = out.getString(FIND_PROVIDER_IN_USER); p.outgoingUriTemplate = out.getString(FIND_PROVIDER_OUT_URI);
p.outgoingUriTemplate = new URI(out.getString(FIND_PROVIDER_OUT_URI)); p.outgoingUsernameTemplate = out.getString(FIND_PROVIDER_OUT_USER);
p.outgoingUsernameTemplate = out.getString(FIND_PROVIDER_OUT_USER); p.note = out.getString(FIND_PROVIDER_NOTE);
p.note = out.getString(FIND_PROVIDER_NOTE); return p;
return p;
} catch (URISyntaxException e) {
Log.d(Logging.LOG_TAG, "uri exception while vendor policy loads " + domain);
}
} }
return null; return null;
} }

View File

@ -501,9 +501,10 @@ public class AccountCheckSettingsFragment extends Fragment {
return new MessagingException(MessagingException.AUTHENTICATION_FAILED); return new MessagingException(MessagingException.AUTHENTICATION_FAILED);
} }
// Return "real" AD results // Return "real" AD results
HostAuth serverInfo = new HostAuth(); HostAuth auth = new HostAuth();
serverInfo.setStoreUri("eas://user:password@testserver.com"); auth.setLogin("user", "password");
return new AutoDiscoverResults(false, serverInfo); auth.setConnection(Store.STORE_SCHEME_EAS, "testserver.com", 0);
return new AutoDiscoverResults(false, auth);
} }
if (isCancelled()) return null; if (isCancelled()) return null;
if ((mMode & SetupData.CHECK_INCOMING) != 0) { if ((mMode & SetupData.CHECK_INCOMING) != 0) {
@ -632,6 +633,7 @@ public class AccountCheckSettingsFragment extends Fragment {
* recreated at any time without affecting the account checking progress. * recreated at any time without affecting the account checking progress.
*/ */
public static class CheckingDialog extends DialogFragment { public static class CheckingDialog extends DialogFragment {
@SuppressWarnings("hiding")
public final static String TAG = "CheckProgressDialog"; public final static String TAG = "CheckProgressDialog";
// Extras for saved instance state // Extras for saved instance state
@ -729,6 +731,7 @@ public class AccountCheckSettingsFragment extends Fragment {
* The standard error dialog. Calls back to onErrorDialogButton(). * The standard error dialog. Calls back to onErrorDialogButton().
*/ */
public static class ErrorDialog extends DialogFragment { public static class ErrorDialog extends DialogFragment {
@SuppressWarnings("hiding")
public final static String TAG = "ErrorDialog"; public final static String TAG = "ErrorDialog";
// Bundle keys for arguments // Bundle keys for arguments
@ -784,6 +787,7 @@ public class AccountCheckSettingsFragment extends Fragment {
* same as any other failed check.) * same as any other failed check.)
*/ */
public static class SecurityRequiredDialog extends DialogFragment { public static class SecurityRequiredDialog extends DialogFragment {
@SuppressWarnings("hiding")
public final static String TAG = "SecurityRequiredDialog"; public final static String TAG = "SecurityRequiredDialog";
// Bundle keys for arguments // Bundle keys for arguments

View File

@ -53,6 +53,7 @@ public abstract class AccountServerBaseFragment extends Fragment
protected Context mContext; protected Context mContext;
protected Callback mCallback = EmptyCallback.INSTANCE; protected Callback mCallback = EmptyCallback.INSTANCE;
protected boolean mSettingsMode; protected boolean mSettingsMode;
// TODO See how to get rid of this. Maybe define an "equals()" for HostAuth?
// The URI that represents this account's currently saved settings // The URI that represents this account's currently saved settings
protected URI mLoadedUri; protected URI mLoadedUri;
@ -60,6 +61,7 @@ public abstract class AccountServerBaseFragment extends Fragment
public Button mProceedButton; public Button mProceedButton;
// This is used to debounce multiple clicks on the proceed button (which does async work) // This is used to debounce multiple clicks on the proceed button (which does async work)
public boolean mProceedButtonPressed; public boolean mProceedButtonPressed;
/*package*/ String mBaseScheme = "protocol";
/** /**
* Callback interface that owning activities must provide * Callback interface that owning activities must provide

View File

@ -119,13 +119,13 @@ public class AccountSettingsUtils {
else if (xmlEventType == XmlResourceParser.START_TAG else if (xmlEventType == XmlResourceParser.START_TAG
&& "incoming".equals(xml.getName()) && "incoming".equals(xml.getName())
&& provider != null) { && provider != null) {
provider.incomingUriTemplate = new URI(getXmlAttribute(context, xml, "uri")); provider.incomingUriTemplate = getXmlAttribute(context, xml, "uri");
provider.incomingUsernameTemplate = getXmlAttribute(context, xml, "username"); provider.incomingUsernameTemplate = getXmlAttribute(context, xml, "username");
} }
else if (xmlEventType == XmlResourceParser.START_TAG else if (xmlEventType == XmlResourceParser.START_TAG
&& "outgoing".equals(xml.getName()) && "outgoing".equals(xml.getName())
&& provider != null) { && provider != null) {
provider.outgoingUriTemplate = new URI(getXmlAttribute(context, xml, "uri")); provider.outgoingUriTemplate = getXmlAttribute(context, xml, "uri");
provider.outgoingUsernameTemplate = getXmlAttribute(context, xml, "username"); provider.outgoingUsernameTemplate = getXmlAttribute(context, xml, "username");
} }
else if (xmlEventType == XmlResourceParser.END_TAG else if (xmlEventType == XmlResourceParser.END_TAG
@ -164,9 +164,9 @@ public class AccountSettingsUtils {
public String id; public String id;
public String label; public String label;
public String domain; public String domain;
public URI incomingUriTemplate; public String incomingUriTemplate;
public String incomingUsernameTemplate; public String incomingUsernameTemplate;
public URI outgoingUriTemplate; public String outgoingUriTemplate;
public String outgoingUsernameTemplate; public String outgoingUsernameTemplate;
public String note; public String note;
} }

View File

@ -116,24 +116,17 @@ public class AccountSetupAccountType extends AccountSetupActivity implements OnC
} }
/** /**
* The user has selected an exchange account type. Try to put together a URI using the entered * The user has selected an exchange account type. Set the mail delete policy here, because
* email address. Also set the mail delete policy here, because there is no UI (for exchange), * there is no UI (for exchange), and switch the default sync interval to "push".
* and switch the default sync interval to "push".
*/ */
private void onExchange() { private void onExchange() {
Account account = SetupData.getAccount(); Account account = SetupData.getAccount();
try { HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
URI uri = new URI(account.getStoreUri(this)); recvAuth.setConnection(
uri = new URI("eas+ssl+", uri.getUserInfo(), uri.getHost(), uri.getPort(), "eas", recvAuth.mAddress, recvAuth.mPort, recvAuth.mFlags | HostAuth.FLAG_SSL);
null, null, null); HostAuth sendAuth = account.getOrCreateHostAuthSend(this);
account.setStoreUri(this, uri.toString()); sendAuth.setConnection(
account.setSenderUri(this, uri.toString()); "eas", sendAuth.mAddress, sendAuth.mPort, sendAuth.mFlags | HostAuth.FLAG_SSL);
} catch (URISyntaxException use) {
/*
* This should not happen.
*/
throw new Error(use);
}
// TODO: Confirm correct delete policy for exchange // TODO: Confirm correct delete policy for exchange
account.setDeletePolicy(Account.DELETE_POLICY_ON_DELETE); account.setDeletePolicy(Account.DELETE_POLICY_ON_DELETE);
account.setSyncInterval(Account.CHECK_INTERVAL_PUSH); account.setSyncInterval(Account.CHECK_INTERVAL_PUSH);

View File

@ -22,6 +22,7 @@ import com.android.email.VendorPolicyLoader;
import com.android.email.activity.ActivityHelper; import com.android.email.activity.ActivityHelper;
import com.android.email.activity.Welcome; import com.android.email.activity.Welcome;
import com.android.email.activity.setup.AccountSettingsUtils.Provider; import com.android.email.activity.setup.AccountSettingsUtils.Provider;
import com.android.email.mail.Store;
import com.android.emailcommon.Logging; import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.EmailContent; import com.android.emailcommon.provider.EmailContent;
import com.android.emailcommon.provider.EmailContent.Account; import com.android.emailcommon.provider.EmailContent.Account;
@ -53,7 +54,6 @@ import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -421,47 +421,40 @@ public class AccountSetupBasics extends AccountSetupActivity
String[] emailParts = email.split("@"); String[] emailParts = email.split("@");
String user = emailParts[0]; String user = emailParts[0];
String domain = emailParts[1]; String domain = emailParts[1];
URI incomingUri = null;
URI outgoingUri = null;
String incomingUsername = mProvider.incomingUsernameTemplate;
try { try {
String incomingUsername = mProvider.incomingUsernameTemplate;
incomingUsername = incomingUsername.replaceAll("\\$email", email); incomingUsername = incomingUsername.replaceAll("\\$email", email);
incomingUsername = incomingUsername.replaceAll("\\$user", user); incomingUsername = incomingUsername.replaceAll("\\$user", user);
incomingUsername = incomingUsername.replaceAll("\\$domain", domain); incomingUsername = incomingUsername.replaceAll("\\$domain", domain);
URI incomingUriTemplate = mProvider.incomingUriTemplate; Account account = SetupData.getAccount();
incomingUri = new URI(incomingUriTemplate.getScheme(), incomingUsername + ":" HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
+ password, incomingUriTemplate.getHost(), incomingUriTemplate.getPort(), Utility.setHostAuthFromString(recvAuth, mProvider.incomingUriTemplate);
incomingUriTemplate.getPath(), null, null);
String outgoingUsername = mProvider.outgoingUsernameTemplate; String outgoingUsername = mProvider.outgoingUsernameTemplate;
outgoingUsername = outgoingUsername.replaceAll("\\$email", email); outgoingUsername = outgoingUsername.replaceAll("\\$email", email);
outgoingUsername = outgoingUsername.replaceAll("\\$user", user); outgoingUsername = outgoingUsername.replaceAll("\\$user", user);
outgoingUsername = outgoingUsername.replaceAll("\\$domain", domain); outgoingUsername = outgoingUsername.replaceAll("\\$domain", domain);
URI outgoingUriTemplate = mProvider.outgoingUriTemplate; HostAuth sendAuth = account.getOrCreateHostAuthSend(this);
outgoingUri = new URI(outgoingUriTemplate.getScheme(), outgoingUsername + ":" Utility.setHostAuthFromString(sendAuth, mProvider.outgoingUriTemplate);
+ password, outgoingUriTemplate.getHost(), outgoingUriTemplate.getPort(),
outgoingUriTemplate.getPath(), null, null);
} catch (URISyntaxException use) { // Populate the setup data, assuming that the duplicate account check will succeed
populateSetupData(getOwnerName(), email, mDefaultView.isChecked());
// Stop here if the login credentials duplicate an existing account
// Launch an Async task to do the work
new DuplicateCheckTask(this, recvAuth.mAddress, incomingUsername).execute();
} catch (URISyntaxException e) {
/* /*
* If there is some problem with the URI we give up and go on to * If there is some problem with the URI we give up and go on to manual setup.
* manual setup. Technically speaking, AutoDiscover is OK here, since user clicked * Technically speaking, AutoDiscover is OK here, since the user clicked "Next"
* "Next" to get here. This would never happen in practice because we don't expect * to get here. This will not happen in practice because we don't expect to
* to find any EAS accounts in the providers list. * find any EAS accounts in the providers list.
*/ */
onManualSetup(true); onManualSetup(true);
return;
} }
// Populate the setup data, assuming that the duplicate account check will succeed
populateSetupData(getOwnerName(), email, mDefaultView.isChecked(),
incomingUri.toString(), outgoingUri.toString());
// Stop here if the login credentials duplicate an existing account
// Launch an Async task to do the work
new DuplicateCheckTask(this, incomingUri.getHost(), incomingUsername).execute();
} }
/** /**
@ -561,18 +554,16 @@ public class AccountSetupBasics extends AccountSetupActivity
return; return;
} }
String uriString = null; Account account = SetupData.getAccount();
try { HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
URI uri = new URI("placeholder", user + ":" + password, domain, -1, null, null, null); recvAuth.setLogin(user, password);
uriString = uri.toString(); recvAuth.setConnection("placeholder", domain, HostAuth.PORT_UNKNOWN, HostAuth.FLAG_NONE);
} catch (URISyntaxException use) {
// If we can't set up the URL, don't continue - account setup pages will fail too
Toast.makeText(this, R.string.account_setup_username_password_toast,
Toast.LENGTH_LONG).show();
return;
}
populateSetupData(getOwnerName(), email, mDefaultView.isChecked(), uriString, uriString); HostAuth sendAuth = account.getOrCreateHostAuthSend(this);
sendAuth.setLogin(user, password);
sendAuth.setConnection("placeholder", domain, HostAuth.PORT_UNKNOWN, HostAuth.FLAG_NONE);
populateSetupData(getOwnerName(), email, mDefaultView.isChecked());
SetupData.setAllowAutodiscover(allowAutoDiscover); SetupData.setAllowAutodiscover(allowAutoDiscover);
AccountSetupAccountType.actionSelectAccountType(this); AccountSetupAccountType.actionSelectAccountType(this);
@ -590,31 +581,42 @@ public class AccountSetupBasics extends AccountSetupActivity
* @param outgoing The URI-style string defining the outgoing account * @param outgoing The URI-style string defining the outgoing account
*/ */
private void forceCreateAccount(String email, String user, String incoming, String outgoing) { private void forceCreateAccount(String email, String user, String incoming, String outgoing) {
populateSetupData(user, email, false, incoming, outgoing); Account account = SetupData.getAccount();
try {
HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
Utility.setHostAuthFromString(recvAuth, incoming);
HostAuth sendAuth = account.getOrCreateHostAuthSend(this);
Utility.setHostAuthFromString(sendAuth, outgoing);
populateSetupData(user, email, false);
} catch (URISyntaxException e) {
// If we can't set up the URL, don't continue - account setup pages will fail too
Toast.makeText(
this, R.string.account_setup_username_password_toast, Toast.LENGTH_LONG).show();
}
} }
/** /**
* Populate SetupData's account with complete setup info. * Populate SetupData's account with complete setup info.
*/ */
private void populateSetupData(String senderName, String senderEmail, boolean isDefault, private void populateSetupData(String senderName, String senderEmail, boolean isDefault) {
String incoming, String outgoing) {
Account account = SetupData.getAccount(); Account account = SetupData.getAccount();
account.setSenderName(senderName); account.setSenderName(senderName);
account.setEmailAddress(senderEmail); account.setEmailAddress(senderEmail);
account.setDisplayName(senderEmail); account.setDisplayName(senderEmail);
account.setDefaultAccount(isDefault); account.setDefaultAccount(isDefault);
SetupData.setDefault(isDefault); // TODO - why duplicated, if already set in account SetupData.setDefault(isDefault); // TODO - why duplicated, if already set in account
account.setStoreUri(this, incoming);
account.setSenderUri(this, outgoing);
// Set sync and delete policies for specific account types String protocol = account.mHostAuthRecv.mProtocol;
if (incoming.startsWith("imap")) { // Set sync and delete policies for specific inbound account types
if (Store.STORE_SCHEME_IMAP.equals(protocol)) {
// Delete policy must be set explicitly, because IMAP does not provide a UI selection // Delete policy must be set explicitly, because IMAP does not provide a UI selection
// for it. This logic needs to be followed in the auto setup flow as well. // for it. This logic needs to be followed in the auto setup flow as well.
account.setDeletePolicy(EmailContent.Account.DELETE_POLICY_ON_DELETE); account.setDeletePolicy(EmailContent.Account.DELETE_POLICY_ON_DELETE);
} }
if (incoming.startsWith("eas")) { if (Store.STORE_SCHEME_EAS.equals(protocol)) {
account.setSyncInterval(Account.CHECK_INTERVAL_PUSH); account.setSyncInterval(Account.CHECK_INTERVAL_PUSH);
} else { } else {
account.setSyncInterval(DEFAULT_ACCOUNT_CHECK_INTERVAL); account.setSyncInterval(DEFAULT_ACCOUNT_CHECK_INTERVAL);

View File

@ -20,8 +20,10 @@ import com.android.email.AccountBackupRestore;
import com.android.email.Email; import com.android.email.Email;
import com.android.email.ExchangeUtils; import com.android.email.ExchangeUtils;
import com.android.email.R; import com.android.email.R;
import com.android.email.mail.Store;
import com.android.emailcommon.Device; import com.android.emailcommon.Device;
import com.android.emailcommon.Logging; import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.EmailContent;
import com.android.emailcommon.provider.EmailContent.Account; import com.android.emailcommon.provider.EmailContent.Account;
import com.android.emailcommon.provider.EmailContent.HostAuth; import com.android.emailcommon.provider.EmailContent.HostAuth;
import com.android.emailcommon.utility.Utility; import com.android.emailcommon.utility.Utility;
@ -85,6 +87,7 @@ public class AccountSetupExchangeFragment extends AccountServerBaseFragment
mCacheLoginCredential = savedInstanceState.getString(STATE_KEY_CREDENTIAL); mCacheLoginCredential = savedInstanceState.getString(STATE_KEY_CREDENTIAL);
mLoaded = savedInstanceState.getBoolean(STATE_KEY_LOADED, false); mLoaded = savedInstanceState.getBoolean(STATE_KEY_LOADED, false);
} }
mBaseScheme = Store.STORE_SCHEME_EAS;
} }
@Override @Override
@ -255,11 +258,13 @@ public class AccountSetupExchangeFragment extends AccountServerBaseFragment
} }
boolean ssl = 0 != (hostAuth.mFlags & HostAuth.FLAG_SSL); boolean ssl = 0 != (hostAuth.mFlags & HostAuth.FLAG_SSL);
boolean trustCertificates = 0 != (hostAuth.mFlags & HostAuth.FLAG_TRUST_ALL_CERTIFICATES); boolean trustCertificates = 0 != (hostAuth.mFlags & HostAuth.FLAG_TRUST_ALL);
mSslSecurityView.setChecked(ssl); mSslSecurityView.setChecked(ssl);
mTrustCertificatesView.setChecked(trustCertificates); mTrustCertificatesView.setChecked(trustCertificates);
showTrustCertificates(ssl); showTrustCertificates(ssl);
// TODO See how to get rid of this. Maybe define an "equals()" for HostAuth?
// used to determine if these settings have changed
try { try {
mLoadedUri = getUri(); mLoadedUri = getUri();
} catch (URISyntaxException ignore) { } catch (URISyntaxException ignore) {
@ -357,11 +362,9 @@ public class AccountSetupExchangeFragment extends AccountServerBaseFragment
*/ */
@Override @Override
protected URI getUri() throws URISyntaxException { protected URI getUri() throws URISyntaxException {
Account account = SetupData.getAccount();
boolean sslRequired = mSslSecurityView.isChecked(); boolean sslRequired = mSslSecurityView.isChecked();
boolean trustCertificates = mTrustCertificatesView.isChecked(); boolean trustCertificates = mTrustCertificatesView.isChecked();
String scheme = (sslRequired)
? (trustCertificates ? "eas+ssl+trustallcerts" : "eas+ssl+")
: "eas";
String userName = mUsernameView.getText().toString().trim(); String userName = mUsernameView.getText().toString().trim();
// Remove a leading backslash, if there is one, since we now automatically put one at // Remove a leading backslash, if there is one, since we now automatically put one at
// the start of the username field // the start of the username field
@ -372,16 +375,18 @@ public class AccountSetupExchangeFragment extends AccountServerBaseFragment
String userInfo = userName + ":" + mPasswordView.getText(); String userInfo = userName + ":" + mPasswordView.getText();
String host = mServerView.getText().toString().trim(); String host = mServerView.getText().toString().trim();
String path = null; String path = null;
int port = mSslSecurityView.isChecked() ? 443 : 80;
// Ensure TLS is not set
int flags = account.getOrCreateHostAuthRecv(mContext).mFlags & ~HostAuth.FLAG_TLS;
URI uri = new URI( URI uri = new URI(
scheme, HostAuth.getSchemeString(mBaseScheme, flags),
userInfo, userInfo,
host, host,
0, port,
path, path,
null, null,
null); null);
return uri; return uri;
} }
@ -399,21 +404,38 @@ public class AccountSetupExchangeFragment extends AccountServerBaseFragment
*/ */
@Override @Override
public void onNext() { public void onNext() {
try { EmailContent.Account account = SetupData.getAccount();
URI uri = getUri();
Account setupAccount = SetupData.getAccount();
setupAccount.setStoreUri(mContext, uri.toString());
setupAccount.setSenderUri(mContext, uri.toString());
// Check for a duplicate account (requires async DB work) and if OK, proceed with check String userName = mUsernameView.getText().toString().trim();
startDuplicateTaskCheck(setupAccount.mId, uri.getHost(), mCacheLoginCredential, if (userName.startsWith("\\")) {
SetupData.CHECK_INCOMING); userName = userName.substring(1);
} catch (URISyntaxException use) {
/*
* It's unrecoverable if we cannot create a URI from components that
* we validated to be safe.
*/
throw new Error(use);
} }
mCacheLoginCredential = userName;
String userPassword = mPasswordView.getText().toString();
int flags = 0;
if (mSslSecurityView.isChecked()) {
flags |= HostAuth.FLAG_SSL;
}
if (mTrustCertificatesView.isChecked()) {
flags |= HostAuth.FLAG_TRUST_ALL;
}
String serverAddress = mServerView.getText().toString().trim();
int port = mSslSecurityView.isChecked() ? 443 : 80;
HostAuth sendAuth = account.getOrCreateHostAuthSend(mContext);
sendAuth.setLogin(userName, userPassword);
sendAuth.setConnection(mBaseScheme, serverAddress, port, flags);
sendAuth.mDomain = null;
HostAuth recvAuth = account.getOrCreateHostAuthRecv(mContext);
recvAuth.setLogin(userName, userPassword);
recvAuth.setConnection(mBaseScheme, serverAddress, port, flags);
recvAuth.mDomain = null;
// Check for a duplicate account (requires async DB work) and if OK, proceed with check
startDuplicateTaskCheck(account.mId, serverAddress, mCacheLoginCredential,
SetupData.CHECK_INCOMING);
} }
} }

View File

@ -19,9 +19,10 @@ package com.android.email.activity.setup;
import com.android.email.AccountBackupRestore; import com.android.email.AccountBackupRestore;
import com.android.email.Email; import com.android.email.Email;
import com.android.email.R; import com.android.email.R;
import com.android.email.mail.Store;
import com.android.emailcommon.Logging; import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.EmailContent;
import com.android.emailcommon.provider.EmailContent.Account; import com.android.emailcommon.provider.EmailContent.Account;
import com.android.emailcommon.provider.EmailContent.HostAuth;
import com.android.emailcommon.utility.Utility; import com.android.emailcommon.utility.Utility;
import android.app.Activity; import android.app.Activity;
@ -54,21 +55,12 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment {
private final static String STATE_KEY_CREDENTIAL = "AccountSetupIncomingFragment.credential"; private final static String STATE_KEY_CREDENTIAL = "AccountSetupIncomingFragment.credential";
private final static String STATE_KEY_LOADED = "AccountSetupIncomingFragment.loaded"; private final static String STATE_KEY_LOADED = "AccountSetupIncomingFragment.loaded";
private static final int POP_PORTS[] = { private static final int POP3_PORT_NORMAL = 110;
110, 995, 995, 110, 110 private static final int POP3_PORT_SSL = 995;
};
private static final String POP_SCHEMES[] = { private static final int IMAP_PORT_NORMAL = 143;
"pop3", "pop3+ssl+", "pop3+ssl+trustallcerts", "pop3+tls+", "pop3+tls+trustallcerts" private static final int IMAP_PORT_SSL = 993;
};
private static final int IMAP_PORTS[] = {
143, 993, 993, 143, 143
};
private static final String IMAP_SCHEMES[] = {
"imap", "imap+ssl+", "imap+ssl+trustallcerts", "imap+tls+", "imap+tls+trustallcerts"
};
private int mAccountPorts[];
private String mAccountSchemes[];
private EditText mUsernameView; private EditText mUsernameView;
private EditText mPasswordView; private EditText mPasswordView;
private TextView mServerLabelView; private TextView mServerLabelView;
@ -131,18 +123,16 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment {
// Set up spinners // Set up spinners
SpinnerOption securityTypes[] = { SpinnerOption securityTypes[] = {
new SpinnerOption(0, new SpinnerOption(HostAuth.FLAG_NONE, context.getString(
context.getString(R.string.account_setup_incoming_security_none_label)), R.string.account_setup_incoming_security_none_label)),
new SpinnerOption(1, new SpinnerOption(HostAuth.FLAG_SSL, context.getString(
context.getString(R.string.account_setup_incoming_security_ssl_label)), R.string.account_setup_incoming_security_ssl_label)),
new SpinnerOption(2, new SpinnerOption(HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL, context.getString(
context.getString( R.string.account_setup_incoming_security_ssl_trust_certificates_label)),
R.string.account_setup_incoming_security_ssl_trust_certificates_label)), new SpinnerOption(HostAuth.FLAG_TLS, context.getString(
new SpinnerOption(3, R.string.account_setup_incoming_security_tls_label)),
context.getString(R.string.account_setup_incoming_security_tls_label)), new SpinnerOption(HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL, context.getString(
new SpinnerOption(4, R.string.account_setup_incoming_security_tls_trust_certificates_label)),
context.getString(
R.string.account_setup_incoming_security_tls_trust_certificates_label)),
}; };
SpinnerOption deletePolicies[] = { SpinnerOption deletePolicies[] = {
@ -290,16 +280,12 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment {
private void configureEditor() { private void configureEditor() {
if (mConfigured) return; if (mConfigured) return;
Account account = SetupData.getAccount(); Account account = SetupData.getAccount();
String protocol = account.mHostAuthRecv.mProtocol; mBaseScheme = account.mHostAuthRecv.mProtocol;
if (protocol.startsWith("pop3")) { if (Store.STORE_SCHEME_POP3.equals(mBaseScheme)) {
mServerLabelView.setText(R.string.account_setup_incoming_pop_server_label); mServerLabelView.setText(R.string.account_setup_incoming_pop_server_label);
mAccountPorts = POP_PORTS;
mAccountSchemes = POP_SCHEMES;
mImapPathPrefixSectionView.setVisibility(View.GONE); mImapPathPrefixSectionView.setVisibility(View.GONE);
} else if (protocol.startsWith("imap")) { } else if (Store.STORE_SCHEME_IMAP.equals(mBaseScheme)) {
mServerLabelView.setText(R.string.account_setup_incoming_imap_server_label); mServerLabelView.setText(R.string.account_setup_incoming_imap_server_label);
mAccountPorts = IMAP_PORTS;
mAccountSchemes = IMAP_SCHEMES;
mDeletePolicyLabelView.setVisibility(View.GONE); mDeletePolicyLabelView.setVisibility(View.GONE);
mDeletePolicyView.setVisibility(View.GONE); mDeletePolicyView.setVisibility(View.GONE);
} else { } else {
@ -313,61 +299,49 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment {
*/ */
private void loadSettings() { private void loadSettings() {
if (mLoaded) return; if (mLoaded) return;
try {
// TODO this should be accessed directly via the HostAuth structure
EmailContent.Account account = SetupData.getAccount();
URI uri = new URI(account.getStoreUri(mContext));
String username = null;
String password = null;
if (uri.getUserInfo() != null) {
String[] userInfoParts = uri.getUserInfo().split(":", 2);
username = userInfoParts[0];
if (userInfoParts.length > 1) {
password = userInfoParts[1];
}
}
if (username != null) { Account account = SetupData.getAccount();
mUsernameView.setText(username); HostAuth recvAuth = account.getOrCreateHostAuthRecv(mContext);
}
if (password != null) { String username = recvAuth.mLogin;
mPasswordView.setText(password); if (username != null) {
} mUsernameView.setText(username);
}
if (uri.getScheme().startsWith("pop3")) { String password = recvAuth.mPassword;
mLoadedDeletePolicy = account.getDeletePolicy(); if (password != null) {
SpinnerOption.setSpinnerOptionValue(mDeletePolicyView, mLoadedDeletePolicy); mPasswordView.setText(password);
} else if (uri.getScheme().startsWith("imap")) {
if (uri.getPath() != null && uri.getPath().length() > 0) {
mImapPathPrefixView.setText(uri.getPath().substring(1));
}
} else {
throw new Error("Unknown account type: " + account.getStoreUri(mContext));
}
for (int i = 0; i < mAccountSchemes.length; i++) {
if (mAccountSchemes[i].equals(uri.getScheme())) {
SpinnerOption.setSpinnerOptionValue(mSecurityTypeView, i);
}
}
if (uri.getHost() != null) {
mServerView.setText(uri.getHost());
}
if (uri.getPort() != -1) {
mPortView.setText(Integer.toString(uri.getPort()));
} else {
updatePortFromSecurityType();
}
} catch (URISyntaxException use) {
/*
* We should always be able to parse our own settings.
*/
throw new Error(use);
} }
if (Store.STORE_SCHEME_POP3.equals(recvAuth.mProtocol)) {
mLoadedDeletePolicy = account.getDeletePolicy();
SpinnerOption.setSpinnerOptionValue(mDeletePolicyView, mLoadedDeletePolicy);
} else if (Store.STORE_SCHEME_IMAP.equals(recvAuth.mProtocol)) {
String prefix = recvAuth.mDomain;
if (prefix != null && prefix.length() > 0) {
mImapPathPrefixView.setText(prefix.substring(1));
}
} else {
throw new Error("Unknown account type: " + account.getStoreUri(mContext));
}
int flags = recvAuth.mFlags;
flags &= ~HostAuth.FLAG_AUTHENTICATE;
SpinnerOption.setSpinnerOptionValue(mSecurityTypeView, flags);
String hostname = recvAuth.mAddress;
if (hostname != null) {
mServerView.setText(hostname);
}
int port = recvAuth.mPort;
if (port != HostAuth.PORT_UNKNOWN) {
mPortView.setText(Integer.toString(port));
} else {
updatePortFromSecurityType();
}
// TODO See how to get rid of this. Maybe define an "equals()" for HostAuth?
// used to determine if these settings have changed
try { try {
mLoadedUri = getUri(); mLoadedUri = getUri();
} catch (URISyntaxException ignore) { } catch (URISyntaxException ignore) {
@ -400,9 +374,19 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment {
AccountSettingsUtils.checkPasswordSpaces(mContext, mPasswordView); AccountSettingsUtils.checkPasswordSpaces(mContext, mPasswordView);
} }
private void updatePortFromSecurityType() { private int getPortFromSecurityType() {
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value; int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
mPortView.setText(Integer.toString(mAccountPorts[securityType])); boolean useSsl = ((securityType & HostAuth.FLAG_SSL) != 0);
int port = useSsl ? IMAP_PORT_SSL : IMAP_PORT_NORMAL; // default to IMAP
if (Store.STORE_SCHEME_POP3.equals(mBaseScheme)) {
port = useSsl ? POP3_PORT_SSL : POP3_PORT_NORMAL;
}
return port;
}
private void updatePortFromSecurityType() {
int port = getPortFromSecurityType();
mPortView.setText(Integer.toString(port));
} }
/** /**
@ -425,28 +409,16 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment {
*/ */
@Override @Override
public void saveSettingsAfterSetup() { public void saveSettingsAfterSetup() {
EmailContent.Account account = SetupData.getAccount(); Account account = SetupData.getAccount();
HostAuth recvAuth = account.getOrCreateHostAuthRecv(mContext);
HostAuth sendAuth = account.getOrCreateHostAuthSend(mContext);
// Set the username and password for the outgoing settings to the username and // Set the username and password for the outgoing settings to the username and
// password the user just set for incoming. Use the verified host address to try and // password the user just set for incoming. Use the verified host address to try and
// pick a smarter outgoing address. // pick a smarter outgoing address.
try { String hostName = AccountSettingsUtils.inferServerName(recvAuth.mAddress, null, "smtp");
String hostName = sendAuth.setLogin(recvAuth.mLogin, recvAuth.mPassword);
AccountSettingsUtils.inferServerName(account.mHostAuthRecv.mAddress, null, "smtp"); sendAuth.setConnection(sendAuth.mProtocol, hostName, sendAuth.mPort, sendAuth.mFlags);
URI oldUri = new URI(account.getSenderUri(mContext));
URI uri = new URI(
oldUri.getScheme(),
mUsernameView.getText().toString().trim() + ":"
+ mPasswordView.getText().toString(),
hostName,
oldUri.getPort(),
null,
null,
null);
account.setSenderUri(mContext, uri.toString());
} catch (URISyntaxException use) {
// If we can't set up the URL we just continue. It's only for convenience.
}
} }
/** /**
@ -458,20 +430,23 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment {
protected URI getUri() throws URISyntaxException { protected URI getUri() throws URISyntaxException {
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value; int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
String path = null; String path = null;
if (mAccountSchemes[securityType].startsWith("imap")) { if (Store.STORE_SCHEME_IMAP.equals(mBaseScheme)) {
path = "/" + mImapPathPrefixView.getText().toString().trim(); path = "/" + mImapPathPrefixView.getText().toString().trim();
} }
String userName = mUsernameView.getText().toString().trim(); String userName = mUsernameView.getText().toString().trim();
mCacheLoginCredential = userName; mCacheLoginCredential = userName;
String userInfo = userName + ":" + mPasswordView.getText();
String host = mServerView.getText().toString().trim();
int port = Integer.parseInt(mPortView.getText().toString().trim());
URI uri = new URI( URI uri = new URI(
mAccountSchemes[securityType], HostAuth.getSchemeString(mBaseScheme, securityType),
userName + ":" + mPasswordView.getText(), userInfo,
mServerView.getText().toString().trim(), host,
Integer.parseInt(mPortView.getText().toString().trim()), port,
path, // path path, // path
null, // query null, // query
null); null);
return uri; return uri;
} }
@ -480,25 +455,32 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment {
*/ */
@Override @Override
public void onNext() { public void onNext() {
EmailContent.Account setupAccount = SetupData.getAccount(); Account account = SetupData.getAccount();
setupAccount.setDeletePolicy( account.setDeletePolicy(
(Integer)((SpinnerOption)mDeletePolicyView.getSelectedItem()).value); (Integer) ((SpinnerOption) mDeletePolicyView.getSelectedItem()).value);
HostAuth recvAuth = account.getOrCreateHostAuthRecv(mContext);
String userName = mUsernameView.getText().toString().trim();
String userPassword = mPasswordView.getText().toString();
recvAuth.setLogin(userName, userPassword);
String serverAddress = mServerView.getText().toString().trim();
int serverPort;
try { try {
URI uri = getUri(); serverPort = Integer.parseInt(mPortView.getText().toString().trim());
setupAccount.setStoreUri(mContext, uri.toString()); } catch (NumberFormatException e) {
serverPort = getPortFromSecurityType();
// Check for a duplicate account (requires async DB work) and if OK, proceed with check Log.d(Logging.LOG_TAG, "Non-integer server port; using '" + serverPort + "'");
startDuplicateTaskCheck(setupAccount.mId, uri.getHost(), mCacheLoginCredential,
SetupData.CHECK_INCOMING);
} catch (URISyntaxException use) {
/*
* It's unrecoverable if we cannot create a URI from components that
* we validated to be safe.
*/
throw new Error(use);
} }
int securityType = (Integer) ((SpinnerOption) mSecurityTypeView.getSelectedItem()).value;
recvAuth.setConnection(mBaseScheme, serverAddress, serverPort, securityType);
recvAuth.mDomain = null;
// Check for a duplicate account (requires async DB work) and if OK,
// proceed with check
startDuplicateTaskCheck(
account.mId, serverAddress, mCacheLoginCredential, SetupData.CHECK_INCOMING);
} }
@Override @Override

View File

@ -22,6 +22,7 @@ import com.android.email.R;
import com.android.emailcommon.Logging; import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.EmailContent; import com.android.emailcommon.provider.EmailContent;
import com.android.emailcommon.provider.EmailContent.Account; import com.android.emailcommon.provider.EmailContent.Account;
import com.android.emailcommon.provider.EmailContent.HostAuth;
import com.android.emailcommon.utility.Utility; import com.android.emailcommon.utility.Utility;
import android.app.Activity; import android.app.Activity;
@ -56,13 +57,8 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
private final static String STATE_KEY_LOADED = "AccountSetupOutgoingFragment.loaded"; private final static String STATE_KEY_LOADED = "AccountSetupOutgoingFragment.loaded";
private static final int SMTP_PORTS[] = { private static final int SMTP_PORT_NORMAL = 587;
587, 465, 465, 587, 587 private static final int SMTP_PORT_SSL = 465;
};
private static final String SMTP_SCHEMES[] = {
"smtp", "smtp+ssl+", "smtp+ssl+trustallcerts", "smtp+tls+", "smtp+tls+trustallcerts"
};
private EditText mUsernameView; private EditText mUsernameView;
private EditText mPasswordView; private EditText mPasswordView;
@ -91,6 +87,7 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
if (savedInstanceState != null) { if (savedInstanceState != null) {
mLoaded = savedInstanceState.getBoolean(STATE_KEY_LOADED, false); mLoaded = savedInstanceState.getBoolean(STATE_KEY_LOADED, false);
} }
mBaseScheme = "smtp";
} }
@Override @Override
@ -118,15 +115,15 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
// Note: Strings are shared with AccountSetupIncomingFragment // Note: Strings are shared with AccountSetupIncomingFragment
SpinnerOption securityTypes[] = { SpinnerOption securityTypes[] = {
new SpinnerOption(0, context.getString( new SpinnerOption(HostAuth.FLAG_NONE, context.getString(
R.string.account_setup_incoming_security_none_label)), R.string.account_setup_incoming_security_none_label)),
new SpinnerOption(1, context.getString( new SpinnerOption(HostAuth.FLAG_SSL, context.getString(
R.string.account_setup_incoming_security_ssl_label)), R.string.account_setup_incoming_security_ssl_label)),
new SpinnerOption(2, context.getString( new SpinnerOption(HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL, context.getString(
R.string.account_setup_incoming_security_ssl_trust_certificates_label)), R.string.account_setup_incoming_security_ssl_trust_certificates_label)),
new SpinnerOption(3, context.getString( new SpinnerOption(HostAuth.FLAG_TLS, context.getString(
R.string.account_setup_incoming_security_tls_label)), R.string.account_setup_incoming_security_tls_label)),
new SpinnerOption(4, context.getString( new SpinnerOption(HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL, context.getString(
R.string.account_setup_incoming_security_tls_trust_certificates_label)), R.string.account_setup_incoming_security_tls_trust_certificates_label)),
}; };
@ -258,50 +255,38 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
*/ */
private void loadSettings() { private void loadSettings() {
if (mLoaded) return; if (mLoaded) return;
try {
// TODO this should be accessed directly via the HostAuth structure
URI uri = new URI(SetupData.getAccount().getSenderUri(mContext));
String username = null;
String password = null;
if (uri.getUserInfo() != null) {
String[] userInfoParts = uri.getUserInfo().split(":", 2);
username = userInfoParts[0];
if (userInfoParts.length > 1) {
password = userInfoParts[1];
}
}
HostAuth senderAuth = SetupData.getAccount().getOrCreateHostAuthSend(mContext);
if ((senderAuth.mFlags & HostAuth.FLAG_AUTHENTICATE) != 0) {
String username = senderAuth.mLogin;
if (username != null) { if (username != null) {
mUsernameView.setText(username); mUsernameView.setText(username);
mRequireLoginView.setChecked(true); mRequireLoginView.setChecked(true);
} }
String password = senderAuth.mPassword;
if (password != null) { if (password != null) {
mPasswordView.setText(password); mPasswordView.setText(password);
} }
for (int i = 0; i < SMTP_SCHEMES.length; i++) {
if (SMTP_SCHEMES[i].equals(uri.getScheme())) {
SpinnerOption.setSpinnerOptionValue(mSecurityTypeView, i);
}
}
if (uri.getHost() != null) {
mServerView.setText(uri.getHost());
}
if (uri.getPort() != -1) {
mPortView.setText(Integer.toString(uri.getPort()));
} else {
updatePortFromSecurityType();
}
} catch (URISyntaxException use) {
/*
* We should always be able to parse our own settings.
*/
throw new Error(use);
} }
int flags = senderAuth.mFlags & ~HostAuth.FLAG_AUTHENTICATE;
SpinnerOption.setSpinnerOptionValue(mSecurityTypeView, flags);
String hostname = senderAuth.mAddress;
if (hostname != null) {
mServerView.setText(hostname);
}
int port = senderAuth.mPort;
if (port != -1) {
mPortView.setText(Integer.toString(port));
} else {
updatePortFromSecurityType();
}
// TODO See how to get rid of this. Maybe define an "equals()" for HostAuth?
// used to determine if these settings have changed
try { try {
mLoadedUri = getUri(); mLoadedUri = getUri();
} catch (URISyntaxException ignore) { } catch (URISyntaxException ignore) {
@ -350,9 +335,15 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
validateFields(); validateFields();
} }
private void updatePortFromSecurityType() { private int getPortFromSecurityType() {
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value; int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
mPortView.setText(Integer.toString(SMTP_PORTS[securityType])); int port = (securityType & HostAuth.FLAG_SSL) != 0 ? SMTP_PORT_SSL : SMTP_PORT_NORMAL;
return port;
}
private void updatePortFromSecurityType() {
int port = getPortFromSecurityType();
mPortView.setText(Integer.toString(port));
} }
/** /**
@ -386,12 +377,18 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
if (mRequireLoginView.isChecked()) { if (mRequireLoginView.isChecked()) {
userInfo = mUsernameView.getText().toString().trim() + ":" + mPasswordView.getText(); userInfo = mUsernameView.getText().toString().trim() + ":" + mPasswordView.getText();
} }
String host = mServerView.getText().toString().trim();
String path = null;
int port = Integer.parseInt(mPortView.getText().toString().trim());
URI uri = new URI( URI uri = new URI(
SMTP_SCHEMES[securityType], HostAuth.getSchemeString(mBaseScheme, securityType),
userInfo, userInfo,
mServerView.getText().toString().trim(), host,
Integer.parseInt(mPortView.getText().toString().trim()), port,
null, null, null); path,
null,
null);
return uri; return uri;
} }
@ -401,17 +398,23 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
@Override @Override
public void onNext() { public void onNext() {
EmailContent.Account account = SetupData.getAccount(); EmailContent.Account account = SetupData.getAccount();
HostAuth sendAuth = account.getOrCreateHostAuthSend(mContext);
String userName = mUsernameView.getText().toString().trim();
String userPassword = mPasswordView.getText().toString();
sendAuth.setLogin(userName, userPassword);
String serverAddress = mServerView.getText().toString().trim();
int serverPort;
try { try {
// TODO this should be accessed directly via the HostAuth structure serverPort = Integer.parseInt(mPortView.getText().toString().trim());
URI uri = getUri(); } catch (NumberFormatException e) {
account.setSenderUri(mContext, uri.toString()); serverPort = getPortFromSecurityType();
} catch (URISyntaxException use) { Log.d(Logging.LOG_TAG, "Non-integer server port; using '" + serverPort + "'");
/*
* It's unrecoverable if we cannot create a URI from components that
* we validated to be safe.
*/
throw new Error(use);
} }
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
sendAuth.setConnection(mBaseScheme, serverAddress, serverPort, securityType);
sendAuth.mDomain = null;
mCallback.onProceedNext(SetupData.CHECK_OUTGOING, this); mCallback.onProceedNext(SetupData.CHECK_OUTGOING, this);
} }

View File

@ -32,6 +32,7 @@ import android.os.Environment;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.os.RemoteException; import android.os.RemoteException;
import android.text.TextUtils;
import java.io.File; import java.io.File;
import java.net.URI; import java.net.URI;
@ -454,6 +455,7 @@ public abstract class EmailContent {
public static final String DELETED_TABLE_NAME = "Message_Deletes"; public static final String DELETED_TABLE_NAME = "Message_Deletes";
// To refer to a specific message, use ContentUris.withAppendedId(CONTENT_URI, id) // To refer to a specific message, use ContentUris.withAppendedId(CONTENT_URI, id)
@SuppressWarnings("hiding")
public static final Uri CONTENT_URI = Uri.parse(EmailContent.CONTENT_URI + "/message"); public static final Uri CONTENT_URI = Uri.parse(EmailContent.CONTENT_URI + "/message");
public static final Uri CONTENT_URI_LIMIT_1 = uriWithLimit(CONTENT_URI, 1); public static final Uri CONTENT_URI_LIMIT_1 = uriWithLimit(CONTENT_URI, 1);
public static final Uri SYNCED_CONTENT_URI = public static final Uri SYNCED_CONTENT_URI =
@ -965,6 +967,7 @@ public abstract class EmailContent {
public static final class Account extends EmailContent implements AccountColumns, Parcelable { public static final class Account extends EmailContent implements AccountColumns, Parcelable {
public static final String TABLE_NAME = "Account"; public static final String TABLE_NAME = "Account";
@SuppressWarnings("hiding")
public static final Uri CONTENT_URI = Uri.parse(EmailContent.CONTENT_URI + "/account"); public static final Uri CONTENT_URI = Uri.parse(EmailContent.CONTENT_URI + "/account");
public static final Uri ADD_TO_FIELD_URI = public static final Uri ADD_TO_FIELD_URI =
Uri.parse(EmailContent.CONTENT_URI + "/accountIdAddToField"); Uri.parse(EmailContent.CONTENT_URI + "/accountIdAddToField");
@ -1353,37 +1356,7 @@ public abstract class EmailContent {
return ""; return "";
} }
/** public HostAuth getOrCreateHostAuthSend(Context context) {
* For compatibility while converting to provider model, set the store URI
*
* @param context
* @param storeUri the new value
*/
@Deprecated
public void setStoreUri(Context context, String storeUri) {
// reconstitute or create if necessary
if (mHostAuthRecv == null) {
if (mHostAuthKeyRecv != 0) {
mHostAuthRecv = HostAuth.restoreHostAuthWithId(context, mHostAuthKeyRecv);
} else {
mHostAuthRecv = new EmailContent.HostAuth();
}
}
if (mHostAuthRecv != null) {
mHostAuthRecv.setStoreUri(storeUri);
}
}
/**
* For compatibility while converting to provider model, set the sender URI
*
* @param context
* @param senderUri the new value
*/
@Deprecated
public void setSenderUri(Context context, String senderUri) {
// reconstitute or create if necessary
if (mHostAuthSend == null) { if (mHostAuthSend == null) {
if (mHostAuthKeySend != 0) { if (mHostAuthKeySend != 0) {
mHostAuthSend = HostAuth.restoreHostAuthWithId(context, mHostAuthKeySend); mHostAuthSend = HostAuth.restoreHostAuthWithId(context, mHostAuthKeySend);
@ -1391,10 +1364,18 @@ public abstract class EmailContent {
mHostAuthSend = new EmailContent.HostAuth(); mHostAuthSend = new EmailContent.HostAuth();
} }
} }
return mHostAuthSend;
}
if (mHostAuthSend != null) { public HostAuth getOrCreateHostAuthRecv(Context context) {
mHostAuthSend.setStoreUri(senderUri); if (mHostAuthRecv == null) {
if (mHostAuthKeyRecv != 0) {
mHostAuthRecv = HostAuth.restoreHostAuthWithId(context, mHostAuthKeyRecv);
} else {
mHostAuthRecv = new EmailContent.HostAuth();
}
} }
return mHostAuthRecv;
} }
/** /**
@ -2569,10 +2550,15 @@ public abstract class EmailContent {
@SuppressWarnings("hiding") @SuppressWarnings("hiding")
public static final Uri CONTENT_URI = Uri.parse(EmailContent.CONTENT_URI + "/hostauth"); public static final Uri CONTENT_URI = Uri.parse(EmailContent.CONTENT_URI + "/hostauth");
public static final int FLAG_SSL = 1; public static final int PORT_UNKNOWN = -1;
public static final int FLAG_TLS = 2;
public static final int FLAG_AUTHENTICATE = 4; public static final int FLAG_NONE = 0x00; // No flags
public static final int FLAG_TRUST_ALL_CERTIFICATES = 8; public static final int FLAG_SSL = 0x01; // Use SSL
public static final int FLAG_TLS = 0x02; // Use TLS
public static final int FLAG_AUTHENTICATE = 0x04; // Use name/password for authentication
public static final int FLAG_TRUST_ALL = 0x08; // Trust all certificates
// Mask of settings directly configurable by the user
public static final int USER_CONFIG_MASK = 0x0b;
public String mProtocol; public String mProtocol;
public String mAddress; public String mAddress;
@ -2581,6 +2567,7 @@ public abstract class EmailContent {
public String mLogin; public String mLogin;
public String mPassword; public String mPassword;
public String mDomain; public String mDomain;
// TODO Remove all vestiges of this
public long mAccountKey; // DEPRECATED - Will not be set or stored public long mAccountKey; // DEPRECATED - Will not be set or stored
public static final int CONTENT_ID_COLUMN = 0; public static final int CONTENT_ID_COLUMN = 0;
@ -2607,7 +2594,7 @@ public abstract class EmailContent {
mBaseUri = CONTENT_URI; mBaseUri = CONTENT_URI;
// other defaults policy) // other defaults policy)
mPort = -1; mPort = PORT_UNKNOWN;
} }
/** /**
@ -2632,6 +2619,52 @@ public abstract class EmailContent {
} }
} }
/**
* Returns the scheme for the specified flags.
*/
public static String getSchemeString(String protocol, int flags) {
String security = "";
switch (flags & USER_CONFIG_MASK) {
case FLAG_SSL:
security = "+ssl+";
break;
case FLAG_SSL | FLAG_TRUST_ALL:
security = "+ssl+trustallcerts";
break;
case FLAG_TLS:
security = "+tls+";
break;
case FLAG_TLS | FLAG_TRUST_ALL:
security = "+tls+trustallcerts";
break;
}
return protocol + security;
}
/**
* Returns the flags for the specified scheme.
*/
public static int getSchemeFlags(String scheme) {
String[] schemeParts = scheme.split("\\+");
int flags = HostAuth.FLAG_NONE;
if (schemeParts.length >= 2) {
String part1 = schemeParts[1];
if ("ssl".equals(part1)) {
flags |= HostAuth.FLAG_SSL;
} else if ("tls".equals(part1)) {
flags |= HostAuth.FLAG_TLS;
}
if (schemeParts.length >= 3) {
String part2 = schemeParts[2];
if ("trustallcerts".equals(part2)) {
flags |= HostAuth.FLAG_TRUST_ALL;
}
}
}
return flags;
}
@Override @Override
public void restore(Cursor cursor) { public void restore(Cursor cursor) {
mBaseUri = CONTENT_URI; mBaseUri = CONTENT_URI;
@ -2667,37 +2700,20 @@ public abstract class EmailContent {
* @return a string in the form of a Uri, as used by the other parts of the email app * @return a string in the form of a Uri, as used by the other parts of the email app
*/ */
public String getStoreUri() { public String getStoreUri() {
String security;
switch (mFlags & (FLAG_SSL | FLAG_TLS | FLAG_TRUST_ALL_CERTIFICATES)) {
case FLAG_SSL:
security = "+ssl+";
break;
case FLAG_SSL | FLAG_TRUST_ALL_CERTIFICATES:
security = "+ssl+trustallcerts";
break;
case FLAG_TLS:
security = "+tls+";
break;
case FLAG_TLS | FLAG_TRUST_ALL_CERTIFICATES:
security = "+tls+trustallcerts";
break;
default:
security = "";
break;
}
String userInfo = null; String userInfo = null;
if ((mFlags & FLAG_AUTHENTICATE) != 0) { if ((mFlags & FLAG_AUTHENTICATE) != 0) {
String trimUser = (mLogin != null) ? mLogin.trim() : ""; String trimUser = (mLogin != null) ? mLogin.trim() : "";
String password = (mPassword != null) ? mPassword : ""; String password = (mPassword != null) ? mPassword : "";
userInfo = trimUser + ":" + password; userInfo = trimUser + ":" + password;
} }
String scheme = getSchemeString(mProtocol, mFlags);
String address = (mAddress != null) ? mAddress.trim() : null; String address = (mAddress != null) ? mAddress.trim() : null;
String path = (mDomain != null) ? "/" + mDomain : null; String path = (mDomain != null) ? "/" + mDomain : null;
URI uri; URI uri;
try { try {
uri = new URI( uri = new URI(
mProtocol + security, scheme,
userInfo, userInfo,
address, address,
mPort, mPort,
@ -2711,77 +2727,73 @@ public abstract class EmailContent {
} }
/** /**
* For compatibility while converting to provider model, set fields from a "store URI" * Sets the user name and password from URI user info string
*
* @param uriString a String containing a Uri
*/ */
@Deprecated public void setLogin(String userInfo) {
public void setStoreUri(String uriString) { String userName = null;
try { String userPassword = null;
URI uri = new URI(uriString); if (!TextUtils.isEmpty(userInfo)) {
mLogin = null; String[] userInfoParts = userInfo.split(":", 2);
mPassword = null; userName = userInfoParts[0];
mFlags &= ~FLAG_AUTHENTICATE; if (userInfoParts.length > 1) {
if (uri.getUserInfo() != null) { userPassword = userInfoParts[1];
String[] userInfoParts = uri.getUserInfo().split(":", 2);
mLogin = userInfoParts[0];
mFlags |= FLAG_AUTHENTICATE;
if (userInfoParts.length > 1) {
mPassword = userInfoParts[1];
}
} }
// Set protocol, security, and additional flags based on uri scheme
String[] schemeParts = uri.getScheme().split("\\+");
mProtocol = (schemeParts.length >= 1) ? schemeParts[0] : null;
mFlags &= ~(FLAG_SSL | FLAG_TLS | FLAG_TRUST_ALL_CERTIFICATES);
boolean ssl = false;
if (schemeParts.length >= 2) {
String part1 = schemeParts[1];
if ("ssl".equals(part1)) {
ssl = true;
mFlags |= FLAG_SSL;
} else if ("tls".equals(part1)) {
mFlags |= FLAG_TLS;
}
if (schemeParts.length >= 3) {
String part2 = schemeParts[2];
if ("trustallcerts".equals(part2)) {
mFlags |= FLAG_TRUST_ALL_CERTIFICATES;
}
}
}
mAddress = uri.getHost();
mPort = uri.getPort();
if (mPort == -1) {
// infer port# from protocol + security
// SSL implies a different port - TLS runs in the "regular" port
// TODO: This really shouldn't be here - it should have been set up
// in the account setup screens.
if ("pop3".equals(mProtocol)) {
mPort = ssl ? 995 : 110;
} else if ("imap".equals(mProtocol)) {
mPort = ssl ? 993 : 143;
} else if ("eas".equals(mProtocol)) {
mPort = ssl ? 443 : 80;
} else if ("smtp".equals(mProtocol)) {
mPort = ssl ? 465 : 587;
}
}
if (uri.getPath() != null && uri.getPath().length() > 0) {
mDomain = uri.getPath().substring(1);
}
} catch (URISyntaxException use) {
/*
* We should always be able to parse our own settings.
*/
throw new Error(use);
} }
setLogin(userName, userPassword);
}
/**
* Sets the user name and password
*/
public void setLogin(String userName, String userPassword) {
mLogin = userName;
mPassword = userPassword;
if (mLogin == null) {
mFlags &= ~FLAG_AUTHENTICATE;
} else {
mFlags |= FLAG_AUTHENTICATE;
}
}
/**
* Sets the connection values of the auth structure per the given scheme, host and port.
*/
public void setConnection(String scheme, String host, int port) {
String[] schemeParts = scheme.split("\\+");
String protocol = schemeParts[0];
int flags = getSchemeFlags(scheme);
setConnection(protocol, host, port, flags);
}
public void setConnection(String protocol, String address, int port, int flags) {
// Set protocol, security, and additional flags based on uri scheme
mProtocol = protocol;
mFlags &= ~(FLAG_SSL | FLAG_TLS | FLAG_TRUST_ALL);
mFlags |= (flags & USER_CONFIG_MASK);
mAddress = address;
mPort = port;
if (mPort == PORT_UNKNOWN) {
boolean useSSL = ((mFlags & FLAG_SSL) != 0);
// infer port# from protocol + security
// SSL implies a different port - TLS runs in the "regular" port
// NOTE: Although the port should be setup in the various setup screens, this
// block cannot easily be moved because we get process URIs from other sources
// (e.g. for tests, provider templates and account restore) that may or may not
// have a port specified.
if ("pop3".equals(mProtocol)) {
mPort = useSSL ? 995 : 110;
} else if ("imap".equals(mProtocol)) {
mPort = useSSL ? 993 : 143;
} else if ("eas".equals(mProtocol)) {
mPort = useSSL ? 443 : 80;
} else if ("smtp".equals(mProtocol)) {
mPort = useSSL ? 465 : 587;
}
}
} }
/** /**

View File

@ -64,6 +64,8 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -1107,4 +1109,21 @@ public class Utility {
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return i; return i;
} }
/**
* Legacy URI parser. Used in one of three different scenarios:
* 1. Backup / Restore of account
* 2. Parsing template from provider.xml
* 3. Forcefully creating URI for test
*/
public static void setHostAuthFromString(HostAuth auth, String uriString)
throws URISyntaxException {
URI uri = new URI(uriString);
String path = uri.getPath();
if (path != null && path.length() > 0) {
auth.mDomain = path.substring(1);
}
auth.setLogin(uri.getUserInfo());
auth.setConnection(uri.getScheme(), uri.getHost(), uri.getPort());
}
} }

View File

@ -242,7 +242,7 @@ public class EasSyncService extends AbstractSyncService {
return; return;
} }
mSsl = (ha.mFlags & HostAuth.FLAG_SSL) != 0; mSsl = (ha.mFlags & HostAuth.FLAG_SSL) != 0;
mTrustSsl = (ha.mFlags & HostAuth.FLAG_TRUST_ALL_CERTIFICATES) != 0; mTrustSsl = (ha.mFlags & HostAuth.FLAG_TRUST_ALL) != 0;
} }
private EasSyncService(String prefix) { private EasSyncService(String prefix) {
@ -853,7 +853,7 @@ public class EasSyncService extends AbstractSyncService {
svc.mUserName = ha.mLogin; svc.mUserName = ha.mLogin;
svc.mPassword = ha.mPassword; svc.mPassword = ha.mPassword;
svc.mSsl = (ha.mFlags & HostAuth.FLAG_SSL) != 0; svc.mSsl = (ha.mFlags & HostAuth.FLAG_SSL) != 0;
svc.mTrustSsl = (ha.mFlags & HostAuth.FLAG_TRUST_ALL_CERTIFICATES) != 0; svc.mTrustSsl = (ha.mFlags & HostAuth.FLAG_TRUST_ALL) != 0;
svc.mDeviceId = Device.getDeviceId(context); svc.mDeviceId = Device.getDeviceId(context);
svc.mAccount = acct; svc.mAccount = acct;
Serializer s = new Serializer(); Serializer s = new Serializer();

View File

@ -18,6 +18,7 @@ package com.android.email.activity.setup;
import com.android.email.mail.Store; import com.android.email.mail.Store;
import com.android.emailcommon.provider.EmailContent.Account; import com.android.emailcommon.provider.EmailContent.Account;
import com.android.emailcommon.utility.Utility;
import android.content.ContentUris; import android.content.ContentUris;
import android.content.Context; import android.content.Context;
@ -28,6 +29,8 @@ import android.preference.PreferenceFragment;
import android.test.ActivityInstrumentationTestCase2; import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.MediumTest;
import java.net.URISyntaxException;
/** /**
* Tests of basic UI logic in the Account Settings fragment. * Tests of basic UI logic in the Account Settings fragment.
* *
@ -129,7 +132,7 @@ public class AccountSettingsXLTests extends ActivityInstrumentationTestCase2<Acc
*/ */
private void getActivityAndFields() throws Throwable { private void getActivityAndFields() throws Throwable {
final AccountSettingsXL theActivity = getActivity(); final AccountSettingsXL theActivity = getActivity();
runTestOnUiThread(new Runnable() { runTestOnUiThread(new Runnable() {
public void run() { public void run() {
PreferenceFragment f = (PreferenceFragment) theActivity.mCurrentFragment; PreferenceFragment f = (PreferenceFragment) theActivity.mCurrentFragment;
@ -155,13 +158,14 @@ public class AccountSettingsXLTests extends ActivityInstrumentationTestCase2<Acc
/** /**
* Create an intent with the Account in it * Create an intent with the Account in it
*/ */
private Intent getTestIntent(String name, String storeUri, String senderUri) { private Intent getTestIntent(String name, String storeUri, String senderUri)
throws URISyntaxException {
mAccount = new Account(); mAccount = new Account();
mAccount.setSenderName(name); mAccount.setSenderName(name);
// For EAS, at least, email address is required // For EAS, at least, email address is required
mAccount.mEmailAddress = "user@server.com"; mAccount.mEmailAddress = "user@server.com";
mAccount.setStoreUri(mContext, storeUri); Utility.setHostAuthFromString(mAccount.getOrCreateHostAuthRecv(mContext), storeUri);
mAccount.setSenderUri(mContext, senderUri); Utility.setHostAuthFromString(mAccount.getOrCreateHostAuthSend(mContext), senderUri);
mAccount.save(mContext); mAccount.save(mContext);
mAccountId = mAccount.mId; mAccountId = mAccount.mId;

View File

@ -19,6 +19,8 @@ package com.android.email.activity.setup;
import com.android.email.R; import com.android.email.R;
import com.android.email.mail.Store; import com.android.email.mail.Store;
import com.android.emailcommon.provider.EmailContent.Account; import com.android.emailcommon.provider.EmailContent.Account;
import com.android.emailcommon.provider.EmailContent.HostAuth;
import com.android.emailcommon.utility.Utility;
import android.content.ContentUris; import android.content.ContentUris;
import android.content.Context; import android.content.Context;
@ -28,6 +30,7 @@ import android.test.ActivityUnitTestCase;
import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest;
import android.view.View; import android.view.View;
import java.net.URISyntaxException;
import java.util.HashSet; import java.util.HashSet;
/** /**
@ -69,7 +72,8 @@ public class AccountSetupAccountTypeTests
/** /**
* Test store type limit enforcement * Test store type limit enforcement
*/ */
public void testStoreTypeLimits() { public void testStoreTypeLimits()
throws URISyntaxException {
createTestAccount("scheme1"); createTestAccount("scheme1");
createTestAccount("scheme1"); createTestAccount("scheme1");
createTestAccount("scheme2"); createTestAccount("scheme2");
@ -94,7 +98,8 @@ public class AccountSetupAccountTypeTests
/** /**
* Confirm that EAS is presented, when supported. * Confirm that EAS is presented, when supported.
*/ */
public void testEasOffered() { public void testEasOffered()
throws URISyntaxException {
createTestAccount("scheme1"); createTestAccount("scheme1");
AccountSetupAccountType activity = startActivity(getTestIntent(), null, null); AccountSetupAccountType activity = startActivity(getTestIntent(), null, null);
View exchangeButton = activity.findViewById(R.id.exchange); View exchangeButton = activity.findViewById(R.id.exchange);
@ -110,9 +115,11 @@ public class AccountSetupAccountTypeTests
/** /**
* Create a dummy account with minimal fields * Create a dummy account with minimal fields
*/ */
private Account createTestAccount(String scheme) { private Account createTestAccount(String scheme)
throws URISyntaxException {
Account account = new Account(); Account account = new Account();
account.setStoreUri(mContext, scheme + "://user:pass@server.com:123"); HostAuth auth = account.getOrCreateHostAuthRecv(mContext);
Utility.setHostAuthFromString(auth, scheme + "://user:pass@server.com:123");
account.save(mContext); account.save(mContext);
mAccounts.add(account); mAccounts.add(account);
SetupData.init(SetupData.FLOW_MODE_NORMAL, account); SetupData.init(SetupData.FLOW_MODE_NORMAL, account);

View File

@ -21,7 +21,9 @@ import com.android.email.provider.ProviderTestUtils;
import com.android.emailcommon.provider.EmailContent; import com.android.emailcommon.provider.EmailContent;
import com.android.emailcommon.provider.EmailContent.Account; import com.android.emailcommon.provider.EmailContent.Account;
import com.android.emailcommon.provider.EmailContent.HostAuth; import com.android.emailcommon.provider.EmailContent.HostAuth;
import com.android.emailcommon.utility.Utility;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2; import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest; import android.test.UiThreadTest;
@ -73,7 +75,8 @@ public class AccountSetupExchangeTests extends
/** /**
* Test processing with a complete, good URI -> good fields * Test processing with a complete, good URI -> good fields
*/ */
public void testGoodUri() { public void testGoodUri()
throws URISyntaxException {
Intent i = getTestIntent("eas://user:password@server.com"); Intent i = getTestIntent("eas://user:password@server.com");
setActivityIntent(i); setActivityIntent(i);
getActivityAndFields(); getActivityAndFields();
@ -86,7 +89,8 @@ public class AccountSetupExchangeTests extends
/** /**
* No user is not OK - not enabled * No user is not OK - not enabled
*/ */
public void testBadUriNoUser() { public void testBadUriNoUser()
throws URISyntaxException {
Intent i = getTestIntent("eas://:password@server.com"); Intent i = getTestIntent("eas://:password@server.com");
setActivityIntent(i); setActivityIntent(i);
getActivityAndFields(); getActivityAndFields();
@ -96,7 +100,8 @@ public class AccountSetupExchangeTests extends
/** /**
* No password is not OK - not enabled * No password is not OK - not enabled
*/ */
public void testBadUriNoPassword() { public void testBadUriNoPassword()
throws URISyntaxException {
Intent i = getTestIntent("eas://user@server.com"); Intent i = getTestIntent("eas://user@server.com");
setActivityIntent(i); setActivityIntent(i);
getActivityAndFields(); getActivityAndFields();
@ -187,7 +192,7 @@ public class AccountSetupExchangeTests extends
account.mHostAuthRecv = ProviderTestUtils.setupHostAuth( account.mHostAuthRecv = ProviderTestUtils.setupHostAuth(
"eas", "hostauth", 1, false, mActivity.getBaseContext()); "eas", "hostauth", 1, false, mActivity.getBaseContext());
account.mHostAuthRecv.mFlags |= HostAuth.FLAG_SSL; account.mHostAuthRecv.mFlags |= HostAuth.FLAG_SSL;
account.mHostAuthRecv.mFlags &= ~HostAuth.FLAG_TRUST_ALL_CERTIFICATES; account.mHostAuthRecv.mFlags &= ~HostAuth.FLAG_TRUST_ALL;
mActivity.mFragment.mLoaded = false; mActivity.mFragment.mLoaded = false;
boolean loadResult = mActivity.mFragment.loadSettings(account); boolean loadResult = mActivity.mFragment.loadSettings(account);
assertTrue(loadResult); assertTrue(loadResult);
@ -197,7 +202,7 @@ public class AccountSetupExchangeTests extends
// Setup host auth with variants of SSL enabled and check. This also enables the // Setup host auth with variants of SSL enabled and check. This also enables the
// "trust certificates" checkbox (not checked, but visible now). // "trust certificates" checkbox (not checked, but visible now).
account.mHostAuthRecv.mFlags |= HostAuth.FLAG_TRUST_ALL_CERTIFICATES; account.mHostAuthRecv.mFlags |= HostAuth.FLAG_TRUST_ALL;
mActivity.mFragment.mLoaded = false; mActivity.mFragment.mLoaded = false;
loadResult = mActivity.mFragment.loadSettings(account); loadResult = mActivity.mFragment.loadSettings(account);
assertTrue(loadResult); assertTrue(loadResult);
@ -232,9 +237,12 @@ public class AccountSetupExchangeTests extends
/** /**
* Create an intent with the Account in it * Create an intent with the Account in it
*/ */
private Intent getTestIntent(String storeUriString) { private Intent getTestIntent(String storeUriString)
throws URISyntaxException {
EmailContent.Account account = new EmailContent.Account(); EmailContent.Account account = new EmailContent.Account();
account.setStoreUri(getInstrumentation().getTargetContext(), storeUriString); Context context = getInstrumentation().getTargetContext();
HostAuth auth = account.getOrCreateHostAuthRecv(context);
Utility.setHostAuthFromString(auth, storeUriString);
Intent i = new Intent(Intent.ACTION_MAIN); Intent i = new Intent(Intent.ACTION_MAIN);
SetupData.init(SetupData.FLOW_MODE_NORMAL, account); SetupData.init(SetupData.FLOW_MODE_NORMAL, account);
SetupData.setAllowAutodiscover(false); SetupData.setAllowAutodiscover(false);

View File

@ -18,7 +18,10 @@ package com.android.email.activity.setup;
import com.android.email.R; import com.android.email.R;
import com.android.emailcommon.provider.EmailContent; import com.android.emailcommon.provider.EmailContent;
import com.android.emailcommon.provider.EmailContent.HostAuth;
import com.android.emailcommon.utility.Utility;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2; import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest; import android.test.UiThreadTest;
@ -34,14 +37,14 @@ import java.net.URISyntaxException;
* runtest -c com.android.email.activity.setup.AccountSetupIncomingTests email * runtest -c com.android.email.activity.setup.AccountSetupIncomingTests email
*/ */
@MediumTest @MediumTest
public class AccountSetupIncomingTests extends public class AccountSetupIncomingTests extends
ActivityInstrumentationTestCase2<AccountSetupIncoming> { ActivityInstrumentationTestCase2<AccountSetupIncoming> {
private AccountSetupIncoming mActivity; private AccountSetupIncoming mActivity;
private AccountSetupIncomingFragment mFragment; private AccountSetupIncomingFragment mFragment;
private EditText mServerView; private EditText mServerView;
private EditText mPasswordView; private EditText mPasswordView;
public AccountSetupIncomingTests() { public AccountSetupIncomingTests() {
super(AccountSetupIncoming.class); super(AccountSetupIncoming.class);
} }
@ -60,47 +63,51 @@ public class AccountSetupIncomingTests extends
Intent i = getTestIntent("imap://user:password@server.com:999"); Intent i = getTestIntent("imap://user:password@server.com:999");
setActivityIntent(i); setActivityIntent(i);
} }
/** /**
* Test processing with a complete, good URI -> good fields * Test processing with a complete, good URI -> good fields
*/ */
public void testGoodUri() { public void testGoodUri()
throws URISyntaxException {
Intent i = getTestIntent("imap://user:password@server.com:999"); Intent i = getTestIntent("imap://user:password@server.com:999");
setActivityIntent(i); setActivityIntent(i);
getActivityAndFields(); getActivityAndFields();
assertTrue(mActivity.mNextButtonEnabled); assertTrue(mActivity.mNextButtonEnabled);
} }
/** /**
* No user is not OK - not enabled * No user is not OK - not enabled
*/ */
public void testBadUriNoUser() { public void testBadUriNoUser()
throws URISyntaxException {
Intent i = getTestIntent("imap://:password@server.com:999"); Intent i = getTestIntent("imap://:password@server.com:999");
setActivityIntent(i); setActivityIntent(i);
getActivityAndFields(); getActivityAndFields();
assertFalse(mActivity.mNextButtonEnabled); assertFalse(mActivity.mNextButtonEnabled);
} }
/** /**
* No password is not OK - not enabled * No password is not OK - not enabled
*/ */
public void testBadUriNoPassword() { public void testBadUriNoPassword()
throws URISyntaxException {
Intent i = getTestIntent("imap://user@server.com:999"); Intent i = getTestIntent("imap://user@server.com:999");
setActivityIntent(i); setActivityIntent(i);
getActivityAndFields(); getActivityAndFields();
assertFalse(mActivity.mNextButtonEnabled); assertFalse(mActivity.mNextButtonEnabled);
} }
/** /**
* No port is OK - still enabled * No port is OK - still enabled
*/ */
public void testGoodUriNoPort() { public void testGoodUriNoPort()
throws URISyntaxException {
Intent i = getTestIntent("imap://user:password@server.com"); Intent i = getTestIntent("imap://user:password@server.com");
setActivityIntent(i); setActivityIntent(i);
getActivityAndFields(); getActivityAndFields();
assertTrue(mActivity.mNextButtonEnabled); assertTrue(mActivity.mNextButtonEnabled);
} }
/** /**
* Test for non-standard but OK server names * Test for non-standard but OK server names
*/ */
@ -108,11 +115,11 @@ public class AccountSetupIncomingTests extends
public void testGoodServerVariants() { public void testGoodServerVariants() {
getActivityAndFields(); getActivityAndFields();
assertTrue(mActivity.mNextButtonEnabled); assertTrue(mActivity.mNextButtonEnabled);
mServerView.setText(" server.com "); mServerView.setText(" server.com ");
assertTrue(mActivity.mNextButtonEnabled); assertTrue(mActivity.mNextButtonEnabled);
} }
/** /**
* Test for non-empty but non-OK server names * Test for non-empty but non-OK server names
*/ */
@ -120,10 +127,10 @@ public class AccountSetupIncomingTests extends
public void testBadServerVariants() { public void testBadServerVariants() {
getActivityAndFields(); getActivityAndFields();
assertTrue(mActivity.mNextButtonEnabled); assertTrue(mActivity.mNextButtonEnabled);
mServerView.setText(" "); mServerView.setText(" ");
assertFalse(mActivity.mNextButtonEnabled); assertFalse(mActivity.mNextButtonEnabled);
mServerView.setText("serv$er.com"); mServerView.setText("serv$er.com");
assertFalse(mActivity.mNextButtonEnabled); assertFalse(mActivity.mNextButtonEnabled);
} }
@ -169,7 +176,7 @@ public class AccountSetupIncomingTests extends
* TODO: A series of tests to explore the logic around security models & ports * TODO: A series of tests to explore the logic around security models & ports
* TODO: A series of tests exploring differences between IMAP and POP3 * TODO: A series of tests exploring differences between IMAP and POP3
*/ */
/** /**
* Get the activity (which causes it to be started, using our intent) and get the UI fields * Get the activity (which causes it to be started, using our intent) and get the UI fields
*/ */
@ -179,13 +186,16 @@ public class AccountSetupIncomingTests extends
mServerView = (EditText) mActivity.findViewById(R.id.account_server); mServerView = (EditText) mActivity.findViewById(R.id.account_server);
mPasswordView = (EditText) mActivity.findViewById(R.id.account_password); mPasswordView = (EditText) mActivity.findViewById(R.id.account_password);
} }
/** /**
* Create an intent with the Account in it * Create an intent with the Account in it
*/ */
private Intent getTestIntent(String storeUriString) { private Intent getTestIntent(String storeUriString)
throws URISyntaxException {
EmailContent.Account account = new EmailContent.Account(); EmailContent.Account account = new EmailContent.Account();
account.setStoreUri(getInstrumentation().getTargetContext(), storeUriString); Context context = getInstrumentation().getTargetContext();
HostAuth auth = account.getOrCreateHostAuthRecv(context);
Utility.setHostAuthFromString(auth, storeUriString);
SetupData.init(SetupData.FLOW_MODE_NORMAL, account); SetupData.init(SetupData.FLOW_MODE_NORMAL, account);
return new Intent(Intent.ACTION_MAIN); return new Intent(Intent.ACTION_MAIN);
} }

View File

@ -19,7 +19,10 @@ package com.android.email.activity.setup;
import com.android.email.R; import com.android.email.R;
import com.android.email.mail.Store; import com.android.email.mail.Store;
import com.android.emailcommon.provider.EmailContent; import com.android.emailcommon.provider.EmailContent;
import com.android.emailcommon.provider.EmailContent.HostAuth;
import com.android.emailcommon.utility.Utility;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2; import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.MediumTest; import android.test.suitebuilder.annotation.MediumTest;
@ -28,19 +31,21 @@ import android.widget.CheckBox;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.SpinnerAdapter; import android.widget.SpinnerAdapter;
import java.net.URISyntaxException;
/** /**
* Tests of basic UI logic in the AccountSetupOptions screen. * Tests of basic UI logic in the AccountSetupOptions screen.
* You can run this entire test case with: * You can run this entire test case with:
* runtest -c com.android.email.activity.setup.AccountSetupOptionsTests email * runtest -c com.android.email.activity.setup.AccountSetupOptionsTests email
*/ */
@MediumTest @MediumTest
public class AccountSetupOptionsTests public class AccountSetupOptionsTests
extends ActivityInstrumentationTestCase2<AccountSetupOptions> { extends ActivityInstrumentationTestCase2<AccountSetupOptions> {
private AccountSetupOptions mActivity; private AccountSetupOptions mActivity;
private Spinner mCheckFrequencyView; private Spinner mCheckFrequencyView;
private CheckBox mBackgroundAttachmentsView; private CheckBox mBackgroundAttachmentsView;
public AccountSetupOptionsTests() { public AccountSetupOptionsTests() {
super(AccountSetupOptions.class); super(AccountSetupOptions.class);
} }
@ -48,44 +53,47 @@ public class AccountSetupOptionsTests
/** /**
* Test that POP accounts aren't displayed with a push option * Test that POP accounts aren't displayed with a push option
*/ */
public void testPushOptionPOP() { public void testPushOptionPOP()
throws URISyntaxException {
Intent i = getTestIntent("Name", "pop3://user:password@server.com"); Intent i = getTestIntent("Name", "pop3://user:password@server.com");
this.setActivityIntent(i); this.setActivityIntent(i);
getActivityAndFields(); getActivityAndFields();
boolean hasPush = frequencySpinnerHasValue(EmailContent.Account.CHECK_INTERVAL_PUSH); boolean hasPush = frequencySpinnerHasValue(EmailContent.Account.CHECK_INTERVAL_PUSH);
assertFalse(hasPush); assertFalse(hasPush);
} }
/** /**
* Test that IMAP accounts aren't displayed with a push option * Test that IMAP accounts aren't displayed with a push option
*/ */
public void testPushOptionIMAP() { public void testPushOptionIMAP()
throws URISyntaxException {
Intent i = getTestIntent("Name", "imap://user:password@server.com"); Intent i = getTestIntent("Name", "imap://user:password@server.com");
this.setActivityIntent(i); this.setActivityIntent(i);
getActivityAndFields(); getActivityAndFields();
boolean hasPush = frequencySpinnerHasValue(EmailContent.Account.CHECK_INTERVAL_PUSH); boolean hasPush = frequencySpinnerHasValue(EmailContent.Account.CHECK_INTERVAL_PUSH);
assertFalse(hasPush); assertFalse(hasPush);
} }
/** /**
* Test that EAS accounts are displayed with a push option * Test that EAS accounts are displayed with a push option
*/ */
public void testPushOptionEAS() { public void testPushOptionEAS()
throws URISyntaxException {
// This test should only be run if EAS is supported // This test should only be run if EAS is supported
if (Store.StoreInfo.getStoreInfo("eas", this.getInstrumentation().getTargetContext()) if (Store.StoreInfo.getStoreInfo("eas", this.getInstrumentation().getTargetContext())
== null) { == null) {
return; return;
} }
Intent i = getTestIntent("Name", "eas://user:password@server.com"); Intent i = getTestIntent("Name", "eas://user:password@server.com");
this.setActivityIntent(i); this.setActivityIntent(i);
getActivityAndFields(); getActivityAndFields();
boolean hasPush = frequencySpinnerHasValue(EmailContent.Account.CHECK_INTERVAL_PUSH); boolean hasPush = frequencySpinnerHasValue(EmailContent.Account.CHECK_INTERVAL_PUSH);
assertTrue(hasPush); assertTrue(hasPush);
} }
@ -93,23 +101,26 @@ public class AccountSetupOptionsTests
/** /**
* Test that POP3 accounts don't have a "background attachments" checkbox * Test that POP3 accounts don't have a "background attachments" checkbox
*/ */
public void testBackgroundAttachmentsPop() { public void testBackgroundAttachmentsPop()
throws URISyntaxException {
checkBackgroundAttachments("pop3://user:password@server.com", false); checkBackgroundAttachments("pop3://user:password@server.com", false);
} }
/** /**
* Test that IMAP accounts have a "background attachments" checkbox * Test that IMAP accounts have a "background attachments" checkbox
*/ */
public void testBackgroundAttachmentsImap() { public void testBackgroundAttachmentsImap()
throws URISyntaxException {
checkBackgroundAttachments("imap://user:password@server.com", true); checkBackgroundAttachments("imap://user:password@server.com", true);
} }
/** /**
* Test that EAS accounts have a "background attachments" checkbox * Test that EAS accounts have a "background attachments" checkbox
*/ */
public void testBackgroundAttachmentsEas() { public void testBackgroundAttachmentsEas()
throws URISyntaxException {
// This test should only be run if EAS is supported // This test should only be run if EAS is supported
if (Store.StoreInfo.getStoreInfo("eas", this.getInstrumentation().getTargetContext()) if (Store.StoreInfo.getStoreInfo("eas", this.getInstrumentation().getTargetContext())
== null) { == null) {
return; return;
} }
@ -117,9 +128,10 @@ public class AccountSetupOptionsTests
} }
/** /**
* Common code to check that the "background attachments" checkbox is shown/hidden properly * Common code to check that the "background attachments" checkbox is shown/hidden properly
*/ */
private void checkBackgroundAttachments(String storeUri, boolean expectVisible) { private void checkBackgroundAttachments(String storeUri, boolean expectVisible)
throws URISyntaxException {
Intent i = getTestIntent("Name", storeUri); Intent i = getTestIntent("Name", storeUri);
this.setActivityIntent(i); this.setActivityIntent(i);
getActivityAndFields(); getActivityAndFields();
@ -144,7 +156,7 @@ public class AccountSetupOptionsTests
mBackgroundAttachmentsView = (CheckBox) mActivity.findViewById( mBackgroundAttachmentsView = (CheckBox) mActivity.findViewById(
R.id.account_background_attachments); R.id.account_background_attachments);
} }
/** /**
* Test the frequency values list for a particular value * Test the frequency values list for a particular value
*/ */
@ -159,16 +171,19 @@ public class AccountSetupOptionsTests
} }
return false; return false;
} }
/** /**
* Create an intent with the Account in it * Create an intent with the Account in it
*/ */
private Intent getTestIntent(String name, String storeUri) { private Intent getTestIntent(String name, String storeUri)
throws URISyntaxException {
EmailContent.Account account = new EmailContent.Account(); EmailContent.Account account = new EmailContent.Account();
account.setSenderName(name); account.setSenderName(name);
account.setStoreUri(getInstrumentation().getTargetContext(), storeUri); Context context = getInstrumentation().getTargetContext();
HostAuth auth = account.getOrCreateHostAuthRecv(context);
Utility.setHostAuthFromString(auth, storeUri);
SetupData.init(SetupData.FLOW_MODE_NORMAL, account); SetupData.init(SetupData.FLOW_MODE_NORMAL, account);
return new Intent(Intent.ACTION_MAIN); return new Intent(Intent.ACTION_MAIN);
} }
} }

View File

@ -18,7 +18,10 @@ package com.android.email.activity.setup;
import com.android.email.R; import com.android.email.R;
import com.android.emailcommon.provider.EmailContent; import com.android.emailcommon.provider.EmailContent;
import com.android.emailcommon.provider.EmailContent.HostAuth;
import com.android.emailcommon.utility.Utility;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.test.ActivityInstrumentationTestCase2; import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest; import android.test.UiThreadTest;
@ -34,14 +37,14 @@ import java.net.URISyntaxException;
* runtest -c com.android.email.activity.setup.AccountSetupOutgoingTests email * runtest -c com.android.email.activity.setup.AccountSetupOutgoingTests email
*/ */
@MediumTest @MediumTest
public class AccountSetupOutgoingTests extends public class AccountSetupOutgoingTests extends
ActivityInstrumentationTestCase2<AccountSetupOutgoing> { ActivityInstrumentationTestCase2<AccountSetupOutgoing> {
private AccountSetupOutgoing mActivity; private AccountSetupOutgoing mActivity;
private AccountSetupOutgoingFragment mFragment; private AccountSetupOutgoingFragment mFragment;
private EditText mServerView; private EditText mServerView;
private EditText mPasswordView; private EditText mPasswordView;
public AccountSetupOutgoingTests() { public AccountSetupOutgoingTests() {
super(AccountSetupOutgoing.class); super(AccountSetupOutgoing.class);
} }
@ -60,7 +63,7 @@ public class AccountSetupOutgoingTests extends
Intent i = getTestIntent("smtp://user:password@server.com:999"); Intent i = getTestIntent("smtp://user:password@server.com:999");
setActivityIntent(i); setActivityIntent(i);
} }
/** /**
* Test processing with a complete, good URI -> good fields * Test processing with a complete, good URI -> good fields
*/ */
@ -68,37 +71,40 @@ public class AccountSetupOutgoingTests extends
getActivityAndFields(); getActivityAndFields();
assertTrue(mActivity.mNextButtonEnabled); assertTrue(mActivity.mNextButtonEnabled);
} }
/** /**
* No user is not OK - not enabled * No user is not OK - not enabled
*/ */
public void testBadUriNoUser() { public void testBadUriNoUser()
throws URISyntaxException {
Intent i = getTestIntent("smtp://:password@server.com:999"); Intent i = getTestIntent("smtp://:password@server.com:999");
setActivityIntent(i); setActivityIntent(i);
getActivityAndFields(); getActivityAndFields();
assertFalse(mActivity.mNextButtonEnabled); assertFalse(mActivity.mNextButtonEnabled);
} }
/** /**
* No password is not OK - not enabled * No password is not OK - not enabled
*/ */
public void testBadUriNoPassword() { public void testBadUriNoPassword()
throws URISyntaxException {
Intent i = getTestIntent("smtp://user@server.com:999"); Intent i = getTestIntent("smtp://user@server.com:999");
setActivityIntent(i); setActivityIntent(i);
getActivityAndFields(); getActivityAndFields();
assertFalse(mActivity.mNextButtonEnabled); assertFalse(mActivity.mNextButtonEnabled);
} }
/** /**
* No port is OK - still enabled * No port is OK - still enabled
*/ */
public void testGoodUriNoPort() { public void testGoodUriNoPort()
throws URISyntaxException {
Intent i = getTestIntent("smtp://user:password@server.com"); Intent i = getTestIntent("smtp://user:password@server.com");
setActivityIntent(i); setActivityIntent(i);
getActivityAndFields(); getActivityAndFields();
assertTrue(mActivity.mNextButtonEnabled); assertTrue(mActivity.mNextButtonEnabled);
} }
/** /**
* Test for non-standard but OK server names * Test for non-standard but OK server names
*/ */
@ -106,11 +112,11 @@ public class AccountSetupOutgoingTests extends
public void testGoodServerVariants() { public void testGoodServerVariants() {
getActivityAndFields(); getActivityAndFields();
assertTrue(mActivity.mNextButtonEnabled); assertTrue(mActivity.mNextButtonEnabled);
mServerView.setText(" server.com "); mServerView.setText(" server.com ");
assertTrue(mActivity.mNextButtonEnabled); assertTrue(mActivity.mNextButtonEnabled);
} }
/** /**
* Test for non-empty but non-OK server names * Test for non-empty but non-OK server names
*/ */
@ -118,10 +124,10 @@ public class AccountSetupOutgoingTests extends
public void testBadServerVariants() { public void testBadServerVariants() {
getActivityAndFields(); getActivityAndFields();
assertTrue(mActivity.mNextButtonEnabled); assertTrue(mActivity.mNextButtonEnabled);
mServerView.setText(" "); mServerView.setText(" ");
assertFalse(mActivity.mNextButtonEnabled); assertFalse(mActivity.mNextButtonEnabled);
mServerView.setText("serv$er.com"); mServerView.setText("serv$er.com");
assertFalse(mActivity.mNextButtonEnabled); assertFalse(mActivity.mNextButtonEnabled);
} }
@ -166,7 +172,7 @@ public class AccountSetupOutgoingTests extends
/** /**
* TODO: A series of tests to explore the logic around security models & ports * TODO: A series of tests to explore the logic around security models & ports
*/ */
/** /**
* Get the activity (which causes it to be started, using our intent) and get the UI fields * Get the activity (which causes it to be started, using our intent) and get the UI fields
*/ */
@ -176,13 +182,16 @@ public class AccountSetupOutgoingTests extends
mServerView = (EditText) mActivity.findViewById(R.id.account_server); mServerView = (EditText) mActivity.findViewById(R.id.account_server);
mPasswordView = (EditText) mActivity.findViewById(R.id.account_password); mPasswordView = (EditText) mActivity.findViewById(R.id.account_password);
} }
/** /**
* Create an intent with the Account in it * Create an intent with the Account in it
*/ */
private Intent getTestIntent(String senderUriString) { private Intent getTestIntent(String senderUriString)
throws URISyntaxException {
EmailContent.Account account = new EmailContent.Account(); EmailContent.Account account = new EmailContent.Account();
account.setSenderUri(this.getInstrumentation().getTargetContext(), senderUriString); Context context = getInstrumentation().getTargetContext();
HostAuth auth = account.getOrCreateHostAuthSend(context);
Utility.setHostAuthFromString(auth, senderUriString);
SetupData.init(SetupData.FLOW_MODE_NORMAL, account); SetupData.init(SetupData.FLOW_MODE_NORMAL, account);
return new Intent(Intent.ACTION_MAIN); return new Intent(Intent.ACTION_MAIN);
} }

View File

@ -46,6 +46,7 @@ import android.test.ProviderTestCase2;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
@ -128,8 +129,78 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
account1.mHostAuthSend, hostAuth2get); account1.mHostAuthSend, hostAuth2get);
} }
public void testAccountGetHostAuthSend() {
Account account = ProviderTestUtils.setupAccount("account-hostauth", false, mMockContext);
account.mHostAuthSend = ProviderTestUtils.setupHostAuth("account-hostauth-send", -1, false,
mMockContext);
account.save(mMockContext);
HostAuth authGet;
HostAuth authTest;
authTest = account.mHostAuthSend;
assertNotNull(authTest);
assertTrue(account.mHostAuthKeySend != 0);
// HostAuth is not changed
authGet = account.getOrCreateHostAuthSend(mMockContext);
assertTrue(authGet == authTest); // return the same object
// New HostAuth; based upon mHostAuthKeyRecv
authTest = EmailContent.HostAuth.restoreHostAuthWithId(mMockContext,
account.mHostAuthKeySend);
account.mHostAuthSend = null;
authGet = account.getOrCreateHostAuthSend(mMockContext);
assertNotNull(authGet);
assertNotNull(account.mHostAuthSend);
ProviderTestUtils.assertHostAuthEqual("testAccountGetHostAuthSend-1", authTest, authGet);
// New HostAuth; completely empty
authTest = new EmailContent.HostAuth();
account.mHostAuthSend = null;
account.mHostAuthKeySend = 0;
authGet = account.getOrCreateHostAuthSend(mMockContext);
assertNotNull(authGet);
assertNotNull(account.mHostAuthSend);
ProviderTestUtils.assertHostAuthEqual("testAccountGetHostAuthSendv-2", authTest, authGet);
}
public void testAccountGetHostAuthRecv() {
Account account = ProviderTestUtils.setupAccount("account-hostauth", false, mMockContext);
account.mHostAuthRecv = ProviderTestUtils.setupHostAuth("account-hostauth-recv", -1, false,
mMockContext);
account.save(mMockContext);
HostAuth authGet;
HostAuth authTest;
authTest = account.mHostAuthRecv;
assertNotNull(authTest);
assertTrue(account.mHostAuthKeyRecv != 0);
// HostAuth is not changed
authGet = account.getOrCreateHostAuthRecv(mMockContext);
assertTrue(authGet == authTest); // return the same object
// New HostAuth; based upon mHostAuthKeyRecv
authTest = EmailContent.HostAuth.restoreHostAuthWithId(mMockContext,
account.mHostAuthKeyRecv);
account.mHostAuthRecv = null;
authGet = account.getOrCreateHostAuthRecv(mMockContext);
assertNotNull(authGet);
assertNotNull(account.mHostAuthRecv);
ProviderTestUtils.assertHostAuthEqual("testAccountGetHostAuthRecv-1", authTest, authGet);
// New HostAuth; completely empty
authTest = new EmailContent.HostAuth();
account.mHostAuthRecv = null;
account.mHostAuthKeyRecv = 0;
authGet = account.getOrCreateHostAuthRecv(mMockContext);
assertNotNull(authGet);
assertNotNull(account.mHostAuthRecv);
ProviderTestUtils.assertHostAuthEqual("testAccountGetHostAuthRecv-2", authTest, authGet);
}
/** /**
* Simple test of account parceling. The rather tortuous path is to ensure that the * Simple test of account parceling. The rather torturous path is to ensure that the
* account is really flattened all the way down to a parcel and back. * account is really flattened all the way down to a parcel and back.
*/ */
public void testAccountParcel() { public void testAccountParcel() {
@ -149,7 +220,7 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
/** /**
* Test for {@link Account#getShortcutSafeUri()} and * Test for {@link Account#getShortcutSafeUri()} and
* {@link Account#getAccountIdForShortcutSafeUri}. * {@link Account#getAccountIdFromShortcutSafeUri}.
*/ */
public void testAccountShortcutSafeUri() { public void testAccountShortcutSafeUri() {
final Account account1 = ProviderTestUtils.setupAccount("account-1", true, mMockContext); final Account account1 = ProviderTestUtils.setupAccount("account-1", true, mMockContext);
@ -223,9 +294,6 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
/** /**
* Get the value of the unread count in the mailbox of the account. * Get the value of the unread count in the mailbox of the account.
* This can be different from the actual number of unread messages in that mailbox. * This can be different from the actual number of unread messages in that mailbox.
* @param accountId
* @param mailboxId
* @return
*/ */
private int getUnreadCount(long mailboxId) { private int getUnreadCount(long mailboxId) {
String text = null; String text = null;
@ -252,24 +320,24 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
/** /**
* Test the various combinations of SSL, TLS, and trust-certificates encoded as Uris * Test the various combinations of SSL, TLS, and trust-certificates encoded as Uris
*/ */
@SuppressWarnings("deprecation") public void testHostAuthSecurityUri()
public void testHostAuthSecurityUri() { throws URISyntaxException {
HostAuth ha = ProviderTestUtils.setupHostAuth("uri-security", 1, false, mMockContext); HostAuth ha = ProviderTestUtils.setupHostAuth("uri-security", 1, false, mMockContext);
final int MASK = final int MASK =
HostAuth.FLAG_SSL | HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL_CERTIFICATES; HostAuth.FLAG_SSL | HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL;
// Set various URIs and check the resulting flags // Set various URIs and check the resulting flags
ha.setStoreUri("protocol://user:password@server:123"); Utility.setHostAuthFromString(ha, "protocol://user:password@server:123");
assertEquals(0, ha.mFlags & MASK); assertEquals(0, ha.mFlags & MASK);
ha.setStoreUri("protocol+ssl+://user:password@server:123"); Utility.setHostAuthFromString(ha, "protocol+ssl+://user:password@server:123");
assertEquals(HostAuth.FLAG_SSL, ha.mFlags & MASK); assertEquals(HostAuth.FLAG_SSL, ha.mFlags & MASK);
ha.setStoreUri("protocol+ssl+trustallcerts://user:password@server:123"); Utility.setHostAuthFromString(ha, "protocol+ssl+trustallcerts://user:password@server:123");
assertEquals(HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL_CERTIFICATES, ha.mFlags & MASK); assertEquals(HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL, ha.mFlags & MASK);
ha.setStoreUri("protocol+tls+://user:password@server:123"); Utility.setHostAuthFromString(ha, "protocol+tls+://user:password@server:123");
assertEquals(HostAuth.FLAG_TLS, ha.mFlags & MASK); assertEquals(HostAuth.FLAG_TLS, ha.mFlags & MASK);
ha.setStoreUri("protocol+tls+trustallcerts://user:password@server:123"); Utility.setHostAuthFromString(ha, "protocol+tls+trustallcerts://user:password@server:123");
assertEquals(HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL_CERTIFICATES, ha.mFlags & MASK); assertEquals(HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL, ha.mFlags & MASK);
// Now check the retrival method (building URI from flags) // Now check the retrival method (building URI from flags)
ha.mFlags &= ~MASK; ha.mFlags &= ~MASK;
@ -278,14 +346,14 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
ha.mFlags |= HostAuth.FLAG_SSL; ha.mFlags |= HostAuth.FLAG_SSL;
uriString = ha.getStoreUri(); uriString = ha.getStoreUri();
assertTrue(uriString.startsWith("protocol+ssl+://")); assertTrue(uriString.startsWith("protocol+ssl+://"));
ha.mFlags |= HostAuth.FLAG_TRUST_ALL_CERTIFICATES; ha.mFlags |= HostAuth.FLAG_TRUST_ALL;
uriString = ha.getStoreUri(); uriString = ha.getStoreUri();
assertTrue(uriString.startsWith("protocol+ssl+trustallcerts://")); assertTrue(uriString.startsWith("protocol+ssl+trustallcerts://"));
ha.mFlags &= ~MASK; ha.mFlags &= ~MASK;
ha.mFlags |= HostAuth.FLAG_TLS; ha.mFlags |= HostAuth.FLAG_TLS;
uriString = ha.getStoreUri(); uriString = ha.getStoreUri();
assertTrue(uriString.startsWith("protocol+tls+://")); assertTrue(uriString.startsWith("protocol+tls+://"));
ha.mFlags |= HostAuth.FLAG_TRUST_ALL_CERTIFICATES; ha.mFlags |= HostAuth.FLAG_TRUST_ALL;
uriString = ha.getStoreUri(); uriString = ha.getStoreUri();
assertTrue(uriString.startsWith("protocol+tls+trustallcerts://")); assertTrue(uriString.startsWith("protocol+tls+trustallcerts://"));
} }
@ -293,89 +361,375 @@ public class ProviderTests extends ProviderTestCase2<EmailProvider> {
/** /**
* Test port assignments made from Uris * Test port assignments made from Uris
*/ */
@SuppressWarnings("deprecation") public void testHostAuthPortAssignments()
public void testHostAuthPortAssignments() { throws URISyntaxException {
HostAuth ha = ProviderTestUtils.setupHostAuth("uri-port", 1, false, mMockContext); HostAuth ha = ProviderTestUtils.setupHostAuth("uri-port", 1, false, mMockContext);
// Set various URIs and check the resulting flags // Set various URIs and check the resulting flags
// Hardwired port // Hardwired port
ha.setStoreUri("imap://user:password@server:123"); Utility.setHostAuthFromString(ha, "imap://user:password@server:123");
assertEquals(123, ha.mPort); assertEquals(123, ha.mPort);
// Auto-assigned ports // Auto-assigned ports
ha.setStoreUri("imap://user:password@server"); Utility.setHostAuthFromString(ha, "imap://user:password@server");
assertEquals(143, ha.mPort); assertEquals(143, ha.mPort);
ha.setStoreUri("imap+ssl://user:password@server"); Utility.setHostAuthFromString(ha, "imap+ssl://user:password@server");
assertEquals(993, ha.mPort); assertEquals(993, ha.mPort);
ha.setStoreUri("imap+ssl+trustallcerts://user:password@server"); Utility.setHostAuthFromString(ha, "imap+ssl+trustallcerts://user:password@server");
assertEquals(993, ha.mPort); assertEquals(993, ha.mPort);
ha.setStoreUri("imap+tls://user:password@server"); Utility.setHostAuthFromString(ha, "imap+tls://user:password@server");
assertEquals(143, ha.mPort); assertEquals(143, ha.mPort);
ha.setStoreUri("imap+tls+trustallcerts://user:password@server"); Utility.setHostAuthFromString(ha, "imap+tls+trustallcerts://user:password@server");
assertEquals(143, ha.mPort); assertEquals(143, ha.mPort);
// Hardwired port // Hardwired port
ha.setStoreUri("pop3://user:password@server:123"); Utility.setHostAuthFromString(ha, "pop3://user:password@server:123");
assertEquals(123, ha.mPort); assertEquals(123, ha.mPort);
// Auto-assigned ports // Auto-assigned ports
ha.setStoreUri("pop3://user:password@server"); Utility.setHostAuthFromString(ha, "pop3://user:password@server");
assertEquals(110, ha.mPort); assertEquals(110, ha.mPort);
ha.setStoreUri("pop3+ssl://user:password@server"); Utility.setHostAuthFromString(ha, "pop3+ssl://user:password@server");
assertEquals(995, ha.mPort); assertEquals(995, ha.mPort);
ha.setStoreUri("pop3+ssl+trustallcerts://user:password@server"); Utility.setHostAuthFromString(ha, "pop3+ssl+trustallcerts://user:password@server");
assertEquals(995, ha.mPort); assertEquals(995, ha.mPort);
ha.setStoreUri("pop3+tls://user:password@server"); Utility.setHostAuthFromString(ha, "pop3+tls://user:password@server");
assertEquals(110, ha.mPort); assertEquals(110, ha.mPort);
ha.setStoreUri("pop3+tls+trustallcerts://user:password@server"); Utility.setHostAuthFromString(ha, "pop3+tls+trustallcerts://user:password@server");
assertEquals(110, ha.mPort); assertEquals(110, ha.mPort);
// Hardwired port // Hardwired port
ha.setStoreUri("eas://user:password@server:123"); Utility.setHostAuthFromString(ha, "eas://user:password@server:123");
assertEquals(123, ha.mPort); assertEquals(123, ha.mPort);
// Auto-assigned ports // Auto-assigned ports
ha.setStoreUri("eas://user:password@server"); Utility.setHostAuthFromString(ha, "eas://user:password@server");
assertEquals(80, ha.mPort); assertEquals(80, ha.mPort);
ha.setStoreUri("eas+ssl://user:password@server"); Utility.setHostAuthFromString(ha, "eas+ssl://user:password@server");
assertEquals(443, ha.mPort); assertEquals(443, ha.mPort);
ha.setStoreUri("eas+ssl+trustallcerts://user:password@server"); Utility.setHostAuthFromString(ha, "eas+ssl+trustallcerts://user:password@server");
assertEquals(443, ha.mPort); assertEquals(443, ha.mPort);
// Hardwired port // Hardwired port
ha.setStoreUri("smtp://user:password@server:123"); Utility.setHostAuthFromString(ha, "smtp://user:password@server:123");
assertEquals(123, ha.mPort); assertEquals(123, ha.mPort);
// Auto-assigned ports // Auto-assigned ports
ha.setStoreUri("smtp://user:password@server"); Utility.setHostAuthFromString(ha, "smtp://user:password@server");
assertEquals(587, ha.mPort); assertEquals(587, ha.mPort);
ha.setStoreUri("smtp+ssl://user:password@server"); Utility.setHostAuthFromString(ha, "smtp+ssl://user:password@server");
assertEquals(465, ha.mPort); assertEquals(465, ha.mPort);
ha.setStoreUri("smtp+ssl+trustallcerts://user:password@server"); Utility.setHostAuthFromString(ha, "smtp+ssl+trustallcerts://user:password@server");
assertEquals(465, ha.mPort); assertEquals(465, ha.mPort);
ha.setStoreUri("smtp+tls://user:password@server"); Utility.setHostAuthFromString(ha, "smtp+tls://user:password@server");
assertEquals(587, ha.mPort); assertEquals(587, ha.mPort);
ha.setStoreUri("smtp+tls+trustallcerts://user:password@server"); Utility.setHostAuthFromString(ha, "smtp+tls+trustallcerts://user:password@server");
assertEquals(587, ha.mPort); assertEquals(587, ha.mPort);
} }
/** /**
* Test preservation of username & password in URI * Test preservation of username & password in URI
*/ */
@SuppressWarnings("deprecation") public void testHostAuthUri()
public void testHostAuthUri() { throws URISyntaxException {
HostAuth ha = new HostAuth(); HostAuth ha = new HostAuth();
ha.setStoreUri("protocol://user:password@server:123"); Utility.setHostAuthFromString(ha, "protocol://user:password@server:123");
String getUri = ha.getStoreUri(); String getUri = ha.getStoreUri();
assertEquals("protocol://user:password@server:123", getUri); assertEquals("protocol://user:password@server:123", getUri);
// Now put spaces in/around username (they are trimmed) // Now put spaces in/around username (they are trimmed)
ha.setStoreUri("protocol://%20us%20er%20:password@server:123"); Utility.setHostAuthFromString(ha, "protocol://%20us%20er%20:password@server:123");
getUri = ha.getStoreUri(); getUri = ha.getStoreUri();
assertEquals("protocol://us%20er:password@server:123", getUri); assertEquals("protocol://us%20er:password@server:123", getUri);
// Now put spaces around password (should not be trimmed) // Now put spaces around password (should not be trimmed)
ha.setStoreUri("protocol://user:%20pass%20word%20@server:123"); Utility.setHostAuthFromString(ha, "protocol://user:%20pass%20word%20@server:123");
getUri = ha.getStoreUri(); getUri = ha.getStoreUri();
assertEquals("protocol://user:%20pass%20word%20@server:123", getUri); assertEquals("protocol://user:%20pass%20word%20@server:123", getUri);
} }
/**
* Test user name and password are set correctly
*/
public void testHostAuthSetLogin() {
HostAuth ha = new HostAuth();
ha.setLogin("user:password");
assertEquals("user", ha.mLogin);
assertEquals("password", ha.mPassword);
// special characters are not removed during insertion
ha.setLogin("%20us%20er%20:password");
assertEquals("%20us%20er%20", ha.mLogin);
assertEquals("password", ha.mPassword);
// special characters are not removed during insertion
ha.setLogin("user:%20pass%20word%20");
assertEquals("user", ha.mLogin);
assertEquals("%20pass%20word%20", ha.mPassword);
ha.setLogin("user:");
assertEquals("user", ha.mLogin);
assertEquals("", ha.mPassword);
ha.setLogin(":password");
assertEquals("", ha.mLogin);
assertEquals("password", ha.mPassword);
ha.setLogin("");
assertNull(ha.mLogin);
assertNull(ha.mPassword);
ha.setLogin(null);
assertNull(ha.mLogin);
assertNull(ha.mPassword);
ha.setLogin("userpassword");
assertEquals("userpassword", ha.mLogin);
assertNull(ha.mPassword);
}
/**
* Test the authentication flag is set correctly when setting user name and password
*/
public void testHostAuthSetLoginAuthenticate() {
HostAuth ha = new HostAuth();
ha.mFlags = 0x00000000;
ha.setLogin("user", "password");
assertEquals(HostAuth.FLAG_AUTHENTICATE, ha.mFlags);
ha.mFlags = 0x00000000;
ha.setLogin("user", "");
assertEquals(HostAuth.FLAG_AUTHENTICATE, ha.mFlags);
ha.mFlags = 0x00000000;
ha.setLogin("", "password");
assertEquals(HostAuth.FLAG_AUTHENTICATE, ha.mFlags);
ha.mFlags = 0x00000000;
ha.setLogin("user", null);
assertEquals(HostAuth.FLAG_AUTHENTICATE, ha.mFlags);
ha.mFlags = 0xffffffff;
ha.setLogin(null, "password");
assertEquals(~HostAuth.FLAG_AUTHENTICATE, ha.mFlags);
ha.mFlags = 0xffffffff;
ha.setLogin(null, null);
assertEquals(~HostAuth.FLAG_AUTHENTICATE, ha.mFlags);
}
/**
* Test setting the connection using a URI scheme
*/
public void testHostAuthSetConnectionScheme() {
HostAuth ha = new HostAuth();
// Set URIs for IMAP
// Hardwired port
ha.setConnection("imap", "server", 123);
assertEquals(0, ha.mFlags);
assertEquals(123, ha.mPort);
// Auto-assigned ports
ha.setConnection("imap", "server", -1);
assertEquals(0, ha.mFlags);
assertEquals(143, ha.mPort);
ha.setConnection("imap+ssl", "server", -1);
assertEquals(HostAuth.FLAG_SSL, ha.mFlags);
assertEquals(993, ha.mPort);
ha.setConnection("imap+ssl+trustallcerts", "server", -1);
assertEquals(HostAuth.FLAG_SSL|HostAuth.FLAG_TRUST_ALL, ha.mFlags);
assertEquals(993, ha.mPort);
ha.setConnection("imap+tls", "server", -1);
assertEquals(HostAuth.FLAG_TLS, ha.mFlags);
assertEquals(143, ha.mPort);
ha.setConnection("imap+tls+trustallcerts", "server", -1);
assertEquals(HostAuth.FLAG_TLS|HostAuth.FLAG_TRUST_ALL, ha.mFlags);
assertEquals(143, ha.mPort);
// Set URIs for POP3
// Hardwired port
ha.setConnection("pop3", "server", 123);
assertEquals(0, ha.mFlags);
assertEquals(123, ha.mPort);
// Auto-assigned ports
ha.setConnection("pop3", "server", -1);
assertEquals(0, ha.mFlags);
assertEquals(110, ha.mPort);
ha.setConnection("pop3+ssl", "server", -1);
assertEquals(HostAuth.FLAG_SSL, ha.mFlags);
assertEquals(995, ha.mPort);
ha.setConnection("pop3+ssl+trustallcerts", "server", -1);
assertEquals(HostAuth.FLAG_SSL|HostAuth.FLAG_TRUST_ALL, ha.mFlags);
assertEquals(995, ha.mPort);
ha.setConnection("pop3+tls", "server", -1);
assertEquals(HostAuth.FLAG_TLS, ha.mFlags);
assertEquals(110, ha.mPort);
ha.setConnection("pop3+tls+trustallcerts", "server", -1);
assertEquals(HostAuth.FLAG_TLS|HostAuth.FLAG_TRUST_ALL, ha.mFlags);
assertEquals(110, ha.mPort);
// Set URIs for Exchange
// Hardwired port
ha.setConnection("eas", "server", 123);
assertEquals(0, ha.mFlags);
assertEquals(123, ha.mPort);
// Auto-assigned ports
ha.setConnection("eas", "server", -1);
assertEquals(0, ha.mFlags);
assertEquals(80, ha.mPort);
ha.setConnection("eas+ssl", "server", -1);
assertEquals(HostAuth.FLAG_SSL, ha.mFlags);
assertEquals(443, ha.mPort);
ha.setConnection("eas+ssl+trustallcerts", "server", -1);
assertEquals(HostAuth.FLAG_SSL|HostAuth.FLAG_TRUST_ALL, ha.mFlags);
assertEquals(443, ha.mPort);
// Set URIs for SMTP
// Hardwired port
ha.setConnection("smtp", "server", 123);
assertEquals(0, ha.mFlags);
assertEquals(123, ha.mPort);
// Auto-assigned ports
ha.setConnection("smtp", "server", -1);
assertEquals(0, ha.mFlags);
assertEquals(587, ha.mPort);
ha.setConnection("smtp+ssl", "server", -1);
assertEquals(HostAuth.FLAG_SSL, ha.mFlags);
assertEquals(465, ha.mPort);
ha.setConnection("smtp+ssl+trustallcerts", "server", -1);
assertEquals(HostAuth.FLAG_SSL|HostAuth.FLAG_TRUST_ALL, ha.mFlags);
assertEquals(465, ha.mPort);
ha.setConnection("smtp+tls", "server", -1);
assertEquals(HostAuth.FLAG_TLS, ha.mFlags);
assertEquals(587, ha.mPort);
ha.setConnection("smtp+tls+trustallcerts", "server", -1);
assertEquals(HostAuth.FLAG_TLS|HostAuth.FLAG_TRUST_ALL, ha.mFlags);
assertEquals(587, ha.mPort);
}
/**
* Test setting the connection using a protocol and flags
*/
public void testHostAuthSetConnectionFlags() {
HostAuth ha = new HostAuth();
// Different port types don't affect flags
ha.setConnection("imap", "server", 123, 0);
assertEquals(0, ha.mFlags);
ha.setConnection("imap", "server", -1, 0);
assertEquals(0, ha.mFlags);
// Different protocol types don't affect flags
ha.setConnection("pop3", "server", 123, 0);
assertEquals(0, ha.mFlags);
ha.setConnection("pop3", "server", -1, 0);
assertEquals(0, ha.mFlags);
ha.setConnection("eas", "server", 123, 0);
assertEquals(0, ha.mFlags);
ha.setConnection("eas", "server", -1, 0);
assertEquals(0, ha.mFlags);
ha.setConnection("smtp", "server", 123, 0);
assertEquals(0, ha.mFlags);
ha.setConnection("smtp", "server", -1, 0);
assertEquals(0, ha.mFlags);
// Sets SSL flag
ha.setConnection("imap", "server", -1, HostAuth.FLAG_SSL);
assertEquals(HostAuth.FLAG_SSL, ha.mFlags);
// Sets SSL+Trusted flags
ha.setConnection("imap", "server", -1, HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL);
assertEquals(HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL, ha.mFlags);
// Sets TLS flag
ha.setConnection("imap", "server", -1, HostAuth.FLAG_TLS);
assertEquals(HostAuth.FLAG_TLS, ha.mFlags);
// Sets TLS+Trusted flags
ha.setConnection("imap", "server", -1, HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL);
assertEquals(HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL, ha.mFlags);
// Test other defined flags; should not affect mFlags
ha.setConnection("imap", "server", -1, HostAuth.FLAG_AUTHENTICATE);
assertEquals(0, ha.mFlags);
// Test every other bit; should not affect mFlags
ha.setConnection("imap", "server", -1, 0xfffffff4);
assertEquals(0, ha.mFlags);
}
public void testHostAuthGetSchemeString() {
String scheme;
scheme = HostAuth.getSchemeString("foo", 0);
assertEquals("foo", scheme);
scheme = HostAuth.getSchemeString("foo", HostAuth.FLAG_SSL);
assertEquals("foo+ssl+", scheme);
scheme = HostAuth.getSchemeString("foo", HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL);
assertEquals("foo+ssl+trustallcerts", scheme);
scheme = HostAuth.getSchemeString("foo", HostAuth.FLAG_TLS);
assertEquals("foo+tls+", scheme);
scheme = HostAuth.getSchemeString("foo", HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL);
assertEquals("foo+tls+trustallcerts", scheme);
// error cases; no security string appended to protocol
scheme = HostAuth.getSchemeString("foo", HostAuth.FLAG_TRUST_ALL);
assertEquals("foo", scheme);
scheme = HostAuth.getSchemeString("foo", HostAuth.FLAG_SSL | HostAuth.FLAG_TLS);
assertEquals("foo", scheme);
scheme = HostAuth.getSchemeString("foo", HostAuth.FLAG_SSL | HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL);
assertEquals("foo", scheme);
scheme = HostAuth.getSchemeString("foo", 0xfffffff4);
assertEquals("foo", scheme);
}
public void testHostAuthGetSchemeFlags() {
int flags;
flags = HostAuth.getSchemeFlags("");
assertEquals(0, flags);
flags = HostAuth.getSchemeFlags("+");
assertEquals(0, flags);
flags = HostAuth.getSchemeFlags("foo+");
assertEquals(0, flags);
flags = HostAuth.getSchemeFlags("foo+ssl");
assertEquals(HostAuth.FLAG_SSL, flags);
flags = HostAuth.getSchemeFlags("foo+ssl+");
assertEquals(HostAuth.FLAG_SSL, flags);
flags = HostAuth.getSchemeFlags("foo+ssl+trustallcerts");
assertEquals(HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL, flags);
flags = HostAuth.getSchemeFlags("foo+tls+");
assertEquals(HostAuth.FLAG_TLS, flags);
flags = HostAuth.getSchemeFlags("foo+tls+trustallcerts");
assertEquals(HostAuth.FLAG_TLS | HostAuth.FLAG_TRUST_ALL, flags);
flags = HostAuth.getSchemeFlags("foo+bogus");
assertEquals(0, flags);
flags = HostAuth.getSchemeFlags("foo+bogus+trustallcerts");
assertEquals(HostAuth.FLAG_TRUST_ALL, flags);
flags = HostAuth.getSchemeFlags("foo+ssl+bogus");
assertEquals(HostAuth.FLAG_SSL, flags);
flags = HostAuth.getSchemeFlags("foo+ssl+trustallcerts+bogus");
assertEquals(HostAuth.FLAG_SSL | HostAuth.FLAG_TRUST_ALL, flags);
flags = HostAuth.getSchemeFlags("foo+bogus+bogus");
assertEquals(0, flags);
flags = HostAuth.getSchemeFlags("foo+bogus+bogus+bogus");
assertEquals(0, flags);
}
/** /**
* Test simple mailbox save/retrieve * Test simple mailbox save/retrieve
*/ */