summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-08-01 15:18:40 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-08-01 15:18:40 -0700
commite2921b824d04071ae5dcea6d594986b3eeda0752 (patch)
tree9cdc69370b6621531680e238c3458152164f630e /tests
parent03cd20804986d2f77ea03de6722927a090f73cf4 (diff)
parent8e70909c098f29b008d062e0cb30f313d300542d (diff)
WifiConfigStore: Limit integrity checks to single user devices
am: 8e70909c09 Change-Id: I3e29479001db5b537126e89ccddf3c0f3bfbcac4
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java3
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java51
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 686b2098d..28964b109 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -229,7 +229,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