Allow spaces in passwords
* Separate/identical fixes for incoming, outgoing, exchange * Unit tests * Some protocols will fail anyway (e.g. POP3) TODO: Some sort of warning (master only - won't backport that) Bug: 2981433 Change-Id: I82984e5912fc7fcb88e747815d0fe33cb36605e7
This commit is contained in:
parent
a1758ebc25
commit
fb4333b3a5
|
@ -336,7 +336,7 @@ public class AccountSetupExchangeFragment extends AccountServerBaseFragment
|
||||||
* 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)
|
||||||
|
@ -349,7 +349,7 @@ public class AccountSetupExchangeFragment extends AccountServerBaseFragment
|
||||||
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;
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ import android.os.Bundle;
|
||||||
public class AccountSetupIncoming extends AccountSetupActivity
|
public class AccountSetupIncoming extends AccountSetupActivity
|
||||||
implements AccountSetupIncomingFragment.Callback {
|
implements AccountSetupIncomingFragment.Callback {
|
||||||
|
|
||||||
private AccountSetupIncomingFragment mFragment;
|
/* package */ AccountSetupIncomingFragment mFragment;
|
||||||
/* package */ boolean mNextButtonEnabled;
|
/* package */ boolean mNextButtonEnabled;
|
||||||
|
|
||||||
public static void actionIncomingSettings(Activity fromActivity, int mode, Account account) {
|
public static void actionIncomingSettings(Activity fromActivity, int mode, Account account) {
|
||||||
|
|
|
@ -414,7 +414,7 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment {
|
||||||
* 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")) {
|
||||||
|
@ -424,7 +424,7 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment {
|
||||||
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
|
||||||
|
|
|
@ -33,7 +33,7 @@ import android.os.Bundle;
|
||||||
public class AccountSetupOutgoing extends Activity
|
public class AccountSetupOutgoing extends Activity
|
||||||
implements AccountSetupOutgoingFragment.Callback {
|
implements AccountSetupOutgoingFragment.Callback {
|
||||||
|
|
||||||
private AccountSetupOutgoingFragment mFragment;
|
/* package */ AccountSetupOutgoingFragment mFragment;
|
||||||
/* package */ boolean mNextButtonEnabled;
|
/* package */ boolean mNextButtonEnabled;
|
||||||
|
|
||||||
public static void actionOutgoingSettings(Activity fromActivity, int mode, Account account) {
|
public static void actionOutgoingSettings(Activity fromActivity, int mode, Account account) {
|
||||||
|
|
|
@ -353,12 +353,11 @@ public class AccountSetupOutgoingFragment extends AccountServerBaseFragment
|
||||||
* 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],
|
||||||
|
|
|
@ -30,6 +30,9 @@ import android.view.View;
|
||||||
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.
|
||||||
* You can run this entire test case with:
|
* You can run this entire test case with:
|
||||||
|
@ -40,7 +43,9 @@ public class AccountSetupExchangeTests extends
|
||||||
ActivityInstrumentationTestCase2<AccountSetupExchange> {
|
ActivityInstrumentationTestCase2<AccountSetupExchange> {
|
||||||
//EXCHANGE-REMOVE-SECTION-START
|
//EXCHANGE-REMOVE-SECTION-START
|
||||||
private AccountSetupExchange mActivity;
|
private AccountSetupExchange mActivity;
|
||||||
|
private AccountSetupExchangeFragment mFragment;
|
||||||
private EditText mServerView;
|
private EditText mServerView;
|
||||||
|
private EditText mPasswordView;
|
||||||
private CheckBox mSslRequiredCheckbox;
|
private CheckBox mSslRequiredCheckbox;
|
||||||
private CheckBox mTrustAllCertificatesCheckbox;
|
private CheckBox mTrustAllCertificatesCheckbox;
|
||||||
//EXCHANGE-REMOVE-SECTION-END
|
//EXCHANGE-REMOVE-SECTION-END
|
||||||
|
@ -125,6 +130,43 @@ public class AccountSetupExchangeTests extends
|
||||||
assertFalse(mActivity.mNextButtonEnabled);
|
assertFalse(mActivity.mNextButtonEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(mActivity.mNextButtonEnabled);
|
||||||
|
URI uri = mFragment.getUri();
|
||||||
|
String actualUserInfo = uri.getUserInfo();
|
||||||
|
String actualPassword = actualUserInfo.split(":", 2)[1];
|
||||||
|
assertEquals(password, actualPassword);
|
||||||
|
} else {
|
||||||
|
assertFalse(mActivity.mNextButtonEnabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test aspects of loadSettings()
|
* Test aspects of loadSettings()
|
||||||
*
|
*
|
||||||
|
@ -176,7 +218,9 @@ public class AccountSetupExchangeTests extends
|
||||||
*/
|
*/
|
||||||
private void getActivityAndFields() {
|
private void getActivityAndFields() {
|
||||||
mActivity = getActivity();
|
mActivity = getActivity();
|
||||||
|
mFragment = mActivity.mFragment;
|
||||||
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
|
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
|
||||||
|
mPasswordView = (EditText) mActivity.findViewById(R.id.account_password);
|
||||||
mSslRequiredCheckbox = (CheckBox) mActivity.findViewById(R.id.account_ssl);
|
mSslRequiredCheckbox = (CheckBox) mActivity.findViewById(R.id.account_ssl);
|
||||||
mTrustAllCertificatesCheckbox =
|
mTrustAllCertificatesCheckbox =
|
||||||
(CheckBox) mActivity.findViewById(R.id.account_trust_certificates);
|
(CheckBox) mActivity.findViewById(R.id.account_trust_certificates);
|
||||||
|
|
|
@ -25,6 +25,9 @@ import android.test.UiThreadTest;
|
||||||
import android.test.suitebuilder.annotation.MediumTest;
|
import android.test.suitebuilder.annotation.MediumTest;
|
||||||
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.
|
||||||
* You can run this entire test case with:
|
* You can run this entire test case with:
|
||||||
|
@ -35,7 +38,9 @@ public class AccountSetupIncomingTests extends
|
||||||
ActivityInstrumentationTestCase2<AccountSetupIncoming> {
|
ActivityInstrumentationTestCase2<AccountSetupIncoming> {
|
||||||
|
|
||||||
private AccountSetupIncoming mActivity;
|
private AccountSetupIncoming mActivity;
|
||||||
|
private AccountSetupIncomingFragment mFragment;
|
||||||
private EditText mServerView;
|
private EditText mServerView;
|
||||||
|
private EditText mPasswordView;
|
||||||
|
|
||||||
public AccountSetupIncomingTests() {
|
public AccountSetupIncomingTests() {
|
||||||
super(AccountSetupIncoming.class);
|
super(AccountSetupIncoming.class);
|
||||||
|
@ -122,7 +127,44 @@ public class AccountSetupIncomingTests extends
|
||||||
mServerView.setText("serv$er.com");
|
mServerView.setText("serv$er.com");
|
||||||
assertFalse(mActivity.mNextButtonEnabled);
|
assertFalse(mActivity.mNextButtonEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(mActivity.mNextButtonEnabled);
|
||||||
|
URI uri = mFragment.getUri();
|
||||||
|
String actualUserInfo = uri.getUserInfo();
|
||||||
|
String actualPassword = actualUserInfo.split(":", 2)[1];
|
||||||
|
assertEquals(password, actualPassword);
|
||||||
|
} else {
|
||||||
|
assertFalse(mActivity.mNextButtonEnabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
@ -133,7 +175,9 @@ public class AccountSetupIncomingTests extends
|
||||||
*/
|
*/
|
||||||
private void getActivityAndFields() {
|
private void getActivityAndFields() {
|
||||||
mActivity = getActivity();
|
mActivity = getActivity();
|
||||||
|
mFragment = mActivity.mFragment;
|
||||||
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
|
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
|
||||||
|
mPasswordView = (EditText) mActivity.findViewById(R.id.account_password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,6 +25,9 @@ import android.test.UiThreadTest;
|
||||||
import android.test.suitebuilder.annotation.MediumTest;
|
import android.test.suitebuilder.annotation.MediumTest;
|
||||||
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.
|
||||||
* You can run this entire test case with:
|
* You can run this entire test case with:
|
||||||
|
@ -35,7 +38,9 @@ public class AccountSetupOutgoingTests extends
|
||||||
ActivityInstrumentationTestCase2<AccountSetupOutgoing> {
|
ActivityInstrumentationTestCase2<AccountSetupOutgoing> {
|
||||||
|
|
||||||
private AccountSetupOutgoing mActivity;
|
private AccountSetupOutgoing mActivity;
|
||||||
|
private AccountSetupOutgoingFragment mFragment;
|
||||||
private EditText mServerView;
|
private EditText mServerView;
|
||||||
|
private EditText mPasswordView;
|
||||||
|
|
||||||
public AccountSetupOutgoingTests() {
|
public AccountSetupOutgoingTests() {
|
||||||
super(AccountSetupOutgoing.class);
|
super(AccountSetupOutgoing.class);
|
||||||
|
@ -120,7 +125,44 @@ public class AccountSetupOutgoingTests extends
|
||||||
mServerView.setText("serv$er.com");
|
mServerView.setText("serv$er.com");
|
||||||
assertFalse(mActivity.mNextButtonEnabled);
|
assertFalse(mActivity.mNextButtonEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(mActivity.mNextButtonEnabled);
|
||||||
|
URI uri = mFragment.getUri();
|
||||||
|
String actualUserInfo = uri.getUserInfo();
|
||||||
|
String actualPassword = actualUserInfo.split(":", 2)[1];
|
||||||
|
assertEquals(password, actualPassword);
|
||||||
|
} else {
|
||||||
|
assertFalse(mActivity.mNextButtonEnabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
|
@ -130,7 +172,9 @@ public class AccountSetupOutgoingTests extends
|
||||||
*/
|
*/
|
||||||
private void getActivityAndFields() {
|
private void getActivityAndFields() {
|
||||||
mActivity = getActivity();
|
mActivity = getActivity();
|
||||||
|
mFragment = mActivity.mFragment;
|
||||||
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
|
mServerView = (EditText) mActivity.findViewById(R.id.account_server);
|
||||||
|
mPasswordView = (EditText) mActivity.findViewById(R.id.account_password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue