diff options
author | Roshan Pius <rpius@google.com> | 2019-07-30 15:16:31 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2019-08-08 19:05:21 +0000 |
commit | 5be4058e19d5b5244224c6d8580b801567cb9ac7 (patch) | |
tree | 390b889b1d281ddfd97e13c6a0779ce9b03fdc06 /tests | |
parent | 7abed5d4cf741aca02836d06664263dc1e3aa699 (diff) |
WifiConfigStore: Limit integrity checks to single user devices
Bug: 138482990
Test: atest com.android.server.wifi
Test: Device boots up & verified that config store files are not
integrity protected.
Test: Will send for full wifi regression tests.
Change-Id: I1bf8ae320935cc1bf70625792c4c1a5e0d54f034
Merged-In: I1bf8ae320935cc1bf70625792c4c1a5e0d54f034
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java | 3 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java | 51 |
2 files changed, 52 insertions, 2 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index 3b86be887..9d5ed04c7 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -228,7 +228,8 @@ public class WifiConfigManagerTest { mSession = ExtendedMockito.mockitoSession() .mockStatic(WifiConfigStore.class, withSettings().lenient()) .startMocking(); - when(WifiConfigStore.createUserFiles(anyInt())).thenReturn(mock(List.class)); + when(WifiConfigStore.createUserFiles(anyInt(), any(UserManager.class))) + .thenReturn(mock(List.class)); when(mTelephonyManager.createForSubscriptionId(anyInt())).thenReturn(mDataTelephonyManager); } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java index 64e762bec..6fdcce80c 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java @@ -31,6 +31,7 @@ import androidx.test.filters.SmallTest; import com.android.internal.util.ArrayUtils; import com.android.server.wifi.WifiConfigStore.StoreData; import com.android.server.wifi.WifiConfigStore.StoreFile; +import com.android.server.wifi.util.DataIntegrityChecker; import com.android.server.wifi.util.XmlUtil; import org.junit.After; @@ -147,6 +148,7 @@ public class WifiConfigStoreTest { private TestLooper mLooper; @Mock private Clock mClock; @Mock private WifiMetrics mWifiMetrics; + @Mock private DataIntegrityChecker mDataIntegrityChecker; private MockStoreFile mSharedStore; private MockStoreFile mUserStore; private MockStoreFile mUserNetworkSuggestionsStore; @@ -379,6 +381,48 @@ public class WifiConfigStoreTest { } /** + * Tests the read API behaviour after a write to the store files (with no integrity checks). + * Expected behaviour: The read should return the same data that was last written. + */ + @Test + public void testReadAfterWriteWithNoIntegrityCheck() throws Exception { + // Recreate the mock store files with no data integrity checking. + mUserStores.clear(); + mSharedStore = new MockStoreFile(WifiConfigStore.STORE_FILE_SHARED_GENERAL, null); + mUserStore = new MockStoreFile(WifiConfigStore.STORE_FILE_USER_GENERAL, null); + mUserNetworkSuggestionsStore = + new MockStoreFile(WifiConfigStore.STORE_FILE_USER_NETWORK_SUGGESTIONS, null); + mUserStores.add(mUserStore); + mUserStores.add(mUserNetworkSuggestionsStore); + mWifiConfigStore = new WifiConfigStore(mContext, mLooper.getLooper(), mClock, mWifiMetrics, + mSharedStore); + + // Register data container. + mWifiConfigStore.registerStoreData(mSharedStoreData); + mWifiConfigStore.registerStoreData(mUserStoreData); + + // Read both share and user config store. + mWifiConfigStore.switchUserStoresAndRead(mUserStores); + + // Verify no data is read. + assertNull(mUserStoreData.getData()); + assertNull(mSharedStoreData.getData()); + + // Write share and user data. + mUserStoreData.setData(TEST_USER_DATA); + mSharedStoreData.setData(TEST_SHARE_DATA); + mWifiConfigStore.write(true); + + // Read and verify the data content in the data container. + mWifiConfigStore.read(); + assertEquals(TEST_USER_DATA, mUserStoreData.getData()); + assertEquals(TEST_SHARE_DATA, mSharedStoreData.getData()); + + verify(mWifiMetrics, times(2)).noteWifiConfigStoreReadDuration(anyInt()); + verify(mWifiMetrics).noteWifiConfigStoreWriteDuration(anyInt()); + } + + /** * Tests the read API behaviour when the shared store file is empty and the user store * is not yet visible (user not yet unlocked). * Expected behaviour: The read should return an empty store data instance when the file not @@ -761,7 +805,12 @@ public class WifiConfigStoreTest { private boolean mStoreWritten; MockStoreFile(@WifiConfigStore.StoreFileId int fileId) { - super(new File("MockStoreFile"), fileId); + super(new File("MockStoreFile"), fileId, mDataIntegrityChecker); + } + + MockStoreFile(@WifiConfigStore.StoreFileId int fileId, + DataIntegrityChecker dataIntegrityChecker) { + super(new File("MockStoreFile"), fileId, dataIntegrityChecker); } @Override |