-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RESTRICT AUTOMERGE Fix to restrict admin from granting permission to …
…a sensor permission group Bug: 308138085 Test: atest PermissionControllerMockingTests:AdminRestrictedPermissionsUtilsTest LOW_COVERAGE_REASON=b/330904893 Relnote: Security bug fix to restrict admin from granting permission to a sensor permission group (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:cee0dab747af4563998f6225f120db4f318843f1) Merged-In: Id9f7b9e1d73deec867ee87d0bde9a0868dd440f2 Change-Id: Id9f7b9e1d73deec867ee87d0bde9a0868dd440f2
- Loading branch information
Showing
4 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...ermissioncontroller/tests/mocking/permission/utils/AdminRestrictedPermissionsUtilsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (C) 2024 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.android.permissioncontroller.tests.mocking.permission.utils | ||
|
||
import android.platform.test.annotations.AsbSecurityTest | ||
import com.android.modules.utils.build.SdkLevel | ||
import com.android.permissioncontroller.permission.utils.AdminRestrictedPermissionsUtils | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assume | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
import org.mockito.Mockito.mock | ||
|
||
@RunWith(Parameterized::class) | ||
class AdminRestrictedPermissionsUtilsTest( | ||
private val permission: String, | ||
private val group: String?, | ||
private val canAdminGrantSensorsPermissions: Boolean, | ||
private val expected: Boolean | ||
) { | ||
@Before | ||
fun setup() { | ||
Assume.assumeTrue(SdkLevel.isAtLeastS()) | ||
} | ||
|
||
@AsbSecurityTest(cveBugId = [308138085]) | ||
@Test | ||
fun mayAdminGrantPermissionTest() { | ||
val canGrant = | ||
AdminRestrictedPermissionsUtils.mayAdminGrantPermission( | ||
permission, | ||
group, | ||
canAdminGrantSensorsPermissions, | ||
false | ||
) | ||
assertEquals(expected, canGrant) | ||
} | ||
|
||
companion object { | ||
/** | ||
* Returns a list of arrays containing the following values: | ||
* | ||
* 0. Permission name (String) | ||
* 1. Permission group name (String) | ||
* 2. Can admin grant sensors permissions (Boolean) | ||
* 3. Expected return from mayAdminGrantPermission method (Boolean) | ||
*/ | ||
@JvmStatic | ||
@Parameterized.Parameters(name = "{index}: validate({0}, {1}, {3}) = {4}") | ||
fun getParameters(): List<Array<out Any?>> { | ||
return listOf( | ||
arrayOf("abc", "xyz", false, true), | ||
arrayOf("abc", null, false, true), | ||
arrayOf("android.permission.RECORD_AUDIO", "xyz", false, false), | ||
arrayOf("abc", "android.permission-group.MICROPHONE", false, false), | ||
arrayOf( | ||
"android.permission.RECORD_AUDIO", | ||
"android.permission-group.MICROPHONE", | ||
false, | ||
false | ||
), | ||
arrayOf( | ||
"android.permission.RECORD_AUDIO", | ||
"android.permission-group.MICROPHONE", | ||
true, | ||
true | ||
), | ||
) | ||
} | ||
} | ||
} |