Merge "Skip DevicePolicyManagerTest that are not supported on automotive." into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
26492d0725
@@ -51,6 +51,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static com.google.common.truth.Truth.assertWithMessage;
|
import static com.google.common.truth.Truth.assertWithMessage;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.junit.Assume.assumeTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyBoolean;
|
import static org.mockito.Matchers.anyBoolean;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
@@ -184,6 +185,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
public DevicePolicyManager parentDpm;
|
public DevicePolicyManager parentDpm;
|
||||||
public DevicePolicyManagerServiceTestable dpms;
|
public DevicePolicyManagerServiceTestable dpms;
|
||||||
|
|
||||||
|
private boolean mIsAutomotive;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The CA cert below is the content of cacert.pem as generated by:
|
* The CA cert below is the content of cacert.pem as generated by:
|
||||||
*
|
*
|
||||||
@@ -266,6 +269,9 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
setUpUserManager();
|
setUpUserManager();
|
||||||
|
|
||||||
when(getServices().lockPatternUtils.hasSecureLockScreen()).thenReturn(true);
|
when(getServices().lockPatternUtils.hasSecureLockScreen()).thenReturn(true);
|
||||||
|
|
||||||
|
mIsAutomotive = mContext.getPackageManager()
|
||||||
|
.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TransferOwnershipMetadataManager getMockTransferMetadataManager() {
|
private TransferOwnershipMetadataManager getMockTransferMetadataManager() {
|
||||||
@@ -2117,10 +2123,13 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
assertThat(dpm.getPasswordExpirationTimeout(admin1))
|
assertThat(dpm.getPasswordExpirationTimeout(admin1))
|
||||||
.isEqualTo(originalPasswordExpirationTimeout);
|
.isEqualTo(originalPasswordExpirationTimeout);
|
||||||
|
|
||||||
int originalPasswordQuality = dpm.getPasswordQuality(admin1);
|
if (isDeprecatedPasswordApisSupported()) {
|
||||||
assertExpectException(SecurityException.class, /* messageRegex= */ null,
|
int originalPasswordQuality = dpm.getPasswordQuality(admin1);
|
||||||
() -> dpm.setPasswordQuality(admin1, DevicePolicyManager.PASSWORD_QUALITY_NUMERIC));
|
assertExpectException(SecurityException.class, /* messageRegex= */ null,
|
||||||
assertThat(dpm.getPasswordQuality(admin1)).isEqualTo(originalPasswordQuality);
|
() -> dpm.setPasswordQuality(admin1,
|
||||||
|
DevicePolicyManager.PASSWORD_QUALITY_NUMERIC));
|
||||||
|
assertThat(dpm.getPasswordQuality(admin1)).isEqualTo(originalPasswordQuality);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -5231,6 +5240,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsActivePasswordSufficient() throws Exception {
|
public void testIsActivePasswordSufficient() throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
|
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
|
||||||
mContext.packageName = admin1.getPackageName();
|
mContext.packageName = admin1.getPackageName();
|
||||||
setupDeviceOwner();
|
setupDeviceOwner();
|
||||||
@@ -5283,6 +5294,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsActivePasswordSufficient_noLockScreen() throws Exception {
|
public void testIsActivePasswordSufficient_noLockScreen() throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
// If there is no lock screen, the password is considered empty no matter what, because
|
// If there is no lock screen, the password is considered empty no matter what, because
|
||||||
// it provides no security.
|
// it provides no security.
|
||||||
when(getServices().lockPatternUtils.hasSecureLockScreen()).thenReturn(false);
|
when(getServices().lockPatternUtils.hasSecureLockScreen()).thenReturn(false);
|
||||||
@@ -5363,6 +5376,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
@Test
|
@Test
|
||||||
public void testGetAggregatedPasswordMetrics_IgnoreProfileRequirement()
|
public void testGetAggregatedPasswordMetrics_IgnoreProfileRequirement()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
final int managedProfileUserId = CALLER_USER_HANDLE;
|
final int managedProfileUserId = CALLER_USER_HANDLE;
|
||||||
final int managedProfileAdminUid =
|
final int managedProfileAdminUid =
|
||||||
UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
|
UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
|
||||||
@@ -5392,6 +5407,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCanSetPasswordRequirementOnParentPreS() throws Exception {
|
public void testCanSetPasswordRequirementOnParentPreS() throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
final int managedProfileUserId = CALLER_USER_HANDLE;
|
final int managedProfileUserId = CALLER_USER_HANDLE;
|
||||||
final int managedProfileAdminUid =
|
final int managedProfileAdminUid =
|
||||||
UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
|
UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
|
||||||
@@ -5407,6 +5424,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCannotSetPasswordRequirementOnParent() throws Exception {
|
public void testCannotSetPasswordRequirementOnParent() throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
final int managedProfileUserId = CALLER_USER_HANDLE;
|
final int managedProfileUserId = CALLER_USER_HANDLE;
|
||||||
final int managedProfileAdminUid =
|
final int managedProfileAdminUid =
|
||||||
UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
|
UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
|
||||||
@@ -5427,6 +5446,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
@Test
|
@Test
|
||||||
public void isActivePasswordSufficient_SeparateWorkChallenge_ProfileQualityRequirementMet()
|
public void isActivePasswordSufficient_SeparateWorkChallenge_ProfileQualityRequirementMet()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
// Create work profile with empty separate challenge
|
// Create work profile with empty separate challenge
|
||||||
final int managedProfileUserId = 15;
|
final int managedProfileUserId = 15;
|
||||||
final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
|
final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
|
||||||
@@ -5450,6 +5471,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
@Test
|
@Test
|
||||||
public void isActivePasswordSufficient_SeparateWorkChallenge_ProfileComplexityRequirementMet()
|
public void isActivePasswordSufficient_SeparateWorkChallenge_ProfileComplexityRequirementMet()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
// Create work profile with empty separate challenge
|
// Create work profile with empty separate challenge
|
||||||
final int managedProfileUserId = 15;
|
final int managedProfileUserId = 15;
|
||||||
final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
|
final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
|
||||||
@@ -5473,6 +5496,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
@Test
|
@Test
|
||||||
public void isActivePasswordSufficient_SeparateWorkChallenge_ParentQualityRequirementMet()
|
public void isActivePasswordSufficient_SeparateWorkChallenge_ParentQualityRequirementMet()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
// Create work profile with empty separate challenge
|
// Create work profile with empty separate challenge
|
||||||
final int managedProfileUserId = 15;
|
final int managedProfileUserId = 15;
|
||||||
final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
|
final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
|
||||||
@@ -5519,6 +5544,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
@Test
|
@Test
|
||||||
public void isActivePasswordSufficient_UnifiedWorkChallenge_ProfileQualityRequirementMet()
|
public void isActivePasswordSufficient_UnifiedWorkChallenge_ProfileQualityRequirementMet()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
// Create work profile with unified challenge
|
// Create work profile with unified challenge
|
||||||
final int managedProfileUserId = 15;
|
final int managedProfileUserId = 15;
|
||||||
final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
|
final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
|
||||||
@@ -5565,6 +5592,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
@Test
|
@Test
|
||||||
public void isActivePasswordSufficient_UnifiedWorkChallenge_ParentQualityRequirementMet()
|
public void isActivePasswordSufficient_UnifiedWorkChallenge_ParentQualityRequirementMet()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
// Create work profile with unified challenge
|
// Create work profile with unified challenge
|
||||||
final int managedProfileUserId = 15;
|
final int managedProfileUserId = 15;
|
||||||
final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
|
final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
|
||||||
@@ -5625,6 +5654,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPasswordQualityAppliesToParentPreS() throws Exception {
|
public void testPasswordQualityAppliesToParentPreS() throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
final int managedProfileUserId = CALLER_USER_HANDLE;
|
final int managedProfileUserId = CALLER_USER_HANDLE;
|
||||||
final int managedProfileAdminUid =
|
final int managedProfileAdminUid =
|
||||||
UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
|
UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
|
||||||
@@ -7285,6 +7316,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetRequiredPasswordComplexity_UnauthorizedCallersOnDO() throws Exception {
|
public void testSetRequiredPasswordComplexity_UnauthorizedCallersOnDO() throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
|
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
|
||||||
setupDeviceOwner();
|
setupDeviceOwner();
|
||||||
// DO must be able to set it.
|
// DO must be able to set it.
|
||||||
@@ -7300,6 +7333,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetRequiredPasswordComplexity_UnauthorizedCallersOnPO() throws Exception {
|
public void testSetRequiredPasswordComplexity_UnauthorizedCallersOnPO() throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
|
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
|
||||||
setupProfileOwner();
|
setupProfileOwner();
|
||||||
// PO must be able to set it.
|
// PO must be able to set it.
|
||||||
@@ -7314,6 +7349,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetRequiredPasswordComplexity_validValuesOnly() throws Exception {
|
public void testSetRequiredPasswordComplexity_validValuesOnly() throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
|
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
|
||||||
setupProfileOwner();
|
setupProfileOwner();
|
||||||
|
|
||||||
@@ -7335,6 +7372,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetRequiredPasswordComplexity_setAndGet() throws Exception {
|
public void testSetRequiredPasswordComplexity_setAndGet() throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
|
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
|
||||||
setupProfileOwner();
|
setupProfileOwner();
|
||||||
|
|
||||||
@@ -7348,6 +7387,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetRequiredPasswordComplexityOnParent_setAndGet() throws Exception {
|
public void testSetRequiredPasswordComplexityOnParent_setAndGet() throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
final int managedProfileUserId = 15;
|
final int managedProfileUserId = 15;
|
||||||
final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
|
final int managedProfileAdminUid = UserHandle.getUid(managedProfileUserId, 19436);
|
||||||
|
|
||||||
@@ -7366,6 +7407,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetRequiredPasswordComplexity_isSufficient() throws Exception {
|
public void testSetRequiredPasswordComplexity_isSufficient() throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
|
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
|
||||||
mContext.packageName = admin1.getPackageName();
|
mContext.packageName = admin1.getPackageName();
|
||||||
setupDeviceOwner();
|
setupDeviceOwner();
|
||||||
@@ -7395,6 +7438,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetRequiredPasswordComplexity_resetBySettingQuality() throws Exception {
|
public void testSetRequiredPasswordComplexity_resetBySettingQuality() throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
|
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
|
||||||
setupProfileOwner();
|
setupProfileOwner();
|
||||||
|
|
||||||
@@ -7407,6 +7452,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetRequiredPasswordComplexity_overridesQuality() throws Exception {
|
public void testSetRequiredPasswordComplexity_overridesQuality() throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
|
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
|
||||||
setupProfileOwner();
|
setupProfileOwner();
|
||||||
|
|
||||||
@@ -7421,6 +7468,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetRequiredPasswordComplexityFailsWithQualityOnParent() throws Exception {
|
public void testSetRequiredPasswordComplexityFailsWithQualityOnParent() throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
final int managedProfileUserId = CALLER_USER_HANDLE;
|
final int managedProfileUserId = CALLER_USER_HANDLE;
|
||||||
final int managedProfileAdminUid =
|
final int managedProfileAdminUid =
|
||||||
UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
|
UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
|
||||||
@@ -7435,6 +7484,8 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetQualityOnParentFailsWithComplexityOnProfile() throws Exception {
|
public void testSetQualityOnParentFailsWithComplexityOnProfile() throws Exception {
|
||||||
|
assumeDeprecatedPasswordApisSupported();
|
||||||
|
|
||||||
final int managedProfileUserId = CALLER_USER_HANDLE;
|
final int managedProfileUserId = CALLER_USER_HANDLE;
|
||||||
final int managedProfileAdminUid =
|
final int managedProfileAdminUid =
|
||||||
UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
|
UserHandle.getUid(managedProfileUserId, DpmMockContext.SYSTEM_UID);
|
||||||
@@ -8015,4 +8066,13 @@ public class DevicePolicyManagerTest extends DpmTestBase {
|
|||||||
when(mContext.getResources().getStringArray(R.array.vendor_policy_exempt_apps))
|
when(mContext.getResources().getStringArray(R.array.vendor_policy_exempt_apps))
|
||||||
.thenReturn(new String[0]);
|
.thenReturn(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isDeprecatedPasswordApisSupported() {
|
||||||
|
return !mIsAutomotive;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assumeDeprecatedPasswordApisSupported() {
|
||||||
|
assumeTrue("device doesn't support deprecated password APIs",
|
||||||
|
isDeprecatedPasswordApisSupported());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user