Update VpnTest for new restricted API
This patch addressses the mocked UserManager for the context of the user which is created by createContextAsUser. Bug: 171529940 Bug: 175883995 Test: FrameworksNetTests Change-Id: Ie72d08c765ed7fb7083c0c4b7ee02a43c23d1707
This commit is contained in:
@@ -253,12 +253,14 @@ public class VpnTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestrictedProfilesAreAddedToVpn() {
|
public void testRestrictedProfilesAreAddedToVpn() {
|
||||||
if (true) return; // TODO(b/175883995): Test disabled until updated for new UserManager API.
|
|
||||||
setMockedUsers(primaryUser, secondaryUser, restrictedProfileA, restrictedProfileB);
|
setMockedUsers(primaryUser, secondaryUser, restrictedProfileA, restrictedProfileB);
|
||||||
|
|
||||||
final Vpn vpn = createVpn(primaryUser.id);
|
final Vpn vpn = createVpn(primaryUser.id);
|
||||||
final Set<UidRange> ranges = vpn.createUserAndRestrictedProfilesRanges(primaryUser.id,
|
|
||||||
null, null);
|
// Assume the user can have restricted profiles.
|
||||||
|
doReturn(true).when(mUserManager).canHaveRestrictedProfile();
|
||||||
|
final Set<UidRange> ranges =
|
||||||
|
vpn.createUserAndRestrictedProfilesRanges(primaryUser.id, null, null);
|
||||||
|
|
||||||
assertEquals(new ArraySet<>(Arrays.asList(new UidRange[] {
|
assertEquals(new ArraySet<>(Arrays.asList(new UidRange[] {
|
||||||
PRI_USER_RANGE, UidRange.createForUser(restrictedProfileA.id)
|
PRI_USER_RANGE, UidRange.createForUser(restrictedProfileA.id)
|
||||||
@@ -267,7 +269,6 @@ public class VpnTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testManagedProfilesAreNotAddedToVpn() {
|
public void testManagedProfilesAreNotAddedToVpn() {
|
||||||
if (true) return; // TODO(b/175883995): Test disabled until updated for new UserManager API.
|
|
||||||
setMockedUsers(primaryUser, managedProfileA);
|
setMockedUsers(primaryUser, managedProfileA);
|
||||||
|
|
||||||
final Vpn vpn = createVpn(primaryUser.id);
|
final Vpn vpn = createVpn(primaryUser.id);
|
||||||
@@ -290,7 +291,6 @@ public class VpnTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUidAllowAndDenylist() throws Exception {
|
public void testUidAllowAndDenylist() throws Exception {
|
||||||
if (true) return; // TODO(b/175883995): Test disabled until updated for new UserManager API.
|
|
||||||
final Vpn vpn = createVpn(primaryUser.id);
|
final Vpn vpn = createVpn(primaryUser.id);
|
||||||
final UidRange user = PRI_USER_RANGE;
|
final UidRange user = PRI_USER_RANGE;
|
||||||
final String[] packages = {PKGS[0], PKGS[1], PKGS[2]};
|
final String[] packages = {PKGS[0], PKGS[1], PKGS[2]};
|
||||||
@@ -316,7 +316,6 @@ public class VpnTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAlwaysAndOnGetLockDown() throws Exception {
|
public void testGetAlwaysAndOnGetLockDown() throws Exception {
|
||||||
if (true) return; // TODO(b/175883995): Test disabled until updated for new UserManager API.
|
|
||||||
final Vpn vpn = createVpn(primaryUser.id);
|
final Vpn vpn = createVpn(primaryUser.id);
|
||||||
|
|
||||||
// Default state.
|
// Default state.
|
||||||
@@ -341,7 +340,6 @@ public class VpnTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLockdownChangingPackage() throws Exception {
|
public void testLockdownChangingPackage() throws Exception {
|
||||||
if (true) return; // TODO(b/175883995): Test disabled until updated for new UserManager API.
|
|
||||||
final Vpn vpn = createVpn(primaryUser.id);
|
final Vpn vpn = createVpn(primaryUser.id);
|
||||||
final UidRange user = PRI_USER_RANGE;
|
final UidRange user = PRI_USER_RANGE;
|
||||||
|
|
||||||
@@ -369,7 +367,6 @@ public class VpnTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLockdownAllowlist() throws Exception {
|
public void testLockdownAllowlist() throws Exception {
|
||||||
if (true) return; // TODO(b/175883995): Test disabled until updated for new UserManager API.
|
|
||||||
final Vpn vpn = createVpn(primaryUser.id);
|
final Vpn vpn = createVpn(primaryUser.id);
|
||||||
final UidRange user = PRI_USER_RANGE;
|
final UidRange user = PRI_USER_RANGE;
|
||||||
|
|
||||||
@@ -444,7 +441,6 @@ public class VpnTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLockdownRuleRepeatability() throws Exception {
|
public void testLockdownRuleRepeatability() throws Exception {
|
||||||
if (true) return; // TODO(b/175883995): Test disabled until updated for new UserManager API.
|
|
||||||
final Vpn vpn = createVpn(primaryUser.id);
|
final Vpn vpn = createVpn(primaryUser.id);
|
||||||
final UidRangeParcel[] primaryUserRangeParcel = new UidRangeParcel[] {
|
final UidRangeParcel[] primaryUserRangeParcel = new UidRangeParcel[] {
|
||||||
new UidRangeParcel(PRI_USER_RANGE.start, PRI_USER_RANGE.stop)};
|
new UidRangeParcel(PRI_USER_RANGE.start, PRI_USER_RANGE.stop)};
|
||||||
@@ -477,7 +473,6 @@ public class VpnTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLockdownRuleReversibility() throws Exception {
|
public void testLockdownRuleReversibility() throws Exception {
|
||||||
if (true) return; // TODO(b/175883995): Test disabled until updated for new UserManager API.
|
|
||||||
final Vpn vpn = createVpn(primaryUser.id);
|
final Vpn vpn = createVpn(primaryUser.id);
|
||||||
final UidRangeParcel[] entireUser = {
|
final UidRangeParcel[] entireUser = {
|
||||||
new UidRangeParcel(PRI_USER_RANGE.start, PRI_USER_RANGE.stop)
|
new UidRangeParcel(PRI_USER_RANGE.start, PRI_USER_RANGE.stop)
|
||||||
@@ -1144,6 +1139,10 @@ public class VpnTest {
|
|||||||
doReturn(UserHandle.of(userId)).when(asUserContext).getUser();
|
doReturn(UserHandle.of(userId)).when(asUserContext).getUser();
|
||||||
when(mContext.createContextAsUser(eq(UserHandle.of(userId)), anyInt()))
|
when(mContext.createContextAsUser(eq(UserHandle.of(userId)), anyInt()))
|
||||||
.thenReturn(asUserContext);
|
.thenReturn(asUserContext);
|
||||||
|
when(asUserContext.getSystemServiceName(UserManager.class))
|
||||||
|
.thenReturn(Context.USER_SERVICE);
|
||||||
|
when(asUserContext.getSystemService(UserManager.class))
|
||||||
|
.thenReturn(mUserManager);
|
||||||
final TestLooper testLooper = new TestLooper();
|
final TestLooper testLooper = new TestLooper();
|
||||||
final Vpn vpn = new Vpn(testLooper.getLooper(), mContext, new TestDeps(), mNetService,
|
final Vpn vpn = new Vpn(testLooper.getLooper(), mContext, new TestDeps(), mNetService,
|
||||||
mNetd, userId, mKeyStore, mSystemServices, mIkev2SessionCreator);
|
mNetd, userId, mKeyStore, mSystemServices, mIkev2SessionCreator);
|
||||||
@@ -1179,11 +1178,6 @@ public class VpnTest {
|
|||||||
final int id = (int) invocation.getArguments()[0];
|
final int id = (int) invocation.getArguments()[0];
|
||||||
return userMap.get(id);
|
return userMap.get(id);
|
||||||
}).when(mUserManager).getUserInfo(anyInt());
|
}).when(mUserManager).getUserInfo(anyInt());
|
||||||
|
|
||||||
doAnswer(invocation -> {
|
|
||||||
final int id = (int) invocation.getArguments()[0];
|
|
||||||
return (userMap.get(id).flags & UserInfo.FLAG_ADMIN) != 0;
|
|
||||||
}).when(mUserManager).canHaveRestrictedProfile();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user