summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Su <dysu@google.com>2019-11-05 20:39:39 -0800
committerDavid Su <dysu@google.com>2019-11-05 20:39:39 -0800
commitcf8a3f0243ff1c36ea19d0bb46225f9df4e01c8f (patch)
tree5835d4dff0be5d53cf3b729d0b7824e345645df9 /tests
parent6c1365cf72153135955a29227644bcd4c013a4bb (diff)
WifiP2pService: Add permission checks for new @SystemApis
Add permission checks for newly exposed @SystemApi's in WifiP2pServiceImpl. Bug: 138801922 Test: atest FrameworksWifiTests Change-Id: I7b67ef43220dea8a56467fa4755995977ca5dbc5
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java97
1 files changed, 96 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java
index 1f6ef3deb..018b36818 100644
--- a/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java
@@ -725,6 +725,11 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
when(mWifiInjector.getWifiP2pNative()).thenReturn(mWifiNative);
when(mWifiInjector.getWifiP2pServiceHandlerThread()).thenReturn(mHandlerThread);
when(mWifiInjector.getWifiPermissionsUtil()).thenReturn(mWifiPermissionsUtil);
+ // enable all permissions, disable specific permissions in tests
+ when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true);
+ when(mWifiPermissionsUtil.checkNetworkStackPermission(anyInt())).thenReturn(true);
+ when(mWifiPermissionsUtil.checkReadWifiCredentialPermission(anyInt())).thenReturn(true);
+ when(mWifiPermissionsUtil.checkConfigOverridePermission(anyInt())).thenReturn(true);
when(mWifiNative.setupInterface(any(), any())).thenReturn(IFACE_NAME_P2P);
when(mWifiNative.p2pGetDeviceAddress()).thenReturn(thisDeviceMac);
doAnswer(new AnswerWithArguments() {
@@ -1688,6 +1693,27 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
}
/**
+ * Verify that respond with DELETE_PERSISTENT_GROUP_FAILED
+ * when caller sends DELETE_PERSISTENT_GROUP and doesn't have the necessary permissions.
+ */
+ @Test
+ public void testDeletePersistentGroupFailureWhenNoPermissions() throws Exception {
+ // Move to enabled state
+ forceP2pEnabled(mClient1);
+
+ // no permissions held
+ when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(false);
+ when(mWifiPermissionsUtil.checkNetworkStackPermission(anyInt())).thenReturn(false);
+ when(mWifiPermissionsUtil.checkConfigOverridePermission(anyInt())).thenReturn(false);
+
+ sendDeletePersistentGroupMsg(mClientMessenger, WifiP2pGroup.PERSISTENT_NET_ID);
+ verify(mClientHandler).sendMessage(mMessageCaptor.capture());
+ Message message = mMessageCaptor.getValue();
+ assertEquals(WifiP2pManager.DELETE_PERSISTENT_GROUP_FAILED, message.what);
+ assertEquals(WifiP2pManager.ERROR, message.arg1);
+ }
+
+ /**
* Verify the peer scan counter is increased while receiving WifiP2pManager.DISCOVER_PEERS at
* P2pEnabledState.
*/
@@ -2445,6 +2471,29 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
}
/**
+ * Verify WifiP2pManager.SET_CHANNEL_FAILED is returned when no permissions are held.
+ */
+ @Test
+ public void testSetChannelFailureWhenNoPermissions() throws Exception {
+ // Move to enabled state
+ forceP2pEnabled(mClient1);
+
+ // no permissions held
+ when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(false);
+ when(mWifiPermissionsUtil.checkNetworkStackPermission(anyInt())).thenReturn(false);
+ when(mWifiPermissionsUtil.checkConfigOverridePermission(anyInt())).thenReturn(false);
+
+ Bundle p2pChannels = new Bundle();
+ p2pChannels.putInt("lc", 1);
+ p2pChannels.putInt("oc", 2);
+ sendSetChannelMsg(mClientMessenger, p2pChannels);
+ verify(mClientHandler).sendMessage(mMessageCaptor.capture());
+ Message message = mMessageCaptor.getValue();
+ assertEquals(WifiP2pManager.SET_CHANNEL_FAILED, message.what);
+ assertEquals(WifiP2pManager.ERROR, message.arg1);
+ }
+
+ /**
* Verify p2pSetChannel doesn't been called when message contain null object.
*/
@Test
@@ -2684,7 +2733,7 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
}
/**
- * Verify WifiP2pManager.SET_DEVICE_NAME_FAILED is returned when p2p device is null.
+ * Verify WifiP2pManager.SET_DEVICE_NAME_FAILED is returned when native call failed.
*/
@Test
public void testSetDeviceNameFailureWhenNativeCallFailure() throws Exception {
@@ -2757,6 +2806,26 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
}
/**
+ * Verify WifiP2pManager.SET_DEVICE_NAME_FAILED is returned when no permissions are held.
+ */
+ @Test
+ public void testSetDeviceNameFailureWhenNoPermissions() throws Exception {
+ // Move to enabled state
+ forceP2pEnabled(mClient1);
+
+ // no permissions held
+ when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(false);
+ when(mWifiPermissionsUtil.checkNetworkStackPermission(anyInt())).thenReturn(false);
+ when(mWifiPermissionsUtil.checkConfigOverridePermission(anyInt())).thenReturn(false);
+
+ sendSetDeviceNameMsg(mClientMessenger, null);
+ verify(mClientHandler).sendMessage(mMessageCaptor.capture());
+ Message message = mMessageCaptor.getValue();
+ assertEquals(WifiP2pManager.SET_DEVICE_NAME_FAILED, message.what);
+ assertEquals(WifiP2pManager.ERROR, message.arg1);
+ }
+
+ /**
* Verify the caller sends WifiP2pManager.SET_WFD_INFO with wfd enabled.
*/
@Test
@@ -3371,6 +3440,32 @@ public class WifiP2pServiceImplTest extends WifiBaseTest {
}
/**
+ * Verify that when no permissions are held, an empty {@link WifiP2pGroupList} is returned.
+ */
+ @Test
+ public void testRequestPersistentGroupInfoNoPermissionFailure() throws Exception {
+ // Ensure our own MAC address is not anonymized in the result
+ when(mWifiPermissionsUtil.checkLocalMacAddressPermission(anyInt())).thenReturn(true);
+ forceP2pEnabled(mClient1);
+
+ // no permissions held
+ when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(false);
+ when(mWifiPermissionsUtil.checkNetworkStackPermission(anyInt())).thenReturn(false);
+ when(mWifiPermissionsUtil.checkReadWifiCredentialPermission(anyInt())).thenReturn(false);
+
+ sendSimpleMsg(mClientMessenger, WifiP2pManager.REQUEST_PERSISTENT_GROUP_INFO);
+
+ verify(mClientHandler).sendMessage(mMessageCaptor.capture());
+ Message message = mMessageCaptor.getValue();
+ WifiP2pGroupList groups = (WifiP2pGroupList) message.obj;
+ assertEquals(WifiP2pManager.RESPONSE_PERSISTENT_GROUP_INFO, message.what);
+ // WifiP2pGroupList does not implement equals operator,
+ // use toString to compare two lists.
+ // Expect empty WifiP2pGroupList()
+ assertEquals(new WifiP2pGroupList().toString(), groups.toString());
+ }
+
+ /**
* Verify that respond with RESPONSE_CONNECTION_INFO
* when caller sends REQUEST_CONNECTION_INFO.
*/