Allow spaces in passwords DO NOT MERGE

* Separate/identical fixes for incoming, outgoing, exchange
* Unit tests
* Some protocols will fail anyway (e.g. POP3)

Bug: 2981433
Backport from: I82984e5912fc7fcb88e747815d0fe33cb36605e7

Change-Id: I49d5c13137e4f78b6fa0f9ce288c1a78ff028f88
This commit is contained in:
Andy Stadler 2010-09-27 13:31:04 -07:00
parent 0dd360c207
commit 02a0edb60d
6 changed files with 132 additions and 7 deletions

View File

@ -423,7 +423,7 @@ public class AccountSetupExchange extends Activity implements OnClickListener,
* a problem with the user input.
* @return a URI built from the account setup fields
*/
private URI getUri() throws URISyntaxException {
/* package */ URI getUri() throws URISyntaxException {
boolean sslRequired = mSslSecurityView.isChecked();
boolean trustCertificates = mTrustCertificatesView.isChecked();
String scheme = (sslRequired)
@ -436,7 +436,7 @@ public class AccountSetupExchange extends Activity implements OnClickListener,
userName = userName.substring(1);
}
mCacheLoginCredential = userName;
String userInfo = userName + ":" + mPasswordView.getText().toString().trim();
String userInfo = userName + ":" + mPasswordView.getText();
String host = mServerView.getText().toString().trim();
String path = null;

View File

@ -373,7 +373,7 @@ public class AccountSetupIncoming extends Activity implements OnClickListener {
* a problem with the user input.
* @return a URI built from the account setup fields
*/
private URI getUri() throws URISyntaxException {
/* package */ URI getUri() throws URISyntaxException {
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
String path = null;
if (mAccountSchemes[securityType].startsWith("imap")) {
@ -383,7 +383,7 @@ public class AccountSetupIncoming extends Activity implements OnClickListener {
mCacheLoginCredential = userName;
URI uri = new URI(
mAccountSchemes[securityType],
userName + ":" + mPasswordView.getText().toString().trim(),
userName + ":" + mPasswordView.getText(),
mServerView.getText().toString().trim(),
Integer.parseInt(mPortView.getText().toString().trim()),
path, // path

View File

@ -272,12 +272,11 @@ public class AccountSetupOutgoing extends Activity implements OnClickListener,
* a problem with the user input.
* @return a URI built from the account setup fields
*/
private URI getUri() throws URISyntaxException {
/* package */ URI getUri() throws URISyntaxException {
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
String userInfo = null;
if (mRequireLoginView.isChecked()) {
userInfo = mUsernameView.getText().toString().trim() + ":"
+ mPasswordView.getText().toString().trim();
userInfo = mUsernameView.getText().toString().trim() + ":" + mPasswordView.getText();
}
URI uri = new URI(
SMTP_SCHEMES[securityType],

View File

@ -31,6 +31,9 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Tests of the basic UI logic in the Account Setup Incoming (IMAP / POP3) screen.
*/
@ -40,6 +43,7 @@ public class AccountSetupExchangeTests extends
//EXCHANGE-REMOVE-SECTION-START
private AccountSetupExchange mActivity;
private EditText mServerView;
private EditText mPasswordView;
private Button mNextButton;
private CheckBox mSslRequiredCheckbox;
private CheckBox mTrustAllCertificatesCheckbox;
@ -160,6 +164,43 @@ public class AccountSetupExchangeTests extends
assertTrue(mTrustAllCertificatesCheckbox.getVisibility() == View.VISIBLE);
}
/**
* Test to confirm that passwords with leading or trailing spaces are accepted verbatim.
*/
@UiThreadTest
public void testPasswordNoTrim() throws URISyntaxException {
getActivityAndFields();
// Clear the password - should disable
checkPassword(null, false);
// Various combinations of spaces should be OK
checkPassword(" leading", true);
checkPassword("trailing ", true);
checkPassword("em bedded", true);
checkPassword(" ", true);
}
/**
* Check password field for a given password. Should be called in UI thread. Confirms that
* the password has not been trimmed.
*
* @param password the password to test with
* @param expectNext true if expected that this password will enable the "next" button
*/
private void checkPassword(String password, boolean expectNext) throws URISyntaxException {
mPasswordView.setText(password);
if (expectNext) {
assertTrue(mNextButton.isEnabled());
URI uri = mActivity.getUri();
String actualUserInfo = uri.getUserInfo();
String actualPassword = actualUserInfo.split(":", 2)[1];
assertEquals(password, actualPassword);
} else {
assertFalse(mNextButton.isEnabled());
}
}
/**
* TODO: Directly test validateFields() checking boolean result
*/
@ -170,6 +211,7 @@ public class AccountSetupExchangeTests extends
private void getActivityAndFields() {
mActivity = getActivity();
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
mPasswordView = (EditText) mActivity.findViewById(R.id.account_password);
mNextButton = (Button) mActivity.findViewById(R.id.next);
mSslRequiredCheckbox = (CheckBox) mActivity.findViewById(R.id.account_ssl);
mTrustAllCertificatesCheckbox =

View File

@ -26,6 +26,9 @@ import android.test.suitebuilder.annotation.MediumTest;
import android.widget.Button;
import android.widget.EditText;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Tests of the basic UI logic in the Account Setup Incoming (IMAP / POP3) screen.
*/
@ -38,6 +41,7 @@ public class AccountSetupIncomingTests extends
private AccountSetupIncoming mActivity;
private EditText mServerView;
private EditText mPasswordView;
private Button mNextButton;
public AccountSetupIncomingTests() {
@ -126,6 +130,43 @@ public class AccountSetupIncomingTests extends
assertFalse(mNextButton.isEnabled());
}
/**
* Test to confirm that passwords with leading or trailing spaces are accepted verbatim.
*/
@UiThreadTest
public void testPasswordNoTrim() throws URISyntaxException {
getActivityAndFields();
// Clear the password - should disable
checkPassword(null, false);
// Various combinations of spaces should be OK
checkPassword(" leading", true);
checkPassword("trailing ", true);
checkPassword("em bedded", true);
checkPassword(" ", true);
}
/**
* Check password field for a given password. Should be called in UI thread. Confirms that
* the password has not been trimmed.
*
* @param password the password to test with
* @param expectNext true if expected that this password will enable the "next" button
*/
private void checkPassword(String password, boolean expectNext) throws URISyntaxException {
mPasswordView.setText(password);
if (expectNext) {
assertTrue(mNextButton.isEnabled());
URI uri = mActivity.getUri();
String actualUserInfo = uri.getUserInfo();
String actualPassword = actualUserInfo.split(":", 2)[1];
assertEquals(password, actualPassword);
} else {
assertFalse(mNextButton.isEnabled());
}
}
/**
* TODO: A series of tests to explore the logic around security models & ports
* TODO: A series of tests exploring differences between IMAP and POP3
@ -137,6 +178,7 @@ public class AccountSetupIncomingTests extends
private void getActivityAndFields() {
mActivity = getActivity();
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
mPasswordView = (EditText) mActivity.findViewById(R.id.account_password);
mNextButton = (Button) mActivity.findViewById(R.id.next);
}

View File

@ -26,6 +26,9 @@ import android.test.suitebuilder.annotation.MediumTest;
import android.widget.Button;
import android.widget.EditText;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Tests of the basic UI logic in the Account Setup Outgoing (SMTP) screen.
*/
@ -35,6 +38,7 @@ public class AccountSetupOutgoingTests extends
private AccountSetupOutgoing mActivity;
private EditText mServerView;
private EditText mPasswordView;
private Button mNextButton;
public AccountSetupOutgoingTests() {
@ -121,6 +125,43 @@ public class AccountSetupOutgoingTests extends
assertFalse(mNextButton.isEnabled());
}
/**
* Test to confirm that passwords with leading or trailing spaces are accepted verbatim.
*/
@UiThreadTest
public void testPasswordNoTrim() throws URISyntaxException {
getActivityAndFields();
// Clear the password - should disable
checkPassword(null, false);
// Various combinations of spaces should be OK
checkPassword(" leading", true);
checkPassword("trailing ", true);
checkPassword("em bedded", true);
checkPassword(" ", true);
}
/**
* Check password field for a given password. Should be called in UI thread. Confirms that
* the password has not been trimmed.
*
* @param password the password to test with
* @param expectNext true if expected that this password will enable the "next" button
*/
private void checkPassword(String password, boolean expectNext) throws URISyntaxException {
mPasswordView.setText(password);
if (expectNext) {
assertTrue(mNextButton.isEnabled());
URI uri = mActivity.getUri();
String actualUserInfo = uri.getUserInfo();
String actualPassword = actualUserInfo.split(":", 2)[1];
assertEquals(password, actualPassword);
} else {
assertFalse(mNextButton.isEnabled());
}
}
/**
* TODO: A series of tests to explore the logic around security models & ports
*/
@ -131,6 +172,7 @@ public class AccountSetupOutgoingTests extends
private void getActivityAndFields() {
mActivity = getActivity();
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
mPasswordView = (EditText) mActivity.findViewById(R.id.account_password);
mNextButton = (Button) mActivity.findViewById(R.id.next);
}