diff options
author | David Su <dysu@google.com> | 2019-10-23 23:41:19 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-10-23 23:41:19 +0000 |
commit | 65c0f2bdef15ce2c7e370d55cc304799bb860323 (patch) | |
tree | 4b156df88b492d3d97054602b199d6b7470ee2f6 /tests | |
parent | 1c37a9bce91dcf7d522a713cb05bc0dd9777aab7 (diff) | |
parent | 0a40731214c56cf604170e4db70c7fb6424f6995 (diff) |
Merge "Enforce permissions check for WifiScanner#getAvailableChannels()"
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java index c61ceb4a9..ea1fb51d5 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java @@ -18,6 +18,7 @@ package com.android.server.wifi.scanner; import static android.content.pm.PackageManager.PERMISSION_DENIED; import static android.content.pm.PackageManager.PERMISSION_GRANTED; +import static android.net.wifi.WifiScanner.GET_AVAILABLE_CHANNELS_EXTRA; import static com.android.server.wifi.ScanTestUtil.NativeScanSettingsBuilder; import static com.android.server.wifi.ScanTestUtil.assertNativePnoSettingsEquals; @@ -3490,4 +3491,51 @@ public class WifiScanningServiceTest extends WifiBaseTest { verifyPnoNetworkFoundReceived(order, handler, requestId, scanResults.getRawScanResults()); } + + /** + * Tests that {@link WifiScanningServiceImpl#getAvailableChannels(int, String)} throws a + * {@link SecurityException} if the caller doesn't hold the required permissions. + */ + @Test(expected = SecurityException.class) + public void getAvailableChannels_noPermission_throwsException() throws Exception { + startServiceAndLoadDriver(); + + // no MAINLINE_WIFI_STACK permission + doThrow(new SecurityException()).when(mContext).enforcePermission( + eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), anyInt(), + eq(Binder.getCallingUid()), any()); + + // Location permission or mode check fail. + doThrow(new SecurityException()) + .when(mWifiPermissionsUtil).enforceCanAccessScanResultsForWifiScanner( + TEST_PACKAGE_NAME, Binder.getCallingUid(), false, false); + + mWifiScanningServiceImpl.getAvailableChannels(WifiScanner.WIFI_BAND_24_GHZ, + TEST_PACKAGE_NAME); + } + + /** + * Tests that {@link WifiScanningServiceImpl#getAvailableChannels(int, String)} returns + * the expected result if the caller does hold the required permissions. + */ + @Test + public void getAvailableChannels_hasPermission_returnsSuccessfully() throws Exception { + startServiceAndLoadDriver(); + + // has MAINLINE_WIFI_STACK permission + doNothing().when(mContext).enforcePermission( + eq(WifiStackClient.PERMISSION_MAINLINE_WIFI_STACK), anyInt(), + eq(Binder.getCallingUid()), any()); + + // has access scan results permission + doNothing().when(mWifiPermissionsUtil).enforceCanAccessScanResultsForWifiScanner( + TEST_PACKAGE_NAME, Binder.getCallingUid(), false, false); + + Bundle bundle = mWifiScanningServiceImpl.getAvailableChannels( + WifiScanner.WIFI_BAND_24_GHZ, TEST_PACKAGE_NAME); + List<Integer> actual = bundle.getIntegerArrayList(GET_AVAILABLE_CHANNELS_EXTRA); + + List<Integer> expected = Arrays.asList(2400, 2450); + assertEquals(expected, actual); + } } |