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:
parent
0dd360c207
commit
02a0edb60d
@ -423,7 +423,7 @@ public class AccountSetupExchange extends Activity implements OnClickListener,
|
|||||||
* a problem with the user input.
|
* a problem with the user input.
|
||||||
* @return a URI built from the account setup fields
|
* @return a URI built from the account setup fields
|
||||||
*/
|
*/
|
||||||
private URI getUri() throws URISyntaxException {
|
/* package */ URI getUri() throws URISyntaxException {
|
||||||
boolean sslRequired = mSslSecurityView.isChecked();
|
boolean sslRequired = mSslSecurityView.isChecked();
|
||||||
boolean trustCertificates = mTrustCertificatesView.isChecked();
|
boolean trustCertificates = mTrustCertificatesView.isChecked();
|
||||||
String scheme = (sslRequired)
|
String scheme = (sslRequired)
|
||||||
@ -436,7 +436,7 @@ public class AccountSetupExchange extends Activity implements OnClickListener,
|
|||||||
userName = userName.substring(1);
|
userName = userName.substring(1);
|
||||||
}
|
}
|
||||||
mCacheLoginCredential = userName;
|
mCacheLoginCredential = userName;
|
||||||
String userInfo = userName + ":" + mPasswordView.getText().toString().trim();
|
String userInfo = userName + ":" + mPasswordView.getText();
|
||||||
String host = mServerView.getText().toString().trim();
|
String host = mServerView.getText().toString().trim();
|
||||||
String path = null;
|
String path = null;
|
||||||
|
|
||||||
|
@ -373,7 +373,7 @@ public class AccountSetupIncoming extends Activity implements OnClickListener {
|
|||||||
* a problem with the user input.
|
* a problem with the user input.
|
||||||
* @return a URI built from the account setup fields
|
* @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;
|
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
||||||
String path = null;
|
String path = null;
|
||||||
if (mAccountSchemes[securityType].startsWith("imap")) {
|
if (mAccountSchemes[securityType].startsWith("imap")) {
|
||||||
@ -383,7 +383,7 @@ public class AccountSetupIncoming extends Activity implements OnClickListener {
|
|||||||
mCacheLoginCredential = userName;
|
mCacheLoginCredential = userName;
|
||||||
URI uri = new URI(
|
URI uri = new URI(
|
||||||
mAccountSchemes[securityType],
|
mAccountSchemes[securityType],
|
||||||
userName + ":" + mPasswordView.getText().toString().trim(),
|
userName + ":" + mPasswordView.getText(),
|
||||||
mServerView.getText().toString().trim(),
|
mServerView.getText().toString().trim(),
|
||||||
Integer.parseInt(mPortView.getText().toString().trim()),
|
Integer.parseInt(mPortView.getText().toString().trim()),
|
||||||
path, // path
|
path, // path
|
||||||
|
@ -272,12 +272,11 @@ public class AccountSetupOutgoing extends Activity implements OnClickListener,
|
|||||||
* a problem with the user input.
|
* a problem with the user input.
|
||||||
* @return a URI built from the account setup fields
|
* @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;
|
int securityType = (Integer)((SpinnerOption)mSecurityTypeView.getSelectedItem()).value;
|
||||||
String userInfo = null;
|
String userInfo = null;
|
||||||
if (mRequireLoginView.isChecked()) {
|
if (mRequireLoginView.isChecked()) {
|
||||||
userInfo = mUsernameView.getText().toString().trim() + ":"
|
userInfo = mUsernameView.getText().toString().trim() + ":" + mPasswordView.getText();
|
||||||
+ mPasswordView.getText().toString().trim();
|
|
||||||
}
|
}
|
||||||
URI uri = new URI(
|
URI uri = new URI(
|
||||||
SMTP_SCHEMES[securityType],
|
SMTP_SCHEMES[securityType],
|
||||||
|
@ -31,6 +31,9 @@ import android.widget.Button;
|
|||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.EditText;
|
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.
|
* 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
|
//EXCHANGE-REMOVE-SECTION-START
|
||||||
private AccountSetupExchange mActivity;
|
private AccountSetupExchange mActivity;
|
||||||
private EditText mServerView;
|
private EditText mServerView;
|
||||||
|
private EditText mPasswordView;
|
||||||
private Button mNextButton;
|
private Button mNextButton;
|
||||||
private CheckBox mSslRequiredCheckbox;
|
private CheckBox mSslRequiredCheckbox;
|
||||||
private CheckBox mTrustAllCertificatesCheckbox;
|
private CheckBox mTrustAllCertificatesCheckbox;
|
||||||
@ -160,6 +164,43 @@ public class AccountSetupExchangeTests extends
|
|||||||
assertTrue(mTrustAllCertificatesCheckbox.getVisibility() == View.VISIBLE);
|
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
|
* TODO: Directly test validateFields() checking boolean result
|
||||||
*/
|
*/
|
||||||
@ -170,6 +211,7 @@ public class AccountSetupExchangeTests extends
|
|||||||
private void getActivityAndFields() {
|
private void getActivityAndFields() {
|
||||||
mActivity = getActivity();
|
mActivity = getActivity();
|
||||||
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
|
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
|
||||||
|
mPasswordView = (EditText) mActivity.findViewById(R.id.account_password);
|
||||||
mNextButton = (Button) mActivity.findViewById(R.id.next);
|
mNextButton = (Button) mActivity.findViewById(R.id.next);
|
||||||
mSslRequiredCheckbox = (CheckBox) mActivity.findViewById(R.id.account_ssl);
|
mSslRequiredCheckbox = (CheckBox) mActivity.findViewById(R.id.account_ssl);
|
||||||
mTrustAllCertificatesCheckbox =
|
mTrustAllCertificatesCheckbox =
|
||||||
|
@ -26,6 +26,9 @@ import android.test.suitebuilder.annotation.MediumTest;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
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.
|
* 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 AccountSetupIncoming mActivity;
|
||||||
private EditText mServerView;
|
private EditText mServerView;
|
||||||
|
private EditText mPasswordView;
|
||||||
private Button mNextButton;
|
private Button mNextButton;
|
||||||
|
|
||||||
public AccountSetupIncomingTests() {
|
public AccountSetupIncomingTests() {
|
||||||
@ -126,6 +130,43 @@ public class AccountSetupIncomingTests extends
|
|||||||
assertFalse(mNextButton.isEnabled());
|
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 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
|
||||||
@ -137,6 +178,7 @@ public class AccountSetupIncomingTests extends
|
|||||||
private void getActivityAndFields() {
|
private void getActivityAndFields() {
|
||||||
mActivity = getActivity();
|
mActivity = getActivity();
|
||||||
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
|
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
|
||||||
|
mPasswordView = (EditText) mActivity.findViewById(R.id.account_password);
|
||||||
mNextButton = (Button) mActivity.findViewById(R.id.next);
|
mNextButton = (Button) mActivity.findViewById(R.id.next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,9 @@ import android.test.suitebuilder.annotation.MediumTest;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
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.
|
* 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 AccountSetupOutgoing mActivity;
|
||||||
private EditText mServerView;
|
private EditText mServerView;
|
||||||
|
private EditText mPasswordView;
|
||||||
private Button mNextButton;
|
private Button mNextButton;
|
||||||
|
|
||||||
public AccountSetupOutgoingTests() {
|
public AccountSetupOutgoingTests() {
|
||||||
@ -121,6 +125,43 @@ public class AccountSetupOutgoingTests extends
|
|||||||
assertFalse(mNextButton.isEnabled());
|
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 to explore the logic around security models & ports
|
||||||
*/
|
*/
|
||||||
@ -131,6 +172,7 @@ public class AccountSetupOutgoingTests extends
|
|||||||
private void getActivityAndFields() {
|
private void getActivityAndFields() {
|
||||||
mActivity = getActivity();
|
mActivity = getActivity();
|
||||||
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
|
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
|
||||||
|
mPasswordView = (EditText) mActivity.findViewById(R.id.account_password);
|
||||||
mNextButton = (Button) mActivity.findViewById(R.id.next);
|
mNextButton = (Button) mActivity.findViewById(R.id.next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user