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