Merge "Verify that the underlying network info will be cleared/sent or not"
This commit is contained in:
@@ -1268,6 +1268,23 @@ public class VpnTest extends VpnTestBase {
|
|||||||
intent.getIntExtra(VpnManager.EXTRA_ERROR_CLASS, -1 /* defaultValue */));
|
intent.getIntExtra(VpnManager.EXTRA_ERROR_CLASS, -1 /* defaultValue */));
|
||||||
assertEquals(errorCode,
|
assertEquals(errorCode,
|
||||||
intent.getIntExtra(VpnManager.EXTRA_ERROR_CODE, -1 /* defaultValue */));
|
intent.getIntExtra(VpnManager.EXTRA_ERROR_CODE, -1 /* defaultValue */));
|
||||||
|
// CATEGORY_EVENT_DEACTIVATED_BY_USER & CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED won't
|
||||||
|
// send NetworkCapabilities & LinkProperties to VPN app.
|
||||||
|
// For ERROR_CODE_NETWORK_LOST, the NetworkCapabilities & LinkProperties of underlying
|
||||||
|
// network will be cleared. So the VPN app will receive null for those 2 extra values.
|
||||||
|
if (category.equals(VpnManager.CATEGORY_EVENT_DEACTIVATED_BY_USER)
|
||||||
|
|| category.equals(VpnManager.CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED)
|
||||||
|
|| errorCode == VpnManager.ERROR_CODE_NETWORK_LOST) {
|
||||||
|
assertNull(intent.getParcelableExtra(
|
||||||
|
VpnManager.EXTRA_UNDERLYING_NETWORK_CAPABILITIES));
|
||||||
|
assertNull(intent.getParcelableExtra(VpnManager.EXTRA_UNDERLYING_LINK_PROPERTIES));
|
||||||
|
} else {
|
||||||
|
assertNotNull(intent.getParcelableExtra(
|
||||||
|
VpnManager.EXTRA_UNDERLYING_NETWORK_CAPABILITIES));
|
||||||
|
assertNotNull(intent.getParcelableExtra(
|
||||||
|
VpnManager.EXTRA_UNDERLYING_LINK_PROPERTIES));
|
||||||
|
}
|
||||||
|
|
||||||
if (profileState != null) {
|
if (profileState != null) {
|
||||||
assertEquals(profileState[i], intent.getParcelableExtra(
|
assertEquals(profileState[i], intent.getParcelableExtra(
|
||||||
VpnManager.EXTRA_VPN_PROFILE_STATE, VpnProfileState.class));
|
VpnManager.EXTRA_VPN_PROFILE_STATE, VpnProfileState.class));
|
||||||
@@ -1470,6 +1487,12 @@ public class VpnTest extends VpnTestBase {
|
|||||||
when(mNetd.interfaceGetCfg(anyString())).thenReturn(config);
|
when(mNetd.interfaceGetCfg(anyString())).thenReturn(config);
|
||||||
final NetworkCallback cb = networkCallbackCaptor.getValue();
|
final NetworkCallback cb = networkCallbackCaptor.getValue();
|
||||||
cb.onAvailable(TEST_NETWORK);
|
cb.onAvailable(TEST_NETWORK);
|
||||||
|
// Trigger onCapabilitiesChanged() and onLinkPropertiesChanged() so the test can verify that
|
||||||
|
// if NetworkCapabilities and LinkProperties of underlying network will be sent/cleared or
|
||||||
|
// not.
|
||||||
|
// See verifyVpnManagerEvent().
|
||||||
|
cb.onCapabilitiesChanged(TEST_NETWORK, new NetworkCapabilities());
|
||||||
|
cb.onLinkPropertiesChanged(TEST_NETWORK, new LinkProperties());
|
||||||
return cb;
|
return cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1488,6 +1511,11 @@ public class VpnTest extends VpnTestBase {
|
|||||||
when(mVpnProfileStore.get(vpn.getProfileNameForPackage(TEST_VPN_PKG)))
|
when(mVpnProfileStore.get(vpn.getProfileNameForPackage(TEST_VPN_PKG)))
|
||||||
.thenReturn(mVpnProfile.encode());
|
.thenReturn(mVpnProfile.encode());
|
||||||
|
|
||||||
|
doReturn(new NetworkCapabilities()).when(mConnectivityManager)
|
||||||
|
.getRedactedNetworkCapabilitiesForPackage(any(), anyInt(), anyString());
|
||||||
|
doReturn(new LinkProperties()).when(mConnectivityManager)
|
||||||
|
.getRedactedLinkPropertiesForPackage(any(), anyInt(), anyString());
|
||||||
|
|
||||||
final String sessionKey = vpn.startVpnProfile(TEST_VPN_PKG);
|
final String sessionKey = vpn.startVpnProfile(TEST_VPN_PKG);
|
||||||
final NetworkCallback cb = triggerOnAvailableAndGetCallback();
|
final NetworkCallback cb = triggerOnAvailableAndGetCallback();
|
||||||
|
|
||||||
@@ -1518,18 +1546,18 @@ public class VpnTest extends VpnTestBase {
|
|||||||
if (errorType == VpnManager.ERROR_CLASS_NOT_RECOVERABLE) {
|
if (errorType == VpnManager.ERROR_CLASS_NOT_RECOVERABLE) {
|
||||||
verify(mConnectivityManager, timeout(TEST_TIMEOUT_MS))
|
verify(mConnectivityManager, timeout(TEST_TIMEOUT_MS))
|
||||||
.unregisterNetworkCallback(eq(cb));
|
.unregisterNetworkCallback(eq(cb));
|
||||||
} else if (errorType == VpnManager.ERROR_CLASS_RECOVERABLE) {
|
} else if (errorType == VpnManager.ERROR_CLASS_RECOVERABLE
|
||||||
|
// Vpn won't retry when there is no usable underlying network.
|
||||||
|
&& errorCode != VpnManager.ERROR_CODE_NETWORK_LOST) {
|
||||||
int retryIndex = 0;
|
int retryIndex = 0;
|
||||||
final IkeSessionCallback ikeCb2 = verifyRetryAndGetNewIkeCb(retryIndex++, errorCode);
|
final IkeSessionCallback ikeCb2 = verifyRetryAndGetNewIkeCb(retryIndex++);
|
||||||
|
|
||||||
if (ikeCb2 != null) {
|
ikeCb2.onClosedWithException(exception);
|
||||||
ikeCb2.onClosedWithException(exception);
|
verifyRetryAndGetNewIkeCb(retryIndex++);
|
||||||
verifyRetryAndGetNewIkeCb(retryIndex++, errorCode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IkeSessionCallback verifyRetryAndGetNewIkeCb(int retryIndex, int errorCode) {
|
private IkeSessionCallback verifyRetryAndGetNewIkeCb(int retryIndex) {
|
||||||
final ArgumentCaptor<Runnable> runnableCaptor =
|
final ArgumentCaptor<Runnable> runnableCaptor =
|
||||||
ArgumentCaptor.forClass(Runnable.class);
|
ArgumentCaptor.forClass(Runnable.class);
|
||||||
final ArgumentCaptor<IkeSessionCallback> ikeCbCaptor =
|
final ArgumentCaptor<IkeSessionCallback> ikeCbCaptor =
|
||||||
@@ -1542,21 +1570,15 @@ public class VpnTest extends VpnTestBase {
|
|||||||
// Mock the event of firing the retry task
|
// Mock the event of firing the retry task
|
||||||
runnableCaptor.getValue().run();
|
runnableCaptor.getValue().run();
|
||||||
|
|
||||||
// Vpn won't retry when there is no usable underlying network.
|
verify(mIkev2SessionCreator)
|
||||||
if (errorCode == VpnManager.ERROR_CODE_NETWORK_LOST) {
|
.createIkeSession(any(), any(), any(), any(), ikeCbCaptor.capture(), any());
|
||||||
verify(mIkev2SessionCreator, never())
|
|
||||||
.createIkeSession(any(), any(), any(), any(), ikeCbCaptor.capture(), any());
|
|
||||||
} else {
|
|
||||||
verify(mIkev2SessionCreator)
|
|
||||||
.createIkeSession(any(), any(), any(), any(), ikeCbCaptor.capture(), any());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Forget the mIkev2SessionCreator#createIkeSession call and mExecutor#schedule call
|
// Forget the mIkev2SessionCreator#createIkeSession call and mExecutor#schedule call
|
||||||
// for the next retry verification
|
// for the next retry verification
|
||||||
resetIkev2SessionCreator(mIkeSessionWrapper);
|
resetIkev2SessionCreator(mIkeSessionWrapper);
|
||||||
resetExecutor(mScheduledFuture);
|
resetExecutor(mScheduledFuture);
|
||||||
|
|
||||||
return (ikeCbCaptor.getAllValues().size() == 0) ? null : ikeCbCaptor.getValue();
|
return ikeCbCaptor.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user