[Wi-Fi] Check if domain field is not empty when users choose a ca certificate
Domain is required for client to validate server's certificate.
This change disable Save button for a new Wi-Fi network of a
specified CA certificate but empty domain.
Bug: 161378819
Test: make RunSettingsRoboTests ROBOTEST_FILTER=WifiConfigControllerTest
make RunSettingsRoboTests ROBOTEST_FILTER=WifiConfigController2Test
manual
1. Install a certificate.
2. Add a new Wi-Fi network of EAP method PEAP
3. Set CA certificate to the certificate installed at 1.
4. Save button should be disabled.
5. Input something in domain field.
6. Save button should be enabled.
Change-Id: I65c8b29ec7a03b21403ddbfc087ce48c2a4a69e4
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 1579188..45cc8e5 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -554,12 +554,11 @@
// 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;
}
@@ -595,14 +594,12 @@
// 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);
}
}
@@ -1713,7 +1710,8 @@
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);
diff --git a/src/com/android/settings/wifi/WifiConfigController2.java b/src/com/android/settings/wifi/WifiConfigController2.java
index 99907f3..d80873f 100644
--- a/src/com/android/settings/wifi/WifiConfigController2.java
+++ b/src/com/android/settings/wifi/WifiConfigController2.java
@@ -533,12 +533,11 @@
// 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;
}
@@ -574,14 +573,12 @@
// 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);
}
}
@@ -1696,7 +1693,8 @@
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);
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
index e588799..06697fb 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigController2Test.java
@@ -225,6 +225,35 @@
}
@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);
diff --git a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
index 9146998..39f9cda 100644
--- a/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/WifiConfigControllerTest.java
@@ -219,6 +219,35 @@
}
@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);