From 9eba9df34d6235da16f2b08be81ac79ae2367f08 Mon Sep 17 00:00:00 2001 From: Peter Qiu Date: Fri, 30 Sep 2016 14:40:12 -0700 Subject: Remove test files for frameworks/base/wifi (android.net.wifi.*) Those test files had already been copied over to frameworks/base/wifi/tests. Bug: 31745421 Test: frameworks/opt/net/wifi/tests/wifitests/runtest.sh Change-Id: I2fe972e57e11951a9fffbf1cbba854e2a67a56f2 --- tests/wifitests/Android.mk | 2 +- tests/wifitests/coverage.sh | 3 +- tests/wifitests/src/android/net/wifi/FakeKeys.java | 67 ----- .../android/net/wifi/WifiEnterpriseConfigTest.java | 282 --------------------- .../src/android/net/wifi/WifiScannerTest.java | 111 -------- .../src/com/android/server/wifi/FakeKeys.java | 67 +++++ .../server/wifi/WifiConfigurationTestUtil.java | 1 - .../server/wifi/WifiConfigurationUtilTest.java | 1 - 8 files changed, 69 insertions(+), 465 deletions(-) delete mode 100644 tests/wifitests/src/android/net/wifi/FakeKeys.java delete mode 100644 tests/wifitests/src/android/net/wifi/WifiEnterpriseConfigTest.java delete mode 100644 tests/wifitests/src/android/net/wifi/WifiScannerTest.java create mode 100644 tests/wifitests/src/com/android/server/wifi/FakeKeys.java (limited to 'tests') diff --git a/tests/wifitests/Android.mk b/tests/wifitests/Android.mk index 6d3ff8785..e0ca76b9c 100644 --- a/tests/wifitests/Android.mk +++ b/tests/wifitests/Android.mk @@ -89,7 +89,7 @@ space:= $(empty) $(empty) # These patterns will match all classes in this module and their inner classes. jacoco_exclude := $(subst $(space),$(comma),$(patsubst %,%*,$(local_classes))) -jacoco_include := com.android.server.wifi.*,android.net.wifi.* +jacoco_include := com.android.server.wifi.* LOCAL_JACK_COVERAGE_INCLUDE_FILTER := $(jacoco_include) LOCAL_JACK_COVERAGE_EXCLUDE_FILTER := $(jacoco_exclude) diff --git a/tests/wifitests/coverage.sh b/tests/wifitests/coverage.sh index 348054137..bf50dee80 100755 --- a/tests/wifitests/coverage.sh +++ b/tests/wifitests/coverage.sh @@ -56,5 +56,4 @@ java -jar $REPORTER_JAR \ --coverage-file $COVERAGE_OUTPUT_FILE \ --report-type $REPORT_TYPE \ --source-dir $ANDROID_BUILD_TOP/frameworks/opt/net/wifi/tests/wifitests/src \ - --source-dir $ANDROID_BUILD_TOP/frameworks/opt/net/wifi/service/java \ - --source-dir $ANDROID_BUILD_TOP/frameworks/base/wifi/java + --source-dir $ANDROID_BUILD_TOP/frameworks/opt/net/wifi/service/java diff --git a/tests/wifitests/src/android/net/wifi/FakeKeys.java b/tests/wifitests/src/android/net/wifi/FakeKeys.java deleted file mode 100644 index 8a1e7b47f..000000000 --- a/tests/wifitests/src/android/net/wifi/FakeKeys.java +++ /dev/null @@ -1,67 +0,0 @@ -package android.net.wifi; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; - -/** - * A class containing test certificates. - */ -public class FakeKeys { - private static final String CA_CERT0_STRING = "-----BEGIN CERTIFICATE-----\n" + - "MIIDKDCCAhCgAwIBAgIJAILlFdwzLVurMA0GCSqGSIb3DQEBCwUAMBIxEDAOBgNV\n" + - "BAMTB0VBUCBDQTEwHhcNMTYwMTEyMTE1MDE1WhcNMjYwMTA5MTE1MDE1WjASMRAw\n" + - "DgYDVQQDEwdFQVAgQ0ExMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA\n" + - "znAPUz26Msae4ws43czR41/J2QtrSIZUKmVUsVumDbYHrPNvTXKSMXAcewORDQYX\n" + - "RqvHvpn8CscB1+oGXZvHwxj4zV0WKoK2zeXkau3vcyl3HIKupJfq2TEACefVjj0t\n" + - "JW+X35PGWp9/H5zIUNVNVjS7Ums84IvKhRB8512PB9UyHagXYVX5GWpAcVpyfrlR\n" + - "FI9Qdhh+Pbk0uyktdbf/CdfgHOoebrTtwRljM0oDtX+2Cv6j0wBK7hD8pPvf1+uy\n" + - "GzczigAU/4Kw7eZqydf9B+5RupR+IZipX41xEiIrKRwqi517WWzXcjaG2cNbf451\n" + - "xpH5PnV3i1tq04jMGQUzFwIDAQABo4GAMH4wHQYDVR0OBBYEFIwX4vs8BiBcScod\n" + - "5noZHRM8E4+iMEIGA1UdIwQ7MDmAFIwX4vs8BiBcScod5noZHRM8E4+ioRakFDAS\n" + - "MRAwDgYDVQQDEwdFQVAgQ0ExggkAguUV3DMtW6swDAYDVR0TBAUwAwEB/zALBgNV\n" + - "HQ8EBAMCAQYwDQYJKoZIhvcNAQELBQADggEBAFfQqOTA7Rv7K+luQ7pnas4BYwHE\n" + - "9GEP/uohv6KOy0TGQFbrRTjFoLVNB9BZ1ymMDZ0/TIwIUc7wi7a8t5mEqYH153wW\n" + - "aWooiSjyLLhuI4sNrNCOtisdBq2r2MFXt6h0mAQYOPv8R8K7/fgSxGFqzhyNmmVL\n" + - "1qBJldx34SpwsTALQVPb4hGwJzZfr1PcpEQx6xMnTl8xEWZE3Ms99uaUxbQqIwRu\n" + - "LgAOkNCmY2m89VhzaHJ1uV85AdM/tD+Ysmlnnjt9LRCejbBipjIGjOXrg1JP+lxV\n" + - "muM4vH+P/mlmxsPPz0d65b+EGmJZpoLkO/tdNNvCYzjJpTEWpEsO6NMhKYo=\n" + - "-----END CERTIFICATE-----\n"; - public static final X509Certificate CA_CERT0 = loadCertificate(CA_CERT0_STRING); - - private static final String CA_CERT1_STRING = "-----BEGIN CERTIFICATE-----\n" + - "MIIDKDCCAhCgAwIBAgIJAOM5SzKO2pzCMA0GCSqGSIb3DQEBCwUAMBIxEDAOBgNV\n" + - "BAMTB0VBUCBDQTAwHhcNMTYwMTEyMDAxMDQ3WhcNMjYwMTA5MDAxMDQ3WjASMRAw\n" + - "DgYDVQQDEwdFQVAgQ0EwMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA\n" + - "89ug+IEKVQXnJGKg5g4uVHg6J/8iRUxR5k2eH5o03hrJNMfN2D+cBe/wCiZcnWbI\n" + - "GbGZACWm2nQth2wy9Zgm2LOd3b4ocrHYls3XLq6Qb5Dd7a0JKU7pdGufiNVEkrmF\n" + - "EB+N64wgwH4COTvCiN4erp5kyJwkfqAl2xLkZo0C464c9XoyQOXbmYD9A8v10wZu\n" + - "jyNsEo7Nr2USyw+qhjWSbFbEirP77Tvx+7pJQJwdtk1V9Tn73T2dGF2WHYejei9S\n" + - "mcWpdIUqsu9etYH+zDmtu7I1xlkwiaVsNr2+D+qaCJyOYqrDTKVNK5nmbBPXDWZc\n" + - "NoDbTOoqquX7xONpq9M6jQIDAQABo4GAMH4wHQYDVR0OBBYEFAZ3A2S4qJZZwuNY\n" + - "wkJ6mAdc0gVdMEIGA1UdIwQ7MDmAFAZ3A2S4qJZZwuNYwkJ6mAdc0gVdoRakFDAS\n" + - "MRAwDgYDVQQDEwdFQVAgQ0EwggkA4zlLMo7anMIwDAYDVR0TBAUwAwEB/zALBgNV\n" + - "HQ8EBAMCAQYwDQYJKoZIhvcNAQELBQADggEBAHmdMwEhtys4d0E+t7owBmoVR+lU\n" + - "hMCcRtWs8YKX5WIM2kTweT0h/O1xwE1mWmRv/IbDAEb8od4BjAQLhIcolStr2JaO\n" + - "9ZzyxjOnNzqeErh/1DHDbb/moPpqfeJ8YiEz7nH/YU56Q8iCPO7TsgS0sNNE7PfN\n" + - "IUsBW0yHRgpQ4OxWmiZG2YZWiECRzAC0ecPzo59N5iH4vLQIMTMYquiDeMPQnn1e\n" + - "NDGxG8gCtDKIaS6tMg3a28MvWB094pr2ETou8O1C8Ji0Y4hE8QJmSdT7I4+GZjgW\n" + - "g94DZ5RiL7sdp3vC48CXOmeT61YBIvhGUsE1rPhXqkpqQ3Z3C4TFF0jXZZc=\n" + - "-----END CERTIFICATE-----\n"; - public static final X509Certificate CA_CERT1 = loadCertificate(CA_CERT1_STRING); - - - private static X509Certificate loadCertificate(String blob) { - try { - final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); - InputStream stream = new ByteArrayInputStream(blob.getBytes(StandardCharsets.UTF_8)); - - return (X509Certificate) certFactory.generateCertificate(stream); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } -} diff --git a/tests/wifitests/src/android/net/wifi/WifiEnterpriseConfigTest.java b/tests/wifitests/src/android/net/wifi/WifiEnterpriseConfigTest.java deleted file mode 100644 index 0d964b7c9..000000000 --- a/tests/wifitests/src/android/net/wifi/WifiEnterpriseConfigTest.java +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package android.net.wifi; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertNull; - -import android.net.wifi.WifiEnterpriseConfig.Eap; -import android.net.wifi.WifiEnterpriseConfig.Phase2; -import android.os.Parcel; -import android.security.Credentials; -import android.test.suitebuilder.annotation.SmallTest; - -import org.junit.Before; -import org.junit.Test; - -import java.security.cert.X509Certificate; - - -/** - * Unit tests for {@link android.net.wifi.WifiEnterpriseConfig}. - */ -@SmallTest -public class WifiEnterpriseConfigTest { - // Maintain a ground truth of the keystore uri prefix which is expected by wpa_supplicant. - public static final String KEYSTORE_URI = "keystore://"; - public static final String CA_CERT_PREFIX = KEYSTORE_URI + Credentials.CA_CERTIFICATE; - public static final String KEYSTORES_URI = "keystores://"; - - private WifiEnterpriseConfig mEnterpriseConfig; - - @Before - public void setUp() throws Exception { - mEnterpriseConfig = new WifiEnterpriseConfig(); - } - - @Test - public void testGetEmptyCaCertificate() { - // A newly-constructed WifiEnterpriseConfig object should have no CA certificate. - assertNull(mEnterpriseConfig.getCaCertificate()); - assertNull(mEnterpriseConfig.getCaCertificates()); - // Setting CA certificate to null explicitly. - mEnterpriseConfig.setCaCertificate(null); - assertNull(mEnterpriseConfig.getCaCertificate()); - // Setting CA certificate to null using setCaCertificates(). - mEnterpriseConfig.setCaCertificates(null); - assertNull(mEnterpriseConfig.getCaCertificates()); - // Setting CA certificate to zero-length array. - mEnterpriseConfig.setCaCertificates(new X509Certificate[0]); - assertNull(mEnterpriseConfig.getCaCertificates()); - } - - @Test - public void testSetGetSingleCaCertificate() { - X509Certificate cert0 = FakeKeys.CA_CERT0; - mEnterpriseConfig.setCaCertificate(cert0); - assertEquals(mEnterpriseConfig.getCaCertificate(), cert0); - } - - @Test - public void testSetGetMultipleCaCertificates() { - X509Certificate cert0 = FakeKeys.CA_CERT0; - X509Certificate cert1 = FakeKeys.CA_CERT1; - mEnterpriseConfig.setCaCertificates(new X509Certificate[] {cert0, cert1}); - X509Certificate[] result = mEnterpriseConfig.getCaCertificates(); - assertEquals(result.length, 2); - assertTrue(result[0] == cert0 && result[1] == cert1); - } - - @Test - public void testSaveSingleCaCertificateAlias() { - final String alias = "single_alias 0"; - mEnterpriseConfig.setCaCertificateAliases(new String[] {alias}); - assertEquals(getCaCertField(), CA_CERT_PREFIX + alias); - } - - @Test - public void testLoadSingleCaCertificateAlias() { - final String alias = "single_alias 1"; - setCaCertField(CA_CERT_PREFIX + alias); - String[] aliases = mEnterpriseConfig.getCaCertificateAliases(); - assertEquals(aliases.length, 1); - assertEquals(aliases[0], alias); - } - - @Test - public void testSaveMultipleCaCertificates() { - final String alias0 = "single_alias 0"; - final String alias1 = "single_alias 1"; - mEnterpriseConfig.setCaCertificateAliases(new String[] {alias0, alias1}); - assertEquals(getCaCertField(), String.format("%s%s %s", - KEYSTORES_URI, - WifiEnterpriseConfig.encodeCaCertificateAlias(Credentials.CA_CERTIFICATE + alias0), - WifiEnterpriseConfig.encodeCaCertificateAlias(Credentials.CA_CERTIFICATE + alias1))); - } - - @Test - public void testLoadMultipleCaCertificates() { - final String alias0 = "single_alias 0"; - final String alias1 = "single_alias 1"; - setCaCertField(String.format("%s%s %s", - KEYSTORES_URI, - WifiEnterpriseConfig.encodeCaCertificateAlias(Credentials.CA_CERTIFICATE + alias0), - WifiEnterpriseConfig.encodeCaCertificateAlias(Credentials.CA_CERTIFICATE + alias1))); - String[] aliases = mEnterpriseConfig.getCaCertificateAliases(); - assertEquals(aliases.length, 2); - assertEquals(aliases[0], alias0); - assertEquals(aliases[1], alias1); - } - - private String getCaCertField() { - return mEnterpriseConfig.getFieldValue(WifiEnterpriseConfig.CA_CERT_KEY); - } - - private void setCaCertField(String value) { - mEnterpriseConfig.setFieldValue(WifiEnterpriseConfig.CA_CERT_KEY, value); - } - - // Retrieves the value for a specific key supplied to wpa_supplicant. - private class SupplicantConfigExtractor implements WifiEnterpriseConfig.SupplicantSaver { - private String mValue = null; - private String mKey; - - SupplicantConfigExtractor(String key) { - mKey = key; - } - - @Override - public boolean saveValue(String key, String value) { - if (key.equals(mKey)) { - mValue = value; - } - return true; - } - - public String getValue() { - return mValue; - } - } - - private String getSupplicantEapMethod() { - SupplicantConfigExtractor entryExtractor = new SupplicantConfigExtractor( - WifiEnterpriseConfig.EAP_KEY); - mEnterpriseConfig.saveToSupplicant(entryExtractor); - return entryExtractor.getValue(); - } - - private String getSupplicantPhase2Method() { - SupplicantConfigExtractor entryExtractor = new SupplicantConfigExtractor( - WifiEnterpriseConfig.PHASE2_KEY); - mEnterpriseConfig.saveToSupplicant(entryExtractor); - return entryExtractor.getValue(); - } - - /** Verifies the default value for EAP outer and inner methods */ - @Test - public void eapInnerDefault() { - assertEquals(null, getSupplicantEapMethod()); - assertEquals(null, getSupplicantPhase2Method()); - } - - /** Verifies that the EAP inner method is reset when we switch to TLS */ - @Test - public void eapPhase2MethodForTls() { - // Initially select an EAP method that supports an phase2. - mEnterpriseConfig.setEapMethod(Eap.PEAP); - mEnterpriseConfig.setPhase2Method(Phase2.MSCHAPV2); - assertEquals("PEAP", getSupplicantEapMethod()); - assertEquals("\"auth=MSCHAPV2\"", getSupplicantPhase2Method()); - - // Change the EAP method to another type which supports a phase2. - mEnterpriseConfig.setEapMethod(Eap.TTLS); - assertEquals("TTLS", getSupplicantEapMethod()); - assertEquals("\"auth=MSCHAPV2\"", getSupplicantPhase2Method()); - - // Change the EAP method to TLS which does not support a phase2. - mEnterpriseConfig.setEapMethod(Eap.TLS); - assertEquals(null, getSupplicantPhase2Method()); - } - - /** Verfies that the EAP inner method is reset when we switch phase2 to NONE */ - @Test - public void eapPhase2None() { - // Initially select an EAP method that supports an phase2. - mEnterpriseConfig.setEapMethod(Eap.PEAP); - mEnterpriseConfig.setPhase2Method(Phase2.MSCHAPV2); - assertEquals("PEAP", getSupplicantEapMethod()); - assertEquals("\"auth=MSCHAPV2\"", getSupplicantPhase2Method()); - - // Change the phase2 method to NONE and ensure the value is cleared. - mEnterpriseConfig.setPhase2Method(Phase2.NONE); - assertEquals(null, getSupplicantPhase2Method()); - } - - /** Verfies that the correct "autheap" parameter is supplied for TTLS/GTC. */ - @Test - public void peapGtcToTtls() { - mEnterpriseConfig.setEapMethod(Eap.PEAP); - mEnterpriseConfig.setPhase2Method(Phase2.GTC); - assertEquals("PEAP", getSupplicantEapMethod()); - assertEquals("\"auth=GTC\"", getSupplicantPhase2Method()); - - mEnterpriseConfig.setEapMethod(Eap.TTLS); - assertEquals("TTLS", getSupplicantEapMethod()); - assertEquals("\"autheap=GTC\"", getSupplicantPhase2Method()); - } - - /** Verfies that the correct "auth" parameter is supplied for PEAP/GTC. */ - @Test - public void ttlsGtcToPeap() { - mEnterpriseConfig.setEapMethod(Eap.TTLS); - mEnterpriseConfig.setPhase2Method(Phase2.GTC); - assertEquals("TTLS", getSupplicantEapMethod()); - assertEquals("\"autheap=GTC\"", getSupplicantPhase2Method()); - - mEnterpriseConfig.setEapMethod(Eap.PEAP); - assertEquals("PEAP", getSupplicantEapMethod()); - assertEquals("\"auth=GTC\"", getSupplicantPhase2Method()); - } - - /** Verfies that the copy constructor preseves the inner method information. */ - @Test - public void copyConstructor() { - WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig(); - enterpriseConfig.setEapMethod(Eap.TTLS); - enterpriseConfig.setPhase2Method(Phase2.GTC); - mEnterpriseConfig = new WifiEnterpriseConfig(enterpriseConfig); - assertEquals("TTLS", getSupplicantEapMethod()); - assertEquals("\"autheap=GTC\"", getSupplicantPhase2Method()); - } - - /** Verfies that parceling a WifiEnterpriseConfig preseves method information. */ - @Test - public void parcelConstructor() { - WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig(); - enterpriseConfig.setEapMethod(Eap.TTLS); - enterpriseConfig.setPhase2Method(Phase2.GTC); - Parcel parcel = Parcel.obtain(); - enterpriseConfig.writeToParcel(parcel, 0); - parcel.setDataPosition(0); // Allow parcel to be read from the beginning. - mEnterpriseConfig = WifiEnterpriseConfig.CREATOR.createFromParcel(parcel); - assertEquals("TTLS", getSupplicantEapMethod()); - assertEquals("\"autheap=GTC\"", getSupplicantPhase2Method()); - } - - /** Verifies proper operation of the getKeyId() method. */ - @Test - public void getKeyId() { - assertEquals("NULL", mEnterpriseConfig.getKeyId(null)); - WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig(); - enterpriseConfig.setEapMethod(Eap.TTLS); - enterpriseConfig.setPhase2Method(Phase2.GTC); - assertEquals("TTLS_GTC", mEnterpriseConfig.getKeyId(enterpriseConfig)); - mEnterpriseConfig.setEapMethod(Eap.PEAP); - mEnterpriseConfig.setPhase2Method(Phase2.MSCHAPV2); - assertEquals("PEAP_MSCHAPV2", mEnterpriseConfig.getKeyId(enterpriseConfig)); - } - - /** Verifies that passwords are not displayed in toString. */ - @Test - public void passwordNotInToString() { - String password = "supersecret"; - mEnterpriseConfig.setPassword(password); - assertFalse(mEnterpriseConfig.toString().contains(password)); - } -} diff --git a/tests/wifitests/src/android/net/wifi/WifiScannerTest.java b/tests/wifitests/src/android/net/wifi/WifiScannerTest.java deleted file mode 100644 index a829eb933..000000000 --- a/tests/wifitests/src/android/net/wifi/WifiScannerTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.net.wifi; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.validateMockitoUsage; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import android.content.Context; -import android.net.wifi.WifiScanner.BssidInfo; -import android.net.wifi.WifiScanner.BssidListener; -import android.os.Handler; -import android.os.Message; -import android.os.test.TestLooper; -import android.test.suitebuilder.annotation.SmallTest; - -import com.android.internal.util.test.BidirectionalAsyncChannelServer; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -/** - * Unit tests for {@link android.net.wifi.WifiScanner}. - */ -@SmallTest -public class WifiScannerTest { - @Mock - private Context mContext; - @Mock - private IWifiScanner mService; - @Mock - private BssidListener mBssidListener; - - private WifiScanner mWifiScanner; - private TestLooper mLooper; - private Handler mHandler; - - /** - * Setup before tests. - */ - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - mLooper = new TestLooper(); - mHandler = mock(Handler.class); - BidirectionalAsyncChannelServer server = new BidirectionalAsyncChannelServer( - mContext, mLooper.getLooper(), mHandler); - when(mService.getMessenger()).thenReturn(server.getMessenger()); - mWifiScanner = new WifiScanner(mContext, mService, mLooper.getLooper()); - mLooper.dispatchAll(); - } - - /** - * Clean up after tests. - */ - @After - public void cleanup() { - validateMockitoUsage(); - } - - private void verifySetHotlistMessage(Handler handler) { - ArgumentCaptor messageCaptor = ArgumentCaptor.forClass(Message.class); - verify(handler, atLeastOnce()).handleMessage(messageCaptor.capture()); - assertEquals("message.what is not CMD_SET_HOTLIST", - WifiScanner.CMD_SET_HOTLIST, - messageCaptor.getValue().what); - } - - /** - * Test duplicate listeners for bssid tracking. - */ - @Test - public void testStartTrackingBssidsDuplicateListeners() throws Exception { - BssidInfo[] bssids = new BssidInfo[] { - new BssidInfo() - }; - - // First start tracking succeeds. - mWifiScanner.startTrackingBssids(bssids, -100, mBssidListener); - mLooper.dispatchAll(); - verifySetHotlistMessage(mHandler); - - // Second start tracking should fail. - mWifiScanner.startTrackingBssids(bssids, -100, mBssidListener); - mLooper.dispatchAll(); - verify(mBssidListener).onFailure(eq(WifiScanner.REASON_DUPLICATE_REQEUST), anyString()); - } -} diff --git a/tests/wifitests/src/com/android/server/wifi/FakeKeys.java b/tests/wifitests/src/com/android/server/wifi/FakeKeys.java new file mode 100644 index 000000000..e8694b4bd --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/FakeKeys.java @@ -0,0 +1,67 @@ +package com.android.server.wifi; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; + +/** + * A class containing test certificates. + */ +public class FakeKeys { + private static final String CA_CERT0_STRING = "-----BEGIN CERTIFICATE-----\n" + + "MIIDKDCCAhCgAwIBAgIJAILlFdwzLVurMA0GCSqGSIb3DQEBCwUAMBIxEDAOBgNV\n" + + "BAMTB0VBUCBDQTEwHhcNMTYwMTEyMTE1MDE1WhcNMjYwMTA5MTE1MDE1WjASMRAw\n" + + "DgYDVQQDEwdFQVAgQ0ExMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA\n" + + "znAPUz26Msae4ws43czR41/J2QtrSIZUKmVUsVumDbYHrPNvTXKSMXAcewORDQYX\n" + + "RqvHvpn8CscB1+oGXZvHwxj4zV0WKoK2zeXkau3vcyl3HIKupJfq2TEACefVjj0t\n" + + "JW+X35PGWp9/H5zIUNVNVjS7Ums84IvKhRB8512PB9UyHagXYVX5GWpAcVpyfrlR\n" + + "FI9Qdhh+Pbk0uyktdbf/CdfgHOoebrTtwRljM0oDtX+2Cv6j0wBK7hD8pPvf1+uy\n" + + "GzczigAU/4Kw7eZqydf9B+5RupR+IZipX41xEiIrKRwqi517WWzXcjaG2cNbf451\n" + + "xpH5PnV3i1tq04jMGQUzFwIDAQABo4GAMH4wHQYDVR0OBBYEFIwX4vs8BiBcScod\n" + + "5noZHRM8E4+iMEIGA1UdIwQ7MDmAFIwX4vs8BiBcScod5noZHRM8E4+ioRakFDAS\n" + + "MRAwDgYDVQQDEwdFQVAgQ0ExggkAguUV3DMtW6swDAYDVR0TBAUwAwEB/zALBgNV\n" + + "HQ8EBAMCAQYwDQYJKoZIhvcNAQELBQADggEBAFfQqOTA7Rv7K+luQ7pnas4BYwHE\n" + + "9GEP/uohv6KOy0TGQFbrRTjFoLVNB9BZ1ymMDZ0/TIwIUc7wi7a8t5mEqYH153wW\n" + + "aWooiSjyLLhuI4sNrNCOtisdBq2r2MFXt6h0mAQYOPv8R8K7/fgSxGFqzhyNmmVL\n" + + "1qBJldx34SpwsTALQVPb4hGwJzZfr1PcpEQx6xMnTl8xEWZE3Ms99uaUxbQqIwRu\n" + + "LgAOkNCmY2m89VhzaHJ1uV85AdM/tD+Ysmlnnjt9LRCejbBipjIGjOXrg1JP+lxV\n" + + "muM4vH+P/mlmxsPPz0d65b+EGmJZpoLkO/tdNNvCYzjJpTEWpEsO6NMhKYo=\n" + + "-----END CERTIFICATE-----\n"; + public static final X509Certificate CA_CERT0 = loadCertificate(CA_CERT0_STRING); + + private static final String CA_CERT1_STRING = "-----BEGIN CERTIFICATE-----\n" + + "MIIDKDCCAhCgAwIBAgIJAOM5SzKO2pzCMA0GCSqGSIb3DQEBCwUAMBIxEDAOBgNV\n" + + "BAMTB0VBUCBDQTAwHhcNMTYwMTEyMDAxMDQ3WhcNMjYwMTA5MDAxMDQ3WjASMRAw\n" + + "DgYDVQQDEwdFQVAgQ0EwMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA\n" + + "89ug+IEKVQXnJGKg5g4uVHg6J/8iRUxR5k2eH5o03hrJNMfN2D+cBe/wCiZcnWbI\n" + + "GbGZACWm2nQth2wy9Zgm2LOd3b4ocrHYls3XLq6Qb5Dd7a0JKU7pdGufiNVEkrmF\n" + + "EB+N64wgwH4COTvCiN4erp5kyJwkfqAl2xLkZo0C464c9XoyQOXbmYD9A8v10wZu\n" + + "jyNsEo7Nr2USyw+qhjWSbFbEirP77Tvx+7pJQJwdtk1V9Tn73T2dGF2WHYejei9S\n" + + "mcWpdIUqsu9etYH+zDmtu7I1xlkwiaVsNr2+D+qaCJyOYqrDTKVNK5nmbBPXDWZc\n" + + "NoDbTOoqquX7xONpq9M6jQIDAQABo4GAMH4wHQYDVR0OBBYEFAZ3A2S4qJZZwuNY\n" + + "wkJ6mAdc0gVdMEIGA1UdIwQ7MDmAFAZ3A2S4qJZZwuNYwkJ6mAdc0gVdoRakFDAS\n" + + "MRAwDgYDVQQDEwdFQVAgQ0EwggkA4zlLMo7anMIwDAYDVR0TBAUwAwEB/zALBgNV\n" + + "HQ8EBAMCAQYwDQYJKoZIhvcNAQELBQADggEBAHmdMwEhtys4d0E+t7owBmoVR+lU\n" + + "hMCcRtWs8YKX5WIM2kTweT0h/O1xwE1mWmRv/IbDAEb8od4BjAQLhIcolStr2JaO\n" + + "9ZzyxjOnNzqeErh/1DHDbb/moPpqfeJ8YiEz7nH/YU56Q8iCPO7TsgS0sNNE7PfN\n" + + "IUsBW0yHRgpQ4OxWmiZG2YZWiECRzAC0ecPzo59N5iH4vLQIMTMYquiDeMPQnn1e\n" + + "NDGxG8gCtDKIaS6tMg3a28MvWB094pr2ETou8O1C8Ji0Y4hE8QJmSdT7I4+GZjgW\n" + + "g94DZ5RiL7sdp3vC48CXOmeT61YBIvhGUsE1rPhXqkpqQ3Z3C4TFF0jXZZc=\n" + + "-----END CERTIFICATE-----\n"; + public static final X509Certificate CA_CERT1 = loadCertificate(CA_CERT1_STRING); + + + private static X509Certificate loadCertificate(String blob) { + try { + final CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); + InputStream stream = new ByteArrayInputStream(blob.getBytes(StandardCharsets.UTF_8)); + + return (X509Certificate) certFactory.generateCertificate(stream); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } +} diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java index 55ca4cea4..3f71b1f46 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java @@ -23,7 +23,6 @@ import android.net.LinkAddress; import android.net.NetworkUtils; import android.net.ProxyInfo; import android.net.StaticIpConfiguration; -import android.net.wifi.FakeKeys; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration.NetworkSelectionStatus; import android.net.wifi.WifiEnterpriseConfig; diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtilTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtilTest.java index af5ca8fe2..1b4a16d1c 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtilTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationUtilTest.java @@ -19,7 +19,6 @@ package com.android.server.wifi; import static org.junit.Assert.*; import android.content.pm.UserInfo; -import android.net.wifi.FakeKeys; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiEnterpriseConfig; import android.net.wifi.WifiScanner; -- cgit v1.2.3