Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.wifi.hotspot2; |
| 18 | |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 19 | import static org.junit.Assert.assertEquals; |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 20 | import static org.junit.Assert.assertFalse; |
Peter Qiu | b54f07e | 2017-03-07 14:56:15 -0800 | [diff] [blame] | 21 | import static org.junit.Assert.assertNull; |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 22 | import static org.junit.Assert.assertTrue; |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 23 | import static org.mockito.Mockito.any; |
Peter Qiu | 33c46cd | 2016-12-19 13:12:13 -0800 | [diff] [blame] | 24 | import static org.mockito.Mockito.anyBoolean; |
Sohani Rao | 0ddc2ba | 2017-10-09 14:36:48 -0700 | [diff] [blame] | 25 | import static org.mockito.Mockito.anyInt; |
Peter Qiu | d28cfdd | 2016-12-13 14:17:20 -0800 | [diff] [blame] | 26 | import static org.mockito.Mockito.anyLong; |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 27 | import static org.mockito.Mockito.anyMap; |
Peter Qiu | f331a6b | 2017-03-20 14:55:45 -0700 | [diff] [blame] | 28 | import static org.mockito.Mockito.doThrow; |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 29 | import static org.mockito.Mockito.eq; |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 30 | import static org.mockito.Mockito.mock; |
Peter Qiu | 33c46cd | 2016-12-19 13:12:13 -0800 | [diff] [blame] | 31 | import static org.mockito.Mockito.never; |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 32 | import static org.mockito.Mockito.reset; |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 33 | import static org.mockito.Mockito.verify; |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 34 | import static org.mockito.Mockito.when; |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 35 | import static org.mockito.MockitoAnnotations.initMocks; |
| 36 | |
| 37 | import android.content.Context; |
| 38 | import android.content.Intent; |
Peter Qiu | ac4ab1b | 2017-06-06 13:59:04 -0700 | [diff] [blame] | 39 | import android.net.Uri; |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 40 | import android.net.wifi.EAPConstants; |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 41 | import android.net.wifi.ScanResult; |
Peter Qiu | 5e4822d | 2017-02-23 11:32:33 -0800 | [diff] [blame] | 42 | import android.net.wifi.WifiConfiguration; |
| 43 | import android.net.wifi.WifiEnterpriseConfig; |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 44 | import android.net.wifi.WifiManager; |
Peter Qiu | ac4ab1b | 2017-06-06 13:59:04 -0700 | [diff] [blame] | 45 | import android.net.wifi.WifiSsid; |
Sohani Rao | 0ddc2ba | 2017-10-09 14:36:48 -0700 | [diff] [blame] | 46 | import android.net.wifi.hotspot2.IProvisioningCallback; |
Peter Qiu | ac4ab1b | 2017-06-06 13:59:04 -0700 | [diff] [blame] | 47 | import android.net.wifi.hotspot2.OsuProvider; |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 48 | import android.net.wifi.hotspot2.PasspointConfiguration; |
| 49 | import android.net.wifi.hotspot2.pps.Credential; |
Peter Qiu | 260f8f7 | 2017-02-02 10:56:48 -0800 | [diff] [blame] | 50 | import android.net.wifi.hotspot2.pps.HomeSp; |
Sohani Rao | 0ddc2ba | 2017-10-09 14:36:48 -0700 | [diff] [blame] | 51 | import android.os.Looper; |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 52 | import android.os.UserHandle; |
Sohani Rao | 0ddc2ba | 2017-10-09 14:36:48 -0700 | [diff] [blame] | 53 | import android.os.test.TestLooper; |
Etan Cohen | 7f2a1e3 | 2018-01-23 07:11:24 -0800 | [diff] [blame] | 54 | import android.support.test.filters.SmallTest; |
Peter Qiu | 5e4822d | 2017-02-23 11:32:33 -0800 | [diff] [blame] | 55 | import android.util.Base64; |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 56 | import android.util.Pair; |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 57 | |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 58 | import com.android.server.wifi.Clock; |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 59 | import com.android.server.wifi.FakeKeys; |
| 60 | import com.android.server.wifi.IMSIParameter; |
| 61 | import com.android.server.wifi.SIMAccessor; |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 62 | import com.android.server.wifi.WifiConfigManager; |
| 63 | import com.android.server.wifi.WifiConfigStore; |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 64 | import com.android.server.wifi.WifiKeyStore; |
Peter Qiu | 26b97ef | 2017-06-22 14:49:02 -0700 | [diff] [blame] | 65 | import com.android.server.wifi.WifiMetrics; |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 66 | import com.android.server.wifi.WifiNative; |
Peter Qiu | 33c46cd | 2016-12-19 13:12:13 -0800 | [diff] [blame] | 67 | import com.android.server.wifi.hotspot2.anqp.ANQPElement; |
| 68 | import com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType; |
| 69 | import com.android.server.wifi.hotspot2.anqp.DomainNameElement; |
Peter Qiu | ac4ab1b | 2017-06-06 13:59:04 -0700 | [diff] [blame] | 70 | import com.android.server.wifi.hotspot2.anqp.HSOsuProvidersElement; |
| 71 | import com.android.server.wifi.hotspot2.anqp.I18Name; |
| 72 | import com.android.server.wifi.hotspot2.anqp.OsuProviderInfo; |
Masashi Honma | 2e889dc | 2018-04-02 17:09:51 +0900 | [diff] [blame] | 73 | import com.android.server.wifi.util.InformationElementUtil.RoamingConsortium; |
Peter Qiu | 48c93da | 2017-03-09 13:28:47 -0800 | [diff] [blame] | 74 | import com.android.server.wifi.util.ScanResultUtil; |
Nate Jiang | 078fb3e | 2020-12-03 14:31:30 -0800 | [diff] [blame^] | 75 | import com.android.server.wifi.util.WifiPermissionsUtil; |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 76 | |
| 77 | import org.junit.Before; |
| 78 | import org.junit.Test; |
| 79 | import org.mockito.ArgumentCaptor; |
| 80 | import org.mockito.Mock; |
| 81 | |
Peter Qiu | 5e4822d | 2017-02-23 11:32:33 -0800 | [diff] [blame] | 82 | import java.nio.charset.StandardCharsets; |
Peter Qiu | f331a6b | 2017-03-20 14:55:45 -0700 | [diff] [blame] | 83 | import java.security.GeneralSecurityException; |
Sohani Rao | 10cae96 | 2017-11-29 15:46:00 -0800 | [diff] [blame] | 84 | import java.security.KeyStore; |
Peter Qiu | f331a6b | 2017-03-20 14:55:45 -0700 | [diff] [blame] | 85 | import java.security.cert.X509Certificate; |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 86 | import java.util.ArrayList; |
Peter Qiu | 33c46cd | 2016-12-19 13:12:13 -0800 | [diff] [blame] | 87 | import java.util.Arrays; |
| 88 | import java.util.HashMap; |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 89 | import java.util.List; |
Peter Qiu | ac4ab1b | 2017-06-06 13:59:04 -0700 | [diff] [blame] | 90 | import java.util.Locale; |
Peter Qiu | 33c46cd | 2016-12-19 13:12:13 -0800 | [diff] [blame] | 91 | import java.util.Map; |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 92 | |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 93 | /** |
| 94 | * Unit tests for {@link com.android.server.wifi.hotspot2.PasspointManager}. |
| 95 | */ |
| 96 | @SmallTest |
| 97 | public class PasspointManagerTest { |
| 98 | private static final long BSSID = 0x112233445566L; |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 99 | private static final String TEST_FQDN = "test1.test.com"; |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 100 | private static final String TEST_FRIENDLY_NAME = "friendly name"; |
| 101 | private static final String TEST_REALM = "realm.test.com"; |
| 102 | private static final String TEST_IMSI = "1234*"; |
Peter Qiu | 87c6f1b | 2016-12-15 15:22:31 -0800 | [diff] [blame] | 103 | private static final IMSIParameter TEST_IMSI_PARAM = IMSIParameter.build(TEST_IMSI); |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 104 | |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 105 | private static final String TEST_SSID = "TestSSID"; |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 106 | private static final long TEST_BSSID = 0x112233445566L; |
| 107 | private static final String TEST_BSSID_STRING = "11:22:33:44:55:66"; |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 108 | private static final long TEST_HESSID = 0x5678L; |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 109 | private static final int TEST_ANQP_DOMAIN_ID = 0; |
| 110 | private static final ANQPNetworkKey TEST_ANQP_KEY = ANQPNetworkKey.buildKey( |
| 111 | TEST_SSID, TEST_BSSID, TEST_HESSID, TEST_ANQP_DOMAIN_ID); |
Peter Qiu | 07816a4 | 2017-04-03 17:08:33 +0000 | [diff] [blame] | 112 | private static final int TEST_CREATOR_UID = 1234; |
Sohani Rao | 0ddc2ba | 2017-10-09 14:36:48 -0700 | [diff] [blame] | 113 | private static final int TEST_UID = 1500; |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 114 | |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 115 | @Mock Context mContext; |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 116 | @Mock WifiNative mWifiNative; |
| 117 | @Mock WifiKeyStore mWifiKeyStore; |
| 118 | @Mock Clock mClock; |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 119 | @Mock SIMAccessor mSimAccessor; |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 120 | @Mock PasspointObjectFactory mObjectFactory; |
| 121 | @Mock PasspointEventHandler.Callbacks mCallbacks; |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 122 | @Mock AnqpCache mAnqpCache; |
Peter Qiu | 33c46cd | 2016-12-19 13:12:13 -0800 | [diff] [blame] | 123 | @Mock ANQPRequestManager mAnqpRequestManager; |
Peter Qiu | f331a6b | 2017-03-20 14:55:45 -0700 | [diff] [blame] | 124 | @Mock CertificateVerifier mCertVerifier; |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 125 | @Mock WifiConfigManager mWifiConfigManager; |
| 126 | @Mock WifiConfigStore mWifiConfigStore; |
| 127 | @Mock PasspointConfigStoreData.DataSource mDataSource; |
Peter Qiu | 26b97ef | 2017-06-22 14:49:02 -0700 | [diff] [blame] | 128 | @Mock WifiMetrics mWifiMetrics; |
Sohani Rao | 0ddc2ba | 2017-10-09 14:36:48 -0700 | [diff] [blame] | 129 | @Mock OsuNetworkConnection mOsuNetworkConnection; |
Sohani Rao | 7df7bb8 | 2017-11-15 17:07:24 -0800 | [diff] [blame] | 130 | @Mock OsuServerConnection mOsuServerConnection; |
Sohani Rao | b36b985 | 2017-10-09 14:36:48 -0700 | [diff] [blame] | 131 | @Mock PasspointProvisioner mPasspointProvisioner; |
Sohani Rao | 0ddc2ba | 2017-10-09 14:36:48 -0700 | [diff] [blame] | 132 | @Mock IProvisioningCallback mCallback; |
Sohani Rao | 10cae96 | 2017-11-29 15:46:00 -0800 | [diff] [blame] | 133 | @Mock WfaKeyStore mWfaKeyStore; |
| 134 | @Mock KeyStore mKeyStore; |
Nate Jiang | 078fb3e | 2020-12-03 14:31:30 -0800 | [diff] [blame^] | 135 | @Mock WifiPermissionsUtil mWifiPermissionsUtil; |
Sohani Rao | 0ddc2ba | 2017-10-09 14:36:48 -0700 | [diff] [blame] | 136 | TestLooper mLooper; |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 137 | PasspointManager mManager; |
| 138 | |
| 139 | /** Sets up test. */ |
| 140 | @Before |
| 141 | public void setUp() throws Exception { |
| 142 | initMocks(this); |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 143 | when(mObjectFactory.makeAnqpCache(mClock)).thenReturn(mAnqpCache); |
Peter Qiu | 99b966a | 2017-03-23 10:04:55 -0700 | [diff] [blame] | 144 | when(mObjectFactory.makeANQPRequestManager(any(), eq(mClock))) |
Peter Qiu | 33c46cd | 2016-12-19 13:12:13 -0800 | [diff] [blame] | 145 | .thenReturn(mAnqpRequestManager); |
Peter Qiu | f331a6b | 2017-03-20 14:55:45 -0700 | [diff] [blame] | 146 | when(mObjectFactory.makeCertificateVerifier()).thenReturn(mCertVerifier); |
Sohani Rao | 0ddc2ba | 2017-10-09 14:36:48 -0700 | [diff] [blame] | 147 | when(mObjectFactory.makeOsuNetworkConnection(any(Context.class))) |
| 148 | .thenReturn(mOsuNetworkConnection); |
Sohani Rao | 7df7bb8 | 2017-11-15 17:07:24 -0800 | [diff] [blame] | 149 | when(mObjectFactory.makeOsuServerConnection()) |
| 150 | .thenReturn(mOsuServerConnection); |
Sohani Rao | 10cae96 | 2017-11-29 15:46:00 -0800 | [diff] [blame] | 151 | when(mObjectFactory.makeWfaKeyStore()).thenReturn(mWfaKeyStore); |
| 152 | when(mWfaKeyStore.get()).thenReturn(mKeyStore); |
| 153 | when(mObjectFactory.makePasspointProvisioner(any(Context.class))) |
Sohani Rao | 7df7bb8 | 2017-11-15 17:07:24 -0800 | [diff] [blame] | 154 | .thenReturn(mPasspointProvisioner); |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 155 | mManager = new PasspointManager(mContext, mWifiNative, mWifiKeyStore, mClock, |
Nate Jiang | 078fb3e | 2020-12-03 14:31:30 -0800 | [diff] [blame^] | 156 | mSimAccessor, mObjectFactory, mWifiConfigManager, mWifiConfigStore, mWifiMetrics, |
| 157 | mWifiPermissionsUtil); |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 158 | ArgumentCaptor<PasspointEventHandler.Callbacks> callbacks = |
| 159 | ArgumentCaptor.forClass(PasspointEventHandler.Callbacks.class); |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 160 | verify(mObjectFactory).makePasspointEventHandler(any(WifiNative.class), |
| 161 | callbacks.capture()); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 162 | ArgumentCaptor<PasspointConfigStoreData.DataSource> dataSource = |
| 163 | ArgumentCaptor.forClass(PasspointConfigStoreData.DataSource.class); |
| 164 | verify(mObjectFactory).makePasspointConfigStoreData( |
| 165 | any(WifiKeyStore.class), any(SIMAccessor.class), dataSource.capture()); |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 166 | mCallbacks = callbacks.getValue(); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 167 | mDataSource = dataSource.getValue(); |
Sohani Rao | 0ddc2ba | 2017-10-09 14:36:48 -0700 | [diff] [blame] | 168 | mLooper = new TestLooper(); |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /** |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 172 | * Verify that the given Passpoint configuration matches the one that's added to |
| 173 | * the PasspointManager. |
| 174 | * |
| 175 | * @param expectedConfig The expected installed Passpoint configuration |
| 176 | */ |
| 177 | private void verifyInstalledConfig(PasspointConfiguration expectedConfig) { |
| 178 | List<PasspointConfiguration> installedConfigs = mManager.getProviderConfigs(); |
| 179 | assertEquals(1, installedConfigs.size()); |
| 180 | assertEquals(expectedConfig, installedConfigs.get(0)); |
| 181 | } |
| 182 | |
| 183 | /** |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 184 | * Create a mock PasspointProvider with default expectations. |
| 185 | * |
| 186 | * @param config The configuration associated with the provider |
| 187 | * @return {@link com.android.server.wifi.hotspot2.PasspointProvider} |
| 188 | */ |
| 189 | private PasspointProvider createMockProvider(PasspointConfiguration config) { |
| 190 | PasspointProvider provider = mock(PasspointProvider.class); |
| 191 | when(provider.installCertsAndKeys()).thenReturn(true); |
| 192 | when(provider.getConfig()).thenReturn(config); |
| 193 | return provider; |
| 194 | } |
| 195 | |
| 196 | /** |
Peter Qiu | 4f4d745 | 2017-01-24 15:51:38 -0800 | [diff] [blame] | 197 | * Helper function for creating a test configuration with user credential. |
| 198 | * |
| 199 | * @return {@link PasspointConfiguration} |
| 200 | */ |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 201 | private PasspointConfiguration createTestConfigWithUserCredential(String fqdn) { |
Peter Qiu | 4f4d745 | 2017-01-24 15:51:38 -0800 | [diff] [blame] | 202 | PasspointConfiguration config = new PasspointConfiguration(); |
Peter Qiu | 260f8f7 | 2017-02-02 10:56:48 -0800 | [diff] [blame] | 203 | HomeSp homeSp = new HomeSp(); |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 204 | homeSp.setFqdn(fqdn); |
Peter Qiu | 4f4d745 | 2017-01-24 15:51:38 -0800 | [diff] [blame] | 205 | homeSp.setFriendlyName(TEST_FRIENDLY_NAME); |
| 206 | config.setHomeSp(homeSp); |
| 207 | Credential credential = new Credential(); |
| 208 | credential.setRealm(TEST_REALM); |
| 209 | credential.setCaCertificate(FakeKeys.CA_CERT0); |
| 210 | Credential.UserCredential userCredential = new Credential.UserCredential(); |
| 211 | userCredential.setUsername("username"); |
| 212 | userCredential.setPassword("password"); |
| 213 | userCredential.setEapType(EAPConstants.EAP_TTLS); |
Peter Qiu | 5e4822d | 2017-02-23 11:32:33 -0800 | [diff] [blame] | 214 | userCredential.setNonEapInnerMethod(Credential.UserCredential.AUTH_METHOD_MSCHAP); |
Peter Qiu | 4f4d745 | 2017-01-24 15:51:38 -0800 | [diff] [blame] | 215 | credential.setUserCredential(userCredential); |
| 216 | config.setCredential(credential); |
| 217 | return config; |
| 218 | } |
| 219 | |
| 220 | /** |
| 221 | * Helper function for creating a test configuration with SIM credential. |
| 222 | * |
| 223 | * @return {@link PasspointConfiguration} |
| 224 | */ |
| 225 | private PasspointConfiguration createTestConfigWithSimCredential() { |
| 226 | PasspointConfiguration config = new PasspointConfiguration(); |
Peter Qiu | 260f8f7 | 2017-02-02 10:56:48 -0800 | [diff] [blame] | 227 | HomeSp homeSp = new HomeSp(); |
Peter Qiu | 4f4d745 | 2017-01-24 15:51:38 -0800 | [diff] [blame] | 228 | homeSp.setFqdn(TEST_FQDN); |
| 229 | homeSp.setFriendlyName(TEST_FRIENDLY_NAME); |
| 230 | config.setHomeSp(homeSp); |
| 231 | Credential credential = new Credential(); |
| 232 | credential.setRealm(TEST_REALM); |
| 233 | Credential.SimCredential simCredential = new Credential.SimCredential(); |
| 234 | simCredential.setImsi(TEST_IMSI); |
| 235 | simCredential.setEapType(EAPConstants.EAP_SIM); |
| 236 | credential.setSimCredential(simCredential); |
| 237 | config.setCredential(credential); |
| 238 | return config; |
| 239 | } |
| 240 | |
| 241 | /** |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 242 | * Helper function for adding a test provider to the manager. Return the mock |
| 243 | * provider that's added to the manager. |
| 244 | * |
| 245 | * @return {@link PasspointProvider} |
| 246 | */ |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 247 | private PasspointProvider addTestProvider(String fqdn) { |
| 248 | PasspointConfiguration config = createTestConfigWithUserCredential(fqdn); |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 249 | PasspointProvider provider = createMockProvider(config); |
Peter Qiu | 87c6f1b | 2016-12-15 15:22:31 -0800 | [diff] [blame] | 250 | when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), |
Peter Qiu | 07816a4 | 2017-04-03 17:08:33 +0000 | [diff] [blame] | 251 | eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(provider); |
| 252 | assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 253 | |
| 254 | return provider; |
| 255 | } |
| 256 | |
| 257 | /** |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 258 | * Helper function for creating a ScanResult for testing. |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 259 | * |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 260 | * @return {@link ScanResult} |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 261 | */ |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 262 | private ScanResult createTestScanResult() { |
| 263 | ScanResult scanResult = new ScanResult(); |
| 264 | scanResult.SSID = TEST_SSID; |
| 265 | scanResult.BSSID = TEST_BSSID_STRING; |
| 266 | scanResult.hessid = TEST_HESSID; |
Peter Qiu | 33c3ae8 | 2017-06-02 11:35:06 -0700 | [diff] [blame] | 267 | scanResult.flags = ScanResult.FLAG_PASSPOINT_NETWORK; |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 268 | return scanResult; |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /** |
Peter Qiu | 33c46cd | 2016-12-19 13:12:13 -0800 | [diff] [blame] | 272 | * Verify that the ANQP elements will be added to the ANQP cache on receiving a successful |
| 273 | * response. |
| 274 | * |
| 275 | * @throws Exception |
| 276 | */ |
| 277 | @Test |
| 278 | public void anqpResponseSuccess() throws Exception { |
| 279 | Map<ANQPElementType, ANQPElement> anqpElementMap = new HashMap<>(); |
| 280 | anqpElementMap.put(ANQPElementType.ANQPDomName, |
| 281 | new DomainNameElement(Arrays.asList(new String[] {"test.com"}))); |
| 282 | |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 283 | when(mAnqpRequestManager.onRequestCompleted(TEST_BSSID, true)).thenReturn(TEST_ANQP_KEY); |
Peter Qiu | 33c46cd | 2016-12-19 13:12:13 -0800 | [diff] [blame] | 284 | mCallbacks.onANQPResponse(TEST_BSSID, anqpElementMap); |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 285 | verify(mAnqpCache).addEntry(TEST_ANQP_KEY, anqpElementMap); |
Peter Qiu | e8fd83b | 2017-03-20 13:55:52 -0700 | [diff] [blame] | 286 | verify(mContext, never()).sendBroadcastAsUser(any(Intent.class), any(UserHandle.class), |
| 287 | any(String.class)); |
| 288 | } |
| 289 | |
| 290 | /** |
Peter Qiu | 33c46cd | 2016-12-19 13:12:13 -0800 | [diff] [blame] | 291 | * Verify that no ANQP elements will be added to the ANQP cache on receiving a successful |
| 292 | * response for a request that's not sent by us. |
| 293 | * |
| 294 | * @throws Exception |
| 295 | */ |
| 296 | @Test |
| 297 | public void anqpResponseSuccessWithUnknownRequest() throws Exception { |
| 298 | Map<ANQPElementType, ANQPElement> anqpElementMap = new HashMap<>(); |
| 299 | anqpElementMap.put(ANQPElementType.ANQPDomName, |
| 300 | new DomainNameElement(Arrays.asList(new String[] {"test.com"}))); |
| 301 | |
| 302 | when(mAnqpRequestManager.onRequestCompleted(TEST_BSSID, true)).thenReturn(null); |
| 303 | mCallbacks.onANQPResponse(TEST_BSSID, anqpElementMap); |
| 304 | verify(mAnqpCache, never()).addEntry(any(ANQPNetworkKey.class), anyMap()); |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Verify that no ANQP elements will be added to the ANQP cache on receiving a failure response. |
| 309 | * |
| 310 | * @throws Exception |
| 311 | */ |
| 312 | @Test |
| 313 | public void anqpResponseFailure() throws Exception { |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 314 | when(mAnqpRequestManager.onRequestCompleted(TEST_BSSID, false)).thenReturn(TEST_ANQP_KEY); |
Peter Qiu | 33c46cd | 2016-12-19 13:12:13 -0800 | [diff] [blame] | 315 | mCallbacks.onANQPResponse(TEST_BSSID, null); |
| 316 | verify(mAnqpCache, never()).addEntry(any(ANQPNetworkKey.class), anyMap()); |
| 317 | |
| 318 | } |
| 319 | |
| 320 | /** |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 321 | * Verify that adding a provider with a null configuration will fail. |
| 322 | * |
| 323 | * @throws Exception |
| 324 | */ |
| 325 | @Test |
| 326 | public void addProviderWithNullConfig() throws Exception { |
Peter Qiu | 07816a4 | 2017-04-03 17:08:33 +0000 | [diff] [blame] | 327 | assertFalse(mManager.addOrUpdateProvider(null, TEST_CREATOR_UID)); |
Peter Qiu | 26b97ef | 2017-06-22 14:49:02 -0700 | [diff] [blame] | 328 | verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); |
| 329 | verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Verify that adding a provider with a empty configuration will fail. |
| 334 | * |
| 335 | * @throws Exception |
| 336 | */ |
| 337 | @Test |
| 338 | public void addProviderWithEmptyConfig() throws Exception { |
Peter Qiu | 07816a4 | 2017-04-03 17:08:33 +0000 | [diff] [blame] | 339 | assertFalse(mManager.addOrUpdateProvider(new PasspointConfiguration(), TEST_CREATOR_UID)); |
Peter Qiu | 26b97ef | 2017-06-22 14:49:02 -0700 | [diff] [blame] | 340 | verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); |
| 341 | verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Verify taht adding a provider with an invalid credential will fail (using EAP-TLS |
| 346 | * for user credential). |
| 347 | * |
| 348 | * @throws Exception |
| 349 | */ |
| 350 | @Test |
| 351 | public void addProviderWithInvalidCredential() throws Exception { |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 352 | PasspointConfiguration config = createTestConfigWithUserCredential(TEST_FQDN); |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 353 | // EAP-TLS not allowed for user credential. |
Peter Qiu | 4f4d745 | 2017-01-24 15:51:38 -0800 | [diff] [blame] | 354 | config.getCredential().getUserCredential().setEapType(EAPConstants.EAP_TLS); |
Peter Qiu | 07816a4 | 2017-04-03 17:08:33 +0000 | [diff] [blame] | 355 | assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); |
Peter Qiu | 26b97ef | 2017-06-22 14:49:02 -0700 | [diff] [blame] | 356 | verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); |
| 357 | verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Verify that adding a provider with a valid configuration and user credential will succeed. |
| 362 | * |
| 363 | * @throws Exception |
| 364 | */ |
| 365 | @Test |
| 366 | public void addRemoveProviderWithValidUserCredential() throws Exception { |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 367 | PasspointConfiguration config = createTestConfigWithUserCredential(TEST_FQDN); |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 368 | PasspointProvider provider = createMockProvider(config); |
Peter Qiu | 87c6f1b | 2016-12-15 15:22:31 -0800 | [diff] [blame] | 369 | when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), |
Peter Qiu | 07816a4 | 2017-04-03 17:08:33 +0000 | [diff] [blame] | 370 | eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(provider); |
| 371 | assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 372 | verifyInstalledConfig(config); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 373 | verify(mWifiConfigManager).saveToStore(true); |
Peter Qiu | 26b97ef | 2017-06-22 14:49:02 -0700 | [diff] [blame] | 374 | verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); |
| 375 | verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); |
| 376 | reset(mWifiMetrics); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 377 | reset(mWifiConfigManager); |
| 378 | |
| 379 | // Verify content in the data source. |
| 380 | List<PasspointProvider> providers = mDataSource.getProviders(); |
| 381 | assertEquals(1, providers.size()); |
| 382 | assertEquals(config, providers.get(0).getConfig()); |
| 383 | // Provider index start with 0, should be 1 after adding a provider. |
| 384 | assertEquals(1, mDataSource.getProviderIndex()); |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 385 | |
| 386 | // Remove the provider. |
Nate Jiang | 078fb3e | 2020-12-03 14:31:30 -0800 | [diff] [blame^] | 387 | assertTrue(mManager.removeProvider(TEST_CREATOR_UID, TEST_FQDN)); |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 388 | verify(provider).uninstallCertsAndKeys(); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 389 | verify(mWifiConfigManager).saveToStore(true); |
Peter Qiu | 26b97ef | 2017-06-22 14:49:02 -0700 | [diff] [blame] | 390 | verify(mWifiMetrics).incrementNumPasspointProviderUninstallation(); |
| 391 | verify(mWifiMetrics).incrementNumPasspointProviderUninstallSuccess(); |
Peter Qiu | d28cfdd | 2016-12-13 14:17:20 -0800 | [diff] [blame] | 392 | assertTrue(mManager.getProviderConfigs().isEmpty()); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 393 | |
| 394 | // Verify content in the data source. |
| 395 | assertTrue(mDataSource.getProviders().isEmpty()); |
| 396 | // Removing a provider should not change the provider index. |
| 397 | assertEquals(1, mDataSource.getProviderIndex()); |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | /** |
| 401 | * Verify that adding a provider with a valid configuration and SIM credential will succeed. |
| 402 | * |
| 403 | * @throws Exception |
| 404 | */ |
| 405 | @Test |
| 406 | public void addRemoveProviderWithValidSimCredential() throws Exception { |
Peter Qiu | 4f4d745 | 2017-01-24 15:51:38 -0800 | [diff] [blame] | 407 | PasspointConfiguration config = createTestConfigWithSimCredential(); |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 408 | PasspointProvider provider = createMockProvider(config); |
Peter Qiu | 87c6f1b | 2016-12-15 15:22:31 -0800 | [diff] [blame] | 409 | when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), |
Peter Qiu | 07816a4 | 2017-04-03 17:08:33 +0000 | [diff] [blame] | 410 | eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(provider); |
| 411 | assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 412 | verifyInstalledConfig(config); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 413 | verify(mWifiConfigManager).saveToStore(true); |
Peter Qiu | 26b97ef | 2017-06-22 14:49:02 -0700 | [diff] [blame] | 414 | verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); |
| 415 | verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); |
| 416 | reset(mWifiMetrics); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 417 | reset(mWifiConfigManager); |
| 418 | |
| 419 | // Verify content in the data source. |
| 420 | List<PasspointProvider> providers = mDataSource.getProviders(); |
| 421 | assertEquals(1, providers.size()); |
| 422 | assertEquals(config, providers.get(0).getConfig()); |
| 423 | // Provider index start with 0, should be 1 after adding a provider. |
| 424 | assertEquals(1, mDataSource.getProviderIndex()); |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 425 | |
| 426 | // Remove the provider. |
Nate Jiang | 078fb3e | 2020-12-03 14:31:30 -0800 | [diff] [blame^] | 427 | assertTrue(mManager.removeProvider(TEST_CREATOR_UID, TEST_FQDN)); |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 428 | verify(provider).uninstallCertsAndKeys(); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 429 | verify(mWifiConfigManager).saveToStore(true); |
Peter Qiu | 26b97ef | 2017-06-22 14:49:02 -0700 | [diff] [blame] | 430 | verify(mWifiMetrics).incrementNumPasspointProviderUninstallation(); |
| 431 | verify(mWifiMetrics).incrementNumPasspointProviderUninstallSuccess(); |
Peter Qiu | d28cfdd | 2016-12-13 14:17:20 -0800 | [diff] [blame] | 432 | assertTrue(mManager.getProviderConfigs().isEmpty()); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 433 | |
| 434 | // Verify content in the data source. |
| 435 | assertTrue(mDataSource.getProviders().isEmpty()); |
| 436 | // Removing a provider should not change the provider index. |
| 437 | assertEquals(1, mDataSource.getProviderIndex()); |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /** |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 441 | * Verify that adding a provider with the same base domain as the existing provider will |
| 442 | * succeed, and verify that the existing provider is replaced by the new provider with |
| 443 | * the new configuration. |
| 444 | * |
| 445 | * @throws Exception |
| 446 | */ |
| 447 | @Test |
| 448 | public void addProviderWithExistingConfig() throws Exception { |
| 449 | // Add a provider with the original configuration. |
Peter Qiu | 4f4d745 | 2017-01-24 15:51:38 -0800 | [diff] [blame] | 450 | PasspointConfiguration origConfig = createTestConfigWithSimCredential(); |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 451 | PasspointProvider origProvider = createMockProvider(origConfig); |
Peter Qiu | 87c6f1b | 2016-12-15 15:22:31 -0800 | [diff] [blame] | 452 | when(mObjectFactory.makePasspointProvider(eq(origConfig), eq(mWifiKeyStore), |
Peter Qiu | 07816a4 | 2017-04-03 17:08:33 +0000 | [diff] [blame] | 453 | eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(origProvider); |
| 454 | assertTrue(mManager.addOrUpdateProvider(origConfig, TEST_CREATOR_UID)); |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 455 | verifyInstalledConfig(origConfig); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 456 | verify(mWifiConfigManager).saveToStore(true); |
Peter Qiu | 26b97ef | 2017-06-22 14:49:02 -0700 | [diff] [blame] | 457 | verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); |
| 458 | verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); |
| 459 | reset(mWifiMetrics); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 460 | reset(mWifiConfigManager); |
| 461 | |
| 462 | // Verify data source content. |
| 463 | List<PasspointProvider> origProviders = mDataSource.getProviders(); |
| 464 | assertEquals(1, origProviders.size()); |
| 465 | assertEquals(origConfig, origProviders.get(0).getConfig()); |
| 466 | assertEquals(1, mDataSource.getProviderIndex()); |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 467 | |
| 468 | // Add another provider with the same base domain as the existing provider. |
| 469 | // This should replace the existing provider with the new configuration. |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 470 | PasspointConfiguration newConfig = createTestConfigWithUserCredential(TEST_FQDN); |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 471 | PasspointProvider newProvider = createMockProvider(newConfig); |
Peter Qiu | 87c6f1b | 2016-12-15 15:22:31 -0800 | [diff] [blame] | 472 | when(mObjectFactory.makePasspointProvider(eq(newConfig), eq(mWifiKeyStore), |
Peter Qiu | 07816a4 | 2017-04-03 17:08:33 +0000 | [diff] [blame] | 473 | eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(newProvider); |
| 474 | assertTrue(mManager.addOrUpdateProvider(newConfig, TEST_CREATOR_UID)); |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 475 | verifyInstalledConfig(newConfig); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 476 | verify(mWifiConfigManager).saveToStore(true); |
Peter Qiu | 26b97ef | 2017-06-22 14:49:02 -0700 | [diff] [blame] | 477 | verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); |
| 478 | verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 479 | |
| 480 | // Verify data source content. |
| 481 | List<PasspointProvider> newProviders = mDataSource.getProviders(); |
| 482 | assertEquals(1, newProviders.size()); |
| 483 | assertEquals(newConfig, newProviders.get(0).getConfig()); |
| 484 | assertEquals(2, mDataSource.getProviderIndex()); |
Peter Qiu | c044796 | 2016-11-02 14:41:25 -0700 | [diff] [blame] | 485 | } |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 486 | |
| 487 | /** |
| 488 | * Verify that adding a provider will fail when failing to install certificates and |
| 489 | * key to the keystore. |
| 490 | * |
| 491 | * @throws Exception |
| 492 | */ |
| 493 | @Test |
| 494 | public void addProviderOnKeyInstallationFailiure() throws Exception { |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 495 | PasspointConfiguration config = createTestConfigWithUserCredential(TEST_FQDN); |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 496 | PasspointProvider provider = mock(PasspointProvider.class); |
| 497 | when(provider.installCertsAndKeys()).thenReturn(false); |
Peter Qiu | 87c6f1b | 2016-12-15 15:22:31 -0800 | [diff] [blame] | 498 | when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), |
Peter Qiu | 07816a4 | 2017-04-03 17:08:33 +0000 | [diff] [blame] | 499 | eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(provider); |
| 500 | assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); |
Peter Qiu | 26b97ef | 2017-06-22 14:49:02 -0700 | [diff] [blame] | 501 | verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); |
| 502 | verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /** |
Peter Qiu | f331a6b | 2017-03-20 14:55:45 -0700 | [diff] [blame] | 506 | * Verify that adding a provider with an invalid CA certificate will fail. |
| 507 | * |
| 508 | * @throws Exception |
| 509 | */ |
| 510 | @Test |
| 511 | public void addProviderWithInvalidCaCert() throws Exception { |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 512 | PasspointConfiguration config = createTestConfigWithUserCredential(TEST_FQDN); |
Peter Qiu | f331a6b | 2017-03-20 14:55:45 -0700 | [diff] [blame] | 513 | doThrow(new GeneralSecurityException()) |
| 514 | .when(mCertVerifier).verifyCaCert(any(X509Certificate.class)); |
Peter Qiu | 07816a4 | 2017-04-03 17:08:33 +0000 | [diff] [blame] | 515 | assertFalse(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); |
Peter Qiu | 26b97ef | 2017-06-22 14:49:02 -0700 | [diff] [blame] | 516 | verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); |
| 517 | verify(mWifiMetrics, never()).incrementNumPasspointProviderInstallSuccess(); |
Peter Qiu | f331a6b | 2017-03-20 14:55:45 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | /** |
| 521 | * Verify that adding a provider with R2 configuration will not perform CA certificate |
| 522 | * verification. |
| 523 | * |
| 524 | * @throws Exception |
| 525 | */ |
| 526 | @Test |
| 527 | public void addProviderWithR2Config() throws Exception { |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 528 | PasspointConfiguration config = createTestConfigWithUserCredential(TEST_FQDN); |
Peter Qiu | f331a6b | 2017-03-20 14:55:45 -0700 | [diff] [blame] | 529 | config.setUpdateIdentifier(1); |
| 530 | PasspointProvider provider = createMockProvider(config); |
| 531 | when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), |
Peter Qiu | 07816a4 | 2017-04-03 17:08:33 +0000 | [diff] [blame] | 532 | eq(mSimAccessor), anyLong(), eq(TEST_CREATOR_UID))).thenReturn(provider); |
| 533 | assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); |
Peter Qiu | f331a6b | 2017-03-20 14:55:45 -0700 | [diff] [blame] | 534 | verify(mCertVerifier, never()).verifyCaCert(any(X509Certificate.class)); |
| 535 | verifyInstalledConfig(config); |
Peter Qiu | 26b97ef | 2017-06-22 14:49:02 -0700 | [diff] [blame] | 536 | verify(mWifiMetrics).incrementNumPasspointProviderInstallation(); |
| 537 | verify(mWifiMetrics).incrementNumPasspointProviderInstallSuccess(); |
Peter Qiu | f331a6b | 2017-03-20 14:55:45 -0700 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | /** |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 541 | * Verify that removing a non-existing provider will fail. |
| 542 | * |
| 543 | * @throws Exception |
| 544 | */ |
| 545 | @Test |
| 546 | public void removeNonExistingProvider() throws Exception { |
Nate Jiang | 078fb3e | 2020-12-03 14:31:30 -0800 | [diff] [blame^] | 547 | assertFalse(mManager.removeProvider(TEST_CREATOR_UID, TEST_FQDN)); |
Peter Qiu | 26b97ef | 2017-06-22 14:49:02 -0700 | [diff] [blame] | 548 | verify(mWifiMetrics).incrementNumPasspointProviderUninstallation(); |
| 549 | verify(mWifiMetrics, never()).incrementNumPasspointProviderUninstallSuccess(); |
Peter Qiu | ae79127 | 2016-11-17 15:17:34 -0800 | [diff] [blame] | 550 | } |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 551 | |
| 552 | /** |
Peter Qiu | b54f07e | 2017-03-07 14:56:15 -0800 | [diff] [blame] | 553 | * Verify that a {code null} will be returned when no providers are installed. |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 554 | * |
| 555 | * @throws Exception |
| 556 | */ |
| 557 | @Test |
| 558 | public void matchProviderWithNoProvidersInstalled() throws Exception { |
Peter Qiu | b54f07e | 2017-03-07 14:56:15 -0800 | [diff] [blame] | 559 | assertNull(mManager.matchProvider(createTestScanResult())); |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | /** |
Peter Qiu | b54f07e | 2017-03-07 14:56:15 -0800 | [diff] [blame] | 563 | * Verify that a {code null} be returned when ANQP entry doesn't exist in the cache. |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 564 | * |
| 565 | * @throws Exception |
| 566 | */ |
| 567 | @Test |
| 568 | public void matchProviderWithAnqpCacheMissed() throws Exception { |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 569 | addTestProvider(TEST_FQDN); |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 570 | |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 571 | when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(null); |
Peter Qiu | b54f07e | 2017-03-07 14:56:15 -0800 | [diff] [blame] | 572 | assertNull(mManager.matchProvider(createTestScanResult())); |
Peter Qiu | 33c46cd | 2016-12-19 13:12:13 -0800 | [diff] [blame] | 573 | // Verify that a request for ANQP elements is initiated. |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 574 | verify(mAnqpRequestManager).requestANQPElements(eq(TEST_BSSID), any(ANQPNetworkKey.class), |
Peter Qiu | 33c46cd | 2016-12-19 13:12:13 -0800 | [diff] [blame] | 575 | anyBoolean(), anyBoolean()); |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | /** |
Peter Qiu | b54f07e | 2017-03-07 14:56:15 -0800 | [diff] [blame] | 579 | * Verify that the expected provider will be returned when a HomeProvider is matched. |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 580 | * |
| 581 | * @throws Exception |
| 582 | */ |
| 583 | @Test |
| 584 | public void matchProviderAsHomeProvider() throws Exception { |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 585 | PasspointProvider provider = addTestProvider(TEST_FQDN); |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 586 | ANQPData entry = new ANQPData(mClock, null); |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 587 | |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 588 | when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); |
Masashi Honma | 2e889dc | 2018-04-02 17:09:51 +0900 | [diff] [blame] | 589 | when(provider.match(anyMap(), any(RoamingConsortium.class))) |
| 590 | .thenReturn(PasspointMatch.HomeProvider); |
Peter Qiu | b54f07e | 2017-03-07 14:56:15 -0800 | [diff] [blame] | 591 | Pair<PasspointProvider, PasspointMatch> result = |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 592 | mManager.matchProvider(createTestScanResult()); |
Peter Qiu | b54f07e | 2017-03-07 14:56:15 -0800 | [diff] [blame] | 593 | assertEquals(PasspointMatch.HomeProvider, result.second); |
| 594 | assertEquals(TEST_FQDN, result.first.getConfig().getHomeSp().getFqdn()); |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /** |
Peter Qiu | b54f07e | 2017-03-07 14:56:15 -0800 | [diff] [blame] | 598 | * Verify that the expected provider will be returned when a RoamingProvider is matched. |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 599 | * |
| 600 | * @throws Exception |
| 601 | */ |
| 602 | @Test |
| 603 | public void matchProviderAsRoamingProvider() throws Exception { |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 604 | PasspointProvider provider = addTestProvider(TEST_FQDN); |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 605 | ANQPData entry = new ANQPData(mClock, null); |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 606 | |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 607 | when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); |
Masashi Honma | 2e889dc | 2018-04-02 17:09:51 +0900 | [diff] [blame] | 608 | when(provider.match(anyMap(), any(RoamingConsortium.class))) |
| 609 | .thenReturn(PasspointMatch.RoamingProvider); |
Peter Qiu | b54f07e | 2017-03-07 14:56:15 -0800 | [diff] [blame] | 610 | Pair<PasspointProvider, PasspointMatch> result = |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 611 | mManager.matchProvider(createTestScanResult()); |
Peter Qiu | b54f07e | 2017-03-07 14:56:15 -0800 | [diff] [blame] | 612 | assertEquals(PasspointMatch.RoamingProvider, result.second); |
| 613 | assertEquals(TEST_FQDN, result.first.getConfig().getHomeSp().getFqdn()); |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | /** |
Peter Qiu | b54f07e | 2017-03-07 14:56:15 -0800 | [diff] [blame] | 617 | * Verify that a {code null} will be returned when there is no matching provider. |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 618 | * |
| 619 | * @throws Exception |
| 620 | */ |
| 621 | @Test |
| 622 | public void matchProviderWithNoMatch() throws Exception { |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 623 | PasspointProvider provider = addTestProvider(TEST_FQDN); |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 624 | ANQPData entry = new ANQPData(mClock, null); |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 625 | |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 626 | when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); |
Masashi Honma | 2e889dc | 2018-04-02 17:09:51 +0900 | [diff] [blame] | 627 | when(provider.match(anyMap(), any(RoamingConsortium.class))) |
| 628 | .thenReturn(PasspointMatch.None); |
Peter Qiu | b54f07e | 2017-03-07 14:56:15 -0800 | [diff] [blame] | 629 | assertNull(mManager.matchProvider(createTestScanResult())); |
Peter Qiu | 3d42402 | 2016-11-30 13:36:25 -0800 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | /** |
| 633 | * Verify the expectations for sweepCache. |
| 634 | * |
| 635 | * @throws Exception |
| 636 | */ |
| 637 | @Test |
| 638 | public void sweepCache() throws Exception { |
| 639 | mManager.sweepCache(); |
| 640 | verify(mAnqpCache).sweep(); |
| 641 | } |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 642 | |
| 643 | /** |
Peter Qiu | ec28f86 | 2017-03-07 14:25:01 -0800 | [diff] [blame] | 644 | * Verify that an empty map will be returned if ANQP elements are not cached for the given AP. |
| 645 | * |
| 646 | * @throws Exception |
| 647 | */ |
| 648 | @Test |
| 649 | public void getANQPElementsWithNoMatchFound() throws Exception { |
| 650 | when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(null); |
| 651 | assertTrue(mManager.getANQPElements(createTestScanResult()).isEmpty()); |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * Verify that an expected ANQP elements will be returned if ANQP elements are cached for the |
| 656 | * given AP. |
| 657 | * |
| 658 | * @throws Exception |
| 659 | */ |
| 660 | @Test |
| 661 | public void getANQPElementsWithMatchFound() throws Exception { |
| 662 | Map<ANQPElementType, ANQPElement> anqpElementMap = new HashMap<>(); |
| 663 | anqpElementMap.put(ANQPElementType.ANQPDomName, |
| 664 | new DomainNameElement(Arrays.asList(new String[] {"test.com"}))); |
| 665 | ANQPData entry = new ANQPData(mClock, anqpElementMap); |
| 666 | |
| 667 | when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); |
| 668 | assertEquals(anqpElementMap, mManager.getANQPElements(createTestScanResult())); |
| 669 | } |
| 670 | |
| 671 | /** |
Peter Qiu | 48c93da | 2017-03-09 13:28:47 -0800 | [diff] [blame] | 672 | * Verify that an expected {@link WifiConfiguration} will be returned when a {@link ScanResult} |
| 673 | * is matched to a home provider. |
| 674 | * |
| 675 | * @throws Exception |
| 676 | */ |
| 677 | @Test |
| 678 | public void getMatchingWifiConfigForHomeProviderAP() throws Exception { |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 679 | PasspointProvider provider = addTestProvider(TEST_FQDN); |
Peter Qiu | 48c93da | 2017-03-09 13:28:47 -0800 | [diff] [blame] | 680 | ANQPData entry = new ANQPData(mClock, null); |
| 681 | |
| 682 | when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); |
Masashi Honma | 2e889dc | 2018-04-02 17:09:51 +0900 | [diff] [blame] | 683 | when(provider.match(anyMap(), any(RoamingConsortium.class))) |
| 684 | .thenReturn(PasspointMatch.HomeProvider); |
Peter Qiu | 48c93da | 2017-03-09 13:28:47 -0800 | [diff] [blame] | 685 | when(provider.getWifiConfig()).thenReturn(new WifiConfiguration()); |
| 686 | WifiConfiguration config = mManager.getMatchingWifiConfig(createTestScanResult()); |
| 687 | assertEquals(ScanResultUtil.createQuotedSSID(TEST_SSID), config.SSID); |
Peter Qiu | d6ba42b | 2017-03-27 09:26:34 -0700 | [diff] [blame] | 688 | assertTrue(config.isHomeProviderNetwork); |
Peter Qiu | 48c93da | 2017-03-09 13:28:47 -0800 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | /** |
| 692 | * Verify that an expected {@link WifiConfiguration} will be returned when a {@link ScanResult} |
| 693 | * is matched to a roaming provider. |
| 694 | * |
| 695 | * @throws Exception |
| 696 | */ |
| 697 | @Test |
| 698 | public void getMatchingWifiConfigForRoamingProviderAP() throws Exception { |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 699 | PasspointProvider provider = addTestProvider(TEST_FQDN); |
Peter Qiu | 48c93da | 2017-03-09 13:28:47 -0800 | [diff] [blame] | 700 | ANQPData entry = new ANQPData(mClock, null); |
| 701 | |
| 702 | when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); |
Masashi Honma | 2e889dc | 2018-04-02 17:09:51 +0900 | [diff] [blame] | 703 | when(provider.match(anyMap(), any(RoamingConsortium.class))) |
| 704 | .thenReturn(PasspointMatch.RoamingProvider); |
Peter Qiu | 48c93da | 2017-03-09 13:28:47 -0800 | [diff] [blame] | 705 | when(provider.getWifiConfig()).thenReturn(new WifiConfiguration()); |
| 706 | WifiConfiguration config = mManager.getMatchingWifiConfig(createTestScanResult()); |
| 707 | assertEquals(ScanResultUtil.createQuotedSSID(TEST_SSID), config.SSID); |
Peter Qiu | d6ba42b | 2017-03-27 09:26:34 -0700 | [diff] [blame] | 708 | assertFalse(config.isHomeProviderNetwork); |
Peter Qiu | 48c93da | 2017-03-09 13:28:47 -0800 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | /** |
| 712 | * Verify that a {code null} will be returned when a {@link ScanResult} doesn't match any |
| 713 | * provider. |
| 714 | * |
| 715 | * @throws Exception |
| 716 | */ |
| 717 | @Test |
| 718 | public void getMatchingWifiConfigWithNoMatchingProvider() throws Exception { |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 719 | PasspointProvider provider = addTestProvider(TEST_FQDN); |
Peter Qiu | 48c93da | 2017-03-09 13:28:47 -0800 | [diff] [blame] | 720 | ANQPData entry = new ANQPData(mClock, null); |
| 721 | |
| 722 | when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); |
Masashi Honma | 2e889dc | 2018-04-02 17:09:51 +0900 | [diff] [blame] | 723 | when(provider.match(anyMap(), any(RoamingConsortium.class))) |
| 724 | .thenReturn(PasspointMatch.None); |
Peter Qiu | 48c93da | 2017-03-09 13:28:47 -0800 | [diff] [blame] | 725 | assertNull(mManager.getMatchingWifiConfig(createTestScanResult())); |
| 726 | verify(provider, never()).getWifiConfig(); |
| 727 | } |
| 728 | |
| 729 | /** |
Peter Qiu | 33c3ae8 | 2017-06-02 11:35:06 -0700 | [diff] [blame] | 730 | * Verify that a {@code null} will be returned when trying to get a matching |
| 731 | * {@link WifiConfiguration} for a {@code null} {@link ScanResult}. |
Peter Qiu | 48c93da | 2017-03-09 13:28:47 -0800 | [diff] [blame] | 732 | * |
| 733 | * @throws Exception |
| 734 | */ |
| 735 | @Test |
| 736 | public void getMatchingWifiConfigWithNullScanResult() throws Exception { |
| 737 | assertNull(mManager.getMatchingWifiConfig(null)); |
| 738 | } |
| 739 | |
| 740 | /** |
Peter Qiu | 33c3ae8 | 2017-06-02 11:35:06 -0700 | [diff] [blame] | 741 | * Verify that a {@code null} will be returned when trying to get a matching |
| 742 | * {@link WifiConfiguration} for a {@link ScanResult} with a {@code null} BSSID. |
| 743 | * |
| 744 | * @throws Exception |
| 745 | */ |
| 746 | @Test |
| 747 | public void getMatchingWifiConfigWithNullBSSID() throws Exception { |
| 748 | ScanResult scanResult = createTestScanResult(); |
| 749 | scanResult.BSSID = null; |
| 750 | assertNull(mManager.getMatchingWifiConfig(scanResult)); |
| 751 | } |
| 752 | |
| 753 | /** |
| 754 | * Verify that a {@code null} will be returned when trying to get a matching |
| 755 | * {@link WifiConfiguration} for a {@link ScanResult} with an invalid BSSID. |
| 756 | * |
| 757 | * @throws Exception |
| 758 | */ |
| 759 | @Test |
| 760 | public void getMatchingWifiConfigWithInvalidBSSID() throws Exception { |
| 761 | ScanResult scanResult = createTestScanResult(); |
| 762 | scanResult.BSSID = "asdfdasfas"; |
| 763 | assertNull(mManager.getMatchingWifiConfig(scanResult)); |
| 764 | } |
| 765 | |
| 766 | /** |
| 767 | * Verify that a {@code null} will be returned when trying to get a matching |
| 768 | * {@link WifiConfiguration} for a non-Passpoint AP. |
| 769 | * |
| 770 | * @throws Exception |
| 771 | */ |
| 772 | @Test |
| 773 | public void getMatchingWifiConfigForNonPasspointAP() throws Exception { |
| 774 | ScanResult scanResult = createTestScanResult(); |
| 775 | scanResult.flags = 0; |
| 776 | assertNull(mManager.getMatchingWifiConfig(scanResult)); |
| 777 | } |
| 778 | |
| 779 | /** |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 780 | * Verify that an expected set of {@link WifiConfiguration} will be returned when a |
| 781 | * {@link ScanResult} is matched to a provider. |
| 782 | * |
| 783 | * @throws Exception |
| 784 | */ |
| 785 | @Test |
| 786 | public void getAllMatchingWifiConfigsForProviderAP() throws Exception { |
| 787 | PasspointProvider providerHome = addTestProvider(TEST_FQDN + 0); |
| 788 | PasspointProvider providerRoaming = addTestProvider(TEST_FQDN + 1); |
| 789 | PasspointProvider providerNone = addTestProvider(TEST_FQDN + 2); |
| 790 | ANQPData entry = new ANQPData(mClock, null); |
| 791 | |
| 792 | when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); |
| 793 | |
Masashi Honma | 2e889dc | 2018-04-02 17:09:51 +0900 | [diff] [blame] | 794 | when(providerHome.match(anyMap(), any(RoamingConsortium.class))) |
| 795 | .thenReturn(PasspointMatch.HomeProvider); |
| 796 | when(providerRoaming.match(anyMap(), any(RoamingConsortium.class))) |
| 797 | .thenReturn(PasspointMatch.RoamingProvider); |
| 798 | when(providerNone.match(anyMap(), any(RoamingConsortium.class))) |
| 799 | .thenReturn(PasspointMatch.None); |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 800 | |
| 801 | when(providerHome.getWifiConfig()).thenReturn(new WifiConfiguration()); |
| 802 | when(providerRoaming.getWifiConfig()).thenReturn(new WifiConfiguration()); |
| 803 | when(providerNone.getWifiConfig()).thenReturn(new WifiConfiguration()); |
| 804 | |
| 805 | List<WifiConfiguration> configs = mManager.getAllMatchingWifiConfigs( |
| 806 | createTestScanResult()); |
| 807 | |
| 808 | assertEquals(2, configs.size()); |
| 809 | int observedHome = 0; |
| 810 | int observedRoaming = 0; |
| 811 | for (WifiConfiguration config : configs) { |
| 812 | assertEquals(ScanResultUtil.createQuotedSSID(TEST_SSID), config.SSID); |
| 813 | if (config.isHomeProviderNetwork) { |
| 814 | observedHome++; |
| 815 | } else { |
| 816 | observedRoaming++; |
| 817 | } |
| 818 | } |
| 819 | assertEquals(1, observedHome); |
| 820 | assertEquals(1, observedRoaming); |
| 821 | } |
| 822 | |
| 823 | /** |
| 824 | * Verify that an empty list will be returned when trying to get all matching |
| 825 | * {@link WifiConfiguration} for a {@code null} {@link ScanResult}. |
| 826 | * |
| 827 | * @throws Exception |
| 828 | */ |
| 829 | @Test |
| 830 | public void getAllMatchingWifiConfigsWithNullScanResult() throws Exception { |
| 831 | assertEquals(0, mManager.getAllMatchingWifiConfigs(null).size()); |
| 832 | } |
| 833 | |
| 834 | /** |
| 835 | * Verify that an empty list will be returned when trying to get a all matching |
| 836 | * {@link WifiConfiguration} for a {@link ScanResult} with a {@code null} BSSID. |
| 837 | * |
| 838 | * @throws Exception |
| 839 | */ |
| 840 | @Test |
| 841 | public void getAllMatchingWifiConfigWithNullBSSID() throws Exception { |
| 842 | ScanResult scanResult = createTestScanResult(); |
| 843 | scanResult.BSSID = null; |
| 844 | assertEquals(0, mManager.getAllMatchingWifiConfigs(scanResult).size()); |
| 845 | } |
| 846 | |
| 847 | /** |
| 848 | * Verify that an empty list will be returned when trying to get all matching |
| 849 | * {@link WifiConfiguration} for a {@link ScanResult} with an invalid BSSID. |
| 850 | * |
| 851 | * @throws Exception |
| 852 | */ |
| 853 | @Test |
| 854 | public void getAllMatchingWifiConfigWithInvalidBSSID() throws Exception { |
| 855 | ScanResult scanResult = createTestScanResult(); |
| 856 | scanResult.BSSID = "asdfdasfas"; |
| 857 | assertEquals(0, mManager.getAllMatchingWifiConfigs(scanResult).size()); |
| 858 | } |
| 859 | |
| 860 | /** |
| 861 | * Verify that an empty list will be returned when trying to get all matching |
| 862 | * {@link WifiConfiguration} for a non-Passpoint AP. |
| 863 | * |
| 864 | * @throws Exception |
| 865 | */ |
| 866 | @Test |
| 867 | public void getAllMatchingWifiConfigForNonPasspointAP() throws Exception { |
| 868 | ScanResult scanResult = createTestScanResult(); |
| 869 | scanResult.flags = 0; |
| 870 | assertEquals(0, mManager.getAllMatchingWifiConfigs(scanResult).size()); |
| 871 | } |
| 872 | |
| 873 | /** |
Peter Qiu | ac4ab1b | 2017-06-06 13:59:04 -0700 | [diff] [blame] | 874 | * Verify that an empty list will be returned when retrieving OSU providers for an AP with |
| 875 | * null scan result. |
| 876 | * |
| 877 | * @throws Exception |
| 878 | */ |
| 879 | @Test |
| 880 | public void getMatchingOsuProvidersForNullScanResult() throws Exception { |
| 881 | assertTrue(mManager.getMatchingOsuProviders(null).isEmpty()); |
| 882 | } |
| 883 | |
| 884 | /** |
| 885 | * Verify that an empty list will be returned when retrieving OSU providers for an AP with |
| 886 | * invalid BSSID. |
| 887 | * |
| 888 | * @throws Exception |
| 889 | */ |
| 890 | @Test |
| 891 | public void getMatchingOsuProvidersForInvalidBSSID() throws Exception { |
| 892 | ScanResult scanResult = createTestScanResult(); |
| 893 | scanResult.BSSID = "asdfdasfas"; |
| 894 | assertTrue(mManager.getMatchingOsuProviders(scanResult).isEmpty()); |
| 895 | } |
| 896 | |
| 897 | /** |
| 898 | * Verify that an empty list will be returned when retrieving OSU providers for a |
| 899 | * non-Passpoint AP. |
| 900 | * |
| 901 | * @throws Exception |
| 902 | */ |
| 903 | @Test |
| 904 | public void getMatchingOsuProvidersForNonPasspointAP() throws Exception { |
| 905 | ScanResult scanResult = createTestScanResult(); |
| 906 | scanResult.flags = 0; |
| 907 | assertTrue(mManager.getMatchingOsuProviders(scanResult).isEmpty()); |
| 908 | } |
| 909 | |
| 910 | /** |
| 911 | * Verify that an empty list will be returned when no match is found from the ANQP cache. |
| 912 | * |
| 913 | * @throws Exception |
| 914 | */ |
| 915 | @Test |
| 916 | public void getMatchingOsuProviderWithNoMatch() throws Exception { |
| 917 | when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(null); |
| 918 | assertTrue(mManager.getMatchingOsuProviders(createTestScanResult()).isEmpty()); |
| 919 | } |
| 920 | |
| 921 | /** |
| 922 | * Verify that an expected provider list will be returned when a match is found from |
| 923 | * the ANQP cache. |
| 924 | * |
| 925 | * @throws Exception |
| 926 | */ |
| 927 | @Test |
| 928 | public void getMatchingOsuProvidersWithMatch() throws Exception { |
| 929 | // Test data. |
| 930 | WifiSsid osuSsid = WifiSsid.createFromAsciiEncoded("Test SSID"); |
| 931 | String friendlyName = "Test Provider"; |
| 932 | String serviceDescription = "Dummy Service"; |
| 933 | Uri serverUri = Uri.parse("https://test.com"); |
| 934 | String nai = "access.test.com"; |
| 935 | List<Integer> methodList = Arrays.asList(1); |
| 936 | List<I18Name> friendlyNames = Arrays.asList( |
| 937 | new I18Name(Locale.ENGLISH.getLanguage(), Locale.ENGLISH, friendlyName)); |
| 938 | List<I18Name> serviceDescriptions = Arrays.asList( |
| 939 | new I18Name(Locale.ENGLISH.getLanguage(), Locale.ENGLISH, serviceDescription)); |
| 940 | |
| 941 | // Setup OSU providers ANQP element. |
| 942 | List<OsuProviderInfo> providerInfoList = new ArrayList<>(); |
| 943 | providerInfoList.add(new OsuProviderInfo( |
| 944 | friendlyNames, serverUri, methodList, null, nai, serviceDescriptions)); |
| 945 | Map<ANQPElementType, ANQPElement> anqpElementMap = new HashMap<>(); |
| 946 | anqpElementMap.put(ANQPElementType.HSOSUProviders, |
| 947 | new HSOsuProvidersElement(osuSsid, providerInfoList)); |
| 948 | ANQPData entry = new ANQPData(mClock, anqpElementMap); |
| 949 | |
| 950 | // Setup expectation. |
| 951 | OsuProvider provider = new OsuProvider( |
| 952 | osuSsid, friendlyName, serviceDescription, serverUri, nai, methodList, null); |
| 953 | List<OsuProvider> expectedList = new ArrayList<>(); |
| 954 | expectedList.add(provider); |
| 955 | |
| 956 | when(mAnqpCache.getEntry(TEST_ANQP_KEY)).thenReturn(entry); |
| 957 | assertEquals(expectedList, mManager.getMatchingOsuProviders(createTestScanResult())); |
| 958 | } |
| 959 | |
| 960 | /** |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 961 | * Verify that the provider list maintained by the PasspointManager after the list is updated |
| 962 | * in the data source. |
| 963 | * |
| 964 | * @throws Exception |
| 965 | */ |
| 966 | @Test |
| 967 | public void verifyProvidersAfterDataSourceUpdate() throws Exception { |
| 968 | // Update the provider list in the data source. |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 969 | PasspointConfiguration config = createTestConfigWithUserCredential(TEST_FQDN); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 970 | PasspointProvider provider = createMockProvider(config); |
| 971 | List<PasspointProvider> providers = new ArrayList<>(); |
| 972 | providers.add(provider); |
| 973 | mDataSource.setProviders(providers); |
| 974 | |
| 975 | // Verify the providers maintained by PasspointManager. |
| 976 | assertEquals(1, mManager.getProviderConfigs().size()); |
| 977 | assertEquals(config, mManager.getProviderConfigs().get(0)); |
| 978 | } |
| 979 | |
| 980 | /** |
| 981 | * Verify that the provider index used by PasspointManager is updated after it is updated in |
| 982 | * the data source. |
| 983 | * |
| 984 | * @throws Exception |
| 985 | */ |
| 986 | @Test |
| 987 | public void verifyProviderIndexAfterDataSourceUpdate() throws Exception { |
| 988 | long providerIndex = 9; |
| 989 | mDataSource.setProviderIndex(providerIndex); |
| 990 | assertEquals(providerIndex, mDataSource.getProviderIndex()); |
| 991 | |
| 992 | // Add a provider. |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 993 | PasspointConfiguration config = createTestConfigWithUserCredential(TEST_FQDN); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 994 | PasspointProvider provider = createMockProvider(config); |
| 995 | // Verify the provider ID used to create the new provider. |
| 996 | when(mObjectFactory.makePasspointProvider(eq(config), eq(mWifiKeyStore), |
Peter Qiu | 07816a4 | 2017-04-03 17:08:33 +0000 | [diff] [blame] | 997 | eq(mSimAccessor), eq(providerIndex), eq(TEST_CREATOR_UID))).thenReturn(provider); |
| 998 | assertTrue(mManager.addOrUpdateProvider(config, TEST_CREATOR_UID)); |
Peter Qiu | 99d4b81 | 2017-02-14 09:42:55 -0800 | [diff] [blame] | 999 | verifyInstalledConfig(config); |
| 1000 | verify(mWifiConfigManager).saveToStore(true); |
| 1001 | reset(mWifiConfigManager); |
| 1002 | } |
Peter Qiu | 5e4822d | 2017-02-23 11:32:33 -0800 | [diff] [blame] | 1003 | |
| 1004 | /** |
| 1005 | * Verify that a PasspointProvider with expected PasspointConfiguration will be installed when |
| 1006 | * adding a legacy Passpoint configuration containing a valid user credential. |
| 1007 | * |
| 1008 | * @throws Exception |
| 1009 | */ |
| 1010 | @Test |
| 1011 | public void addLegacyPasspointConfigWithUserCredential() throws Exception { |
| 1012 | // Test data. |
| 1013 | String fqdn = "test.com"; |
| 1014 | String friendlyName = "Friendly Name"; |
| 1015 | long[] rcOIs = new long[] {0x1234L, 0x2345L}; |
| 1016 | String realm = "realm.com"; |
| 1017 | String username = "username"; |
| 1018 | String password = "password"; |
| 1019 | byte[] base64EncodedPw = |
| 1020 | Base64.encode(password.getBytes(StandardCharsets.UTF_8), Base64.DEFAULT); |
| 1021 | String encodedPasswordStr = new String(base64EncodedPw, StandardCharsets.UTF_8); |
| 1022 | String caCertificateAlias = "CaCert"; |
| 1023 | |
| 1024 | // Setup WifiConfiguration for legacy Passpoint configuraiton. |
| 1025 | WifiConfiguration wifiConfig = new WifiConfiguration(); |
| 1026 | wifiConfig.FQDN = fqdn; |
| 1027 | wifiConfig.providerFriendlyName = friendlyName; |
| 1028 | wifiConfig.roamingConsortiumIds = rcOIs; |
| 1029 | wifiConfig.enterpriseConfig.setIdentity(username); |
| 1030 | wifiConfig.enterpriseConfig.setPassword(password); |
| 1031 | wifiConfig.enterpriseConfig.setRealm(realm); |
| 1032 | wifiConfig.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TTLS); |
| 1033 | wifiConfig.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.PAP); |
| 1034 | wifiConfig.enterpriseConfig.setCaCertificateAlias(caCertificateAlias); |
| 1035 | |
| 1036 | // Setup expected {@link PasspointConfiguration} |
| 1037 | PasspointConfiguration passpointConfig = new PasspointConfiguration(); |
| 1038 | HomeSp homeSp = new HomeSp(); |
| 1039 | homeSp.setFqdn(fqdn); |
| 1040 | homeSp.setFriendlyName(friendlyName); |
| 1041 | homeSp.setRoamingConsortiumOis(rcOIs); |
| 1042 | passpointConfig.setHomeSp(homeSp); |
| 1043 | Credential credential = new Credential(); |
| 1044 | Credential.UserCredential userCredential = new Credential.UserCredential(); |
| 1045 | userCredential.setUsername(username); |
| 1046 | userCredential.setPassword(encodedPasswordStr); |
| 1047 | userCredential.setEapType(EAPConstants.EAP_TTLS); |
| 1048 | userCredential.setNonEapInnerMethod("PAP"); |
| 1049 | credential.setUserCredential(userCredential); |
| 1050 | credential.setRealm(realm); |
| 1051 | passpointConfig.setCredential(credential); |
| 1052 | |
| 1053 | assertTrue(PasspointManager.addLegacyPasspointConfig(wifiConfig)); |
| 1054 | verifyInstalledConfig(passpointConfig); |
| 1055 | } |
| 1056 | |
| 1057 | /** |
| 1058 | * Verify that adding a legacy Passpoint configuration containing user credential will |
| 1059 | * fail when client certificate is not provided. |
| 1060 | * |
| 1061 | * @throws Exception |
| 1062 | */ |
| 1063 | @Test |
| 1064 | public void addLegacyPasspointConfigWithUserCredentialWithoutCaCert() throws Exception { |
| 1065 | // Test data. |
| 1066 | String fqdn = "test.com"; |
| 1067 | String friendlyName = "Friendly Name"; |
| 1068 | long[] rcOIs = new long[] {0x1234L, 0x2345L}; |
| 1069 | String realm = "realm.com"; |
| 1070 | String username = "username"; |
| 1071 | String password = "password"; |
| 1072 | byte[] base64EncodedPw = |
| 1073 | Base64.encode(password.getBytes(StandardCharsets.UTF_8), Base64.DEFAULT); |
| 1074 | String encodedPasswordStr = new String(base64EncodedPw, StandardCharsets.UTF_8); |
| 1075 | |
| 1076 | // Setup WifiConfiguration for legacy Passpoint configuraiton. |
| 1077 | WifiConfiguration wifiConfig = new WifiConfiguration(); |
| 1078 | wifiConfig.FQDN = fqdn; |
| 1079 | wifiConfig.providerFriendlyName = friendlyName; |
| 1080 | wifiConfig.roamingConsortiumIds = rcOIs; |
| 1081 | wifiConfig.enterpriseConfig.setIdentity(username); |
| 1082 | wifiConfig.enterpriseConfig.setPassword(password); |
| 1083 | wifiConfig.enterpriseConfig.setRealm(realm); |
| 1084 | wifiConfig.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TTLS); |
| 1085 | wifiConfig.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.PAP); |
| 1086 | |
| 1087 | assertFalse(PasspointManager.addLegacyPasspointConfig(wifiConfig)); |
| 1088 | } |
| 1089 | |
| 1090 | /** |
| 1091 | * Verify that a PasspointProvider with expected PasspointConfiguration will be installed when |
| 1092 | * adding a legacy Passpoint configuration containing a valid SIM credential. |
| 1093 | * |
| 1094 | * @throws Exception |
| 1095 | */ |
| 1096 | @Test |
| 1097 | public void addLegacyPasspointConfigWithSimCredential() throws Exception { |
| 1098 | // Test data. |
| 1099 | String fqdn = "test.com"; |
| 1100 | String friendlyName = "Friendly Name"; |
| 1101 | long[] rcOIs = new long[] {0x1234L, 0x2345L}; |
| 1102 | String realm = "realm.com"; |
| 1103 | String imsi = "1234"; |
| 1104 | |
| 1105 | // Setup WifiConfiguration for legacy Passpoint configuraiton. |
| 1106 | WifiConfiguration wifiConfig = new WifiConfiguration(); |
| 1107 | wifiConfig.FQDN = fqdn; |
| 1108 | wifiConfig.providerFriendlyName = friendlyName; |
| 1109 | wifiConfig.roamingConsortiumIds = rcOIs; |
| 1110 | wifiConfig.enterpriseConfig.setRealm(realm); |
| 1111 | wifiConfig.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.SIM); |
| 1112 | wifiConfig.enterpriseConfig.setPlmn(imsi); |
| 1113 | |
| 1114 | // Setup expected {@link PasspointConfiguration} |
| 1115 | PasspointConfiguration passpointConfig = new PasspointConfiguration(); |
| 1116 | HomeSp homeSp = new HomeSp(); |
| 1117 | homeSp.setFqdn(fqdn); |
| 1118 | homeSp.setFriendlyName(friendlyName); |
| 1119 | homeSp.setRoamingConsortiumOis(rcOIs); |
| 1120 | passpointConfig.setHomeSp(homeSp); |
| 1121 | Credential credential = new Credential(); |
| 1122 | Credential.SimCredential simCredential = new Credential.SimCredential(); |
| 1123 | simCredential.setEapType(EAPConstants.EAP_SIM); |
| 1124 | simCredential.setImsi(imsi); |
| 1125 | credential.setSimCredential(simCredential); |
| 1126 | credential.setRealm(realm); |
| 1127 | passpointConfig.setCredential(credential); |
| 1128 | |
| 1129 | assertTrue(PasspointManager.addLegacyPasspointConfig(wifiConfig)); |
| 1130 | verifyInstalledConfig(passpointConfig); |
| 1131 | } |
| 1132 | |
| 1133 | /** |
| 1134 | * Verify that a PasspointProvider with expected PasspointConfiguration will be installed when |
| 1135 | * adding a legacy Passpoint configuration containing a valid certificate credential. |
| 1136 | * |
| 1137 | * @throws Exception |
| 1138 | */ |
| 1139 | @Test |
| 1140 | public void addLegacyPasspointConfigWithCertCredential() throws Exception { |
| 1141 | // Test data. |
| 1142 | String fqdn = "test.com"; |
| 1143 | String friendlyName = "Friendly Name"; |
| 1144 | long[] rcOIs = new long[] {0x1234L, 0x2345L}; |
| 1145 | String realm = "realm.com"; |
| 1146 | String caCertificateAlias = "CaCert"; |
| 1147 | String clientCertificateAlias = "ClientCert"; |
| 1148 | |
| 1149 | // Setup WifiConfiguration for legacy Passpoint configuraiton. |
| 1150 | WifiConfiguration wifiConfig = new WifiConfiguration(); |
| 1151 | wifiConfig.FQDN = fqdn; |
| 1152 | wifiConfig.providerFriendlyName = friendlyName; |
| 1153 | wifiConfig.roamingConsortiumIds = rcOIs; |
| 1154 | wifiConfig.enterpriseConfig.setRealm(realm); |
| 1155 | wifiConfig.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TLS); |
| 1156 | wifiConfig.enterpriseConfig.setCaCertificateAlias(caCertificateAlias); |
| 1157 | wifiConfig.enterpriseConfig.setClientCertificateAlias(clientCertificateAlias); |
| 1158 | |
| 1159 | // Setup expected {@link PasspointConfiguration} |
| 1160 | PasspointConfiguration passpointConfig = new PasspointConfiguration(); |
| 1161 | HomeSp homeSp = new HomeSp(); |
| 1162 | homeSp.setFqdn(fqdn); |
| 1163 | homeSp.setFriendlyName(friendlyName); |
| 1164 | homeSp.setRoamingConsortiumOis(rcOIs); |
| 1165 | passpointConfig.setHomeSp(homeSp); |
| 1166 | Credential credential = new Credential(); |
| 1167 | Credential.CertificateCredential certCredential = new Credential.CertificateCredential(); |
| 1168 | certCredential.setCertType(Credential.CertificateCredential.CERT_TYPE_X509V3); |
| 1169 | credential.setCertCredential(certCredential); |
| 1170 | credential.setRealm(realm); |
| 1171 | passpointConfig.setCredential(credential); |
| 1172 | |
| 1173 | assertTrue(PasspointManager.addLegacyPasspointConfig(wifiConfig)); |
| 1174 | verifyInstalledConfig(passpointConfig); |
| 1175 | } |
| 1176 | |
| 1177 | /** |
| 1178 | * Verify that adding a legacy Passpoint configuration containing certificate credential will |
| 1179 | * fail when CA certificate is not provided. |
| 1180 | * |
| 1181 | * @throws Exception |
| 1182 | */ |
| 1183 | @Test |
| 1184 | public void addLegacyPasspointConfigWithCertCredentialWithoutCaCert() throws Exception { |
| 1185 | // Test data. |
| 1186 | String fqdn = "test.com"; |
| 1187 | String friendlyName = "Friendly Name"; |
| 1188 | long[] rcOIs = new long[] {0x1234L, 0x2345L}; |
| 1189 | String realm = "realm.com"; |
| 1190 | String clientCertificateAlias = "ClientCert"; |
| 1191 | |
| 1192 | // Setup WifiConfiguration for legacy Passpoint configuraiton. |
| 1193 | WifiConfiguration wifiConfig = new WifiConfiguration(); |
| 1194 | wifiConfig.FQDN = fqdn; |
| 1195 | wifiConfig.providerFriendlyName = friendlyName; |
| 1196 | wifiConfig.roamingConsortiumIds = rcOIs; |
| 1197 | wifiConfig.enterpriseConfig.setRealm(realm); |
| 1198 | wifiConfig.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TLS); |
| 1199 | wifiConfig.enterpriseConfig.setClientCertificateAlias(clientCertificateAlias); |
| 1200 | |
| 1201 | assertFalse(PasspointManager.addLegacyPasspointConfig(wifiConfig)); |
| 1202 | } |
| 1203 | |
| 1204 | /** |
| 1205 | * Verify that adding a legacy Passpoint configuration containing certificate credential will |
| 1206 | * fail when client certificate is not provided. |
| 1207 | * |
| 1208 | * @throws Exception |
| 1209 | */ |
| 1210 | @Test |
| 1211 | public void addLegacyPasspointConfigWithCertCredentialWithoutClientCert() throws Exception { |
| 1212 | // Test data. |
| 1213 | String fqdn = "test.com"; |
| 1214 | String friendlyName = "Friendly Name"; |
| 1215 | long[] rcOIs = new long[] {0x1234L, 0x2345L}; |
| 1216 | String realm = "realm.com"; |
| 1217 | String caCertificateAlias = "CaCert"; |
| 1218 | |
| 1219 | // Setup WifiConfiguration for legacy Passpoint configuraiton. |
| 1220 | WifiConfiguration wifiConfig = new WifiConfiguration(); |
| 1221 | wifiConfig.FQDN = fqdn; |
| 1222 | wifiConfig.providerFriendlyName = friendlyName; |
| 1223 | wifiConfig.roamingConsortiumIds = rcOIs; |
| 1224 | wifiConfig.enterpriseConfig.setRealm(realm); |
| 1225 | wifiConfig.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TLS); |
| 1226 | wifiConfig.enterpriseConfig.setCaCertificateAlias(caCertificateAlias); |
| 1227 | |
| 1228 | assertFalse(PasspointManager.addLegacyPasspointConfig(wifiConfig)); |
| 1229 | } |
Peter Qiu | 49357a3 | 2017-06-22 15:48:19 -0700 | [diff] [blame] | 1230 | |
| 1231 | /** |
| 1232 | * Verify that the provider's "hasEverConnected" flag will be set to true and the associated |
| 1233 | * metric is updated after the provider was used to successfully connect to a Passpoint |
| 1234 | * network for the first time. |
| 1235 | * |
| 1236 | * @throws Exception |
| 1237 | */ |
| 1238 | @Test |
| 1239 | public void providerNetworkConnectedFirstTime() throws Exception { |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 1240 | PasspointProvider provider = addTestProvider(TEST_FQDN); |
Peter Qiu | 49357a3 | 2017-06-22 15:48:19 -0700 | [diff] [blame] | 1241 | when(provider.getHasEverConnected()).thenReturn(false); |
| 1242 | mManager.onPasspointNetworkConnected(TEST_FQDN); |
| 1243 | verify(provider).setHasEverConnected(eq(true)); |
| 1244 | } |
| 1245 | |
| 1246 | /** |
| 1247 | * Verify that the provider's "hasEverConnected" flag the associated metric is not updated |
| 1248 | * after the provider was used to successfully connect to a Passpoint network for non-first |
| 1249 | * time. |
| 1250 | * |
| 1251 | * @throws Exception |
| 1252 | */ |
| 1253 | @Test |
| 1254 | public void providerNetworkConnectedNotFirstTime() throws Exception { |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 1255 | PasspointProvider provider = addTestProvider(TEST_FQDN); |
Peter Qiu | 49357a3 | 2017-06-22 15:48:19 -0700 | [diff] [blame] | 1256 | when(provider.getHasEverConnected()).thenReturn(true); |
| 1257 | mManager.onPasspointNetworkConnected(TEST_FQDN); |
| 1258 | verify(provider, never()).setHasEverConnected(anyBoolean()); |
| 1259 | } |
| 1260 | |
| 1261 | /** |
| 1262 | * Verify that the expected Passpoint metrics are updated when |
| 1263 | * {@link PasspointManager#updateMetrics} is invoked. |
| 1264 | * |
| 1265 | * @throws Exception |
| 1266 | */ |
| 1267 | @Test |
| 1268 | public void updateMetrics() throws Exception { |
Etan Cohen | d3fb3d8 | 2017-10-17 08:43:56 -0700 | [diff] [blame] | 1269 | PasspointProvider provider = addTestProvider(TEST_FQDN); |
Peter Qiu | 49357a3 | 2017-06-22 15:48:19 -0700 | [diff] [blame] | 1270 | |
| 1271 | // Provider have not provided a successful network connection. |
| 1272 | int expectedInstalledProviders = 1; |
| 1273 | int expectedConnectedProviders = 0; |
| 1274 | when(provider.getHasEverConnected()).thenReturn(false); |
| 1275 | mManager.updateMetrics(); |
| 1276 | verify(mWifiMetrics).updateSavedPasspointProfiles( |
| 1277 | eq(expectedInstalledProviders), eq(expectedConnectedProviders)); |
| 1278 | reset(provider); |
| 1279 | reset(mWifiMetrics); |
| 1280 | |
| 1281 | // Provider have provided a successful network connection. |
| 1282 | expectedConnectedProviders = 1; |
| 1283 | when(provider.getHasEverConnected()).thenReturn(true); |
| 1284 | mManager.updateMetrics(); |
| 1285 | verify(mWifiMetrics).updateSavedPasspointProfiles( |
| 1286 | eq(expectedInstalledProviders), eq(expectedConnectedProviders)); |
| 1287 | } |
Sohani Rao | 0ddc2ba | 2017-10-09 14:36:48 -0700 | [diff] [blame] | 1288 | /** |
| 1289 | * Verify Passpoint Manager's provisioning APIs by invoking methods in PasspointProvisioner for |
| 1290 | * initiailization and provisioning a provider. |
| 1291 | */ |
| 1292 | @Test |
| 1293 | public void verifyPasspointProvisioner() { |
| 1294 | mManager.initializeProvisioner(mLooper.getLooper()); |
| 1295 | verify(mPasspointProvisioner).init(any(Looper.class)); |
| 1296 | when(mPasspointProvisioner.startSubscriptionProvisioning(anyInt(), any(OsuProvider.class), |
| 1297 | any(IProvisioningCallback.class))).thenReturn(true); |
| 1298 | OsuProvider osuProvider = PasspointProvisioningTestUtil.generateOsuProvider(true); |
| 1299 | assertEquals(true, |
| 1300 | mManager.startSubscriptionProvisioning(TEST_UID, osuProvider, mCallback)); |
| 1301 | } |
Peter Qiu | eaa6ff2 | 2016-09-12 10:00:13 -0700 | [diff] [blame] | 1302 | } |