Merge "[Wi-Fi] Check if domain field is not empty when users choose a ca certificate"

This commit is contained in:
Arc Wang
2020-07-31 02:22:02 +00:00
committed by Android (Google) Code Review
4 changed files with 72 additions and 18 deletions

View File

@@ -549,12 +549,11 @@ public class WifiConfigController implements TextWatcher,
// Disallow submit if the user has not selected a CA certificate for an EAP network
// configuration.
enabled = false;
}
if (caCertSelection.equals(mUseSystemCertsString)
} else if (!caCertSelection.equals(mDoNotValidateEapServerString)
&& mEapDomainView != null
&& mView.findViewById(R.id.l_domain).getVisibility() != View.GONE
&& TextUtils.isEmpty(mEapDomainView.getText().toString())) {
// Disallow submit if the user chooses to use system certificates for EAP server
// Disallow submit if the user chooses to use a certificate for EAP server
// validation, but does not provide a domain.
enabled = false;
}
@@ -590,14 +589,12 @@ public class WifiConfigController implements TextWatcher,
// Display warning if user chooses not to validate the EAP server with a
// user-supplied CA certificate in an EAP network configuration.
mView.findViewById(R.id.no_ca_cert_warning).setVisibility(View.VISIBLE);
}
if (caCertSelection.equals(mUseSystemCertsString)
} else if (!caCertSelection.equals(mUnspecifiedCertString)
&& mEapDomainView != null
&& mView.findViewById(R.id.l_domain).getVisibility() != View.GONE
&& TextUtils.isEmpty(mEapDomainView.getText().toString())) {
// Display warning if user chooses to use pre-installed public CA certificates
// without restricting the server domain that these certificates can be used to
// validate.
// Display warning if user chooses to use a certificate without restricting the
// server domain that these certificates can be used to validate.
mView.findViewById(R.id.no_domain_warning).setVisibility(View.VISIBLE);
}
}
@@ -1703,7 +1700,8 @@ public class WifiConfigController implements TextWatcher,
mContext.getResources().getStringArray(contentStringArrayResId));
}
private ArrayAdapter<CharSequence> getSpinnerAdapter(
@VisibleForTesting
ArrayAdapter<CharSequence> getSpinnerAdapter(
String[] contentStringArray) {
ArrayAdapter<CharSequence> spinnerAdapter = new ArrayAdapter<>(mContext,
android.R.layout.simple_spinner_item, contentStringArray);

View File

@@ -518,12 +518,11 @@ public class WifiConfigController2 implements TextWatcher,
// Disallow submit if the user has not selected a CA certificate for an EAP network
// configuration.
enabled = false;
}
if (caCertSelection.equals(mUseSystemCertsString)
} else if (!caCertSelection.equals(mDoNotValidateEapServerString)
&& mEapDomainView != null
&& mView.findViewById(R.id.l_domain).getVisibility() != View.GONE
&& TextUtils.isEmpty(mEapDomainView.getText().toString())) {
// Disallow submit if the user chooses to use system certificates for EAP server
// Disallow submit if the user chooses to use a certificate for EAP server
// validation, but does not provide a domain.
enabled = false;
}
@@ -559,14 +558,12 @@ public class WifiConfigController2 implements TextWatcher,
// Display warning if user chooses not to validate the EAP server with a
// user-supplied CA certificate in an EAP network configuration.
mView.findViewById(R.id.no_ca_cert_warning).setVisibility(View.VISIBLE);
}
if (caCertSelection.equals(mUseSystemCertsString)
} else if (!caCertSelection.equals(mUnspecifiedCertString)
&& mEapDomainView != null
&& mView.findViewById(R.id.l_domain).getVisibility() != View.GONE
&& TextUtils.isEmpty(mEapDomainView.getText().toString())) {
// Display warning if user chooses to use pre-installed public CA certificates
// without restricting the server domain that these certificates can be used to
// validate.
// Display warning if user chooses to use a certificate without restricting the
// server domain that these certificates can be used to validate.
mView.findViewById(R.id.no_domain_warning).setVisibility(View.VISIBLE);
}
}
@@ -1736,7 +1733,8 @@ public class WifiConfigController2 implements TextWatcher,
mContext.getResources().getStringArray(contentStringArrayResId));
}
private ArrayAdapter<CharSequence> getSpinnerAdapter(
@VisibleForTesting
ArrayAdapter<CharSequence> getSpinnerAdapter(
String[] contentStringArray) {
ArrayAdapter<CharSequence> spinnerAdapter = new ArrayAdapter<>(mContext,
android.R.layout.simple_spinner_item, contentStringArray);

View File

@@ -233,6 +233,35 @@ public class WifiConfigController2Test {
assertThat(mController.isSubmittable()).isTrue();
}
@Test
public void isSubmittable_caCertWithoutDomain_shouldReturnFalse() {
when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
WifiConfigUiBase2.MODE_CONNECT);
mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
final Spinner eapCaCertSpinner = mView.findViewById(R.id.ca_cert);
eapCaCertSpinner.setAdapter(mController.getSpinnerAdapter(new String[]{"certificate"}));
eapCaCertSpinner.setSelection(0);
mView.findViewById(R.id.l_domain).setVisibility(View.VISIBLE);
assertThat(mController.isSubmittable()).isFalse();
}
@Test
public void isSubmittable_caCertWithDomain_shouldReturnTrue() {
when(mWifiEntry.getSecurity()).thenReturn(WifiEntry.SECURITY_EAP);
mController = new TestWifiConfigController2(mConfigUiBase, mView, mWifiEntry,
WifiConfigUiBase2.MODE_CONNECT);
mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
final Spinner eapCaCertSpinner = mView.findViewById(R.id.ca_cert);
eapCaCertSpinner.setAdapter(mController.getSpinnerAdapter(new String[]{"certificate"}));
eapCaCertSpinner.setSelection(0);
mView.findViewById(R.id.l_domain).setVisibility(View.VISIBLE);
((TextView) mView.findViewById(R.id.domain)).setText("fakeDomain");
assertThat(mController.isSubmittable()).isTrue();
}
@Test
public void getSignalString_notReachable_shouldHaveNoSignalString() {
when(mWifiEntry.getLevel()).thenReturn(WifiEntry.WIFI_LEVEL_UNREACHABLE);

View File

@@ -220,6 +220,35 @@ public class WifiConfigControllerTest {
assertThat(mController.isSubmittable()).isTrue();
}
@Test
public void isSubmittable_caCertWithoutDomain_shouldReturnFalse() {
when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_EAP);
mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint,
WifiConfigUiBase.MODE_CONNECT);
mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
final Spinner eapCaCertSpinner = mView.findViewById(R.id.ca_cert);
eapCaCertSpinner.setAdapter(mController.getSpinnerAdapter(new String[]{"certificate"}));
eapCaCertSpinner.setSelection(0);
mView.findViewById(R.id.l_domain).setVisibility(View.VISIBLE);
assertThat(mController.isSubmittable()).isFalse();
}
@Test
public void isSubmittable_caCertWithDomain_shouldReturnTrue() {
when(mAccessPoint.getSecurity()).thenReturn(AccessPoint.SECURITY_EAP);
mController = new TestWifiConfigController(mConfigUiBase, mView, mAccessPoint,
WifiConfigUiBase.MODE_CONNECT);
mView.findViewById(R.id.l_ca_cert).setVisibility(View.VISIBLE);
final Spinner eapCaCertSpinner = mView.findViewById(R.id.ca_cert);
eapCaCertSpinner.setAdapter(mController.getSpinnerAdapter(new String[]{"certificate"}));
eapCaCertSpinner.setSelection(0);
mView.findViewById(R.id.l_domain).setVisibility(View.VISIBLE);
((TextView) mView.findViewById(R.id.domain)).setText("fakeDomain");
assertThat(mController.isSubmittable()).isTrue();
}
@Test
public void getSignalString_notReachable_shouldHaveNoSignalString() {
when(mAccessPoint.isReachable()).thenReturn(false);