Decouple security exception check test from ConnectivityServiceTest

Decouple security exception check test from ConnectivityServiceTest
to VpnManagerServiceTest.

These security exception tests landed in ConnectivityServiceTest
because of no VpnManagerServiceTest. Move the tests to the
VpnManagerServiceTest where is better place to put the VPN related
tests to reduce the size of ConnectivityServiceTest.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: I94b691c4d1f63bd5226e3296e6d0160dcb03107c
This commit is contained in:
chiachangwang
2022-06-21 10:57:44 +00:00
parent 7f5d04962b
commit 1aef309197
2 changed files with 14 additions and 13 deletions

View File

@@ -10632,19 +10632,6 @@ public class ConnectivityServiceTest {
assertContainsExactly(uidCaptor.getValue(), APP1_UID, APP2_UID);
}
@Test
public void testStartVpnProfileFromDiffPackage() throws Exception {
final String notMyVpnPkg = "com.not.my.vpn";
assertThrows(
SecurityException.class, () -> mVpnManagerService.startVpnProfile(notMyVpnPkg));
}
@Test
public void testStopVpnProfileFromDiffPackage() throws Exception {
final String notMyVpnPkg = "com.not.my.vpn";
assertThrows(SecurityException.class, () -> mVpnManagerService.stopVpnProfile(notMyVpnPkg));
}
@Test
public void testUidUpdateChangesInterfaceFilteringRule() throws Exception {
LinkProperties lp = new LinkProperties();

View File

@@ -20,6 +20,7 @@ import static android.os.Build.VERSION_CODES.R;
import static com.android.testutils.ContextUtils.mockService;
import static com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo;
import static com.android.testutils.MiscAsserts.assertThrows;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
@@ -75,6 +76,8 @@ public class VpnManagerServiceTest extends VpnTestBase {
private VpnManagerServiceDependencies mDeps;
private VpnManagerService mService;
private final String mNotMyVpnPkg = "com.not.my.vpn";
class VpnManagerServiceDependencies extends VpnManagerService.Dependencies {
@Override
public HandlerThread makeHandlerThread() {
@@ -146,4 +149,15 @@ public class VpnManagerServiceTest extends VpnTestBase {
mService.onPackageAdded(PKGS[0], PKG_UIDS[0], false /* isReplacing */);
verify(mVpn, times(2)).refreshPlatformVpnAppExclusionList();
}
@Test
public void testStartVpnProfileFromDiffPackage() {
assertThrows(
SecurityException.class, () -> mService.startVpnProfile(mNotMyVpnPkg));
}
@Test
public void testStopVpnProfileFromDiffPackage() {
assertThrows(SecurityException.class, () -> mService.stopVpnProfile(mNotMyVpnPkg));
}
}