Merge "Test recoverable Ikev2 errors" am: 281390e58c
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2098818 Change-Id: Ib43845ab9fbc32defebbd8470193287ec79342f9 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -1315,7 +1315,7 @@ public class VpnTest {
|
|||||||
config -> Arrays.asList(config.flags).contains(flag)));
|
config -> Arrays.asList(config.flags).contains(flag)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupPlatformVpnWithSpecificExceptionAndItsErrorCode(IkeException exception,
|
private void doTestPlatformVpnWithException(IkeException exception,
|
||||||
String category, int errorType, int errorCode) throws Exception {
|
String category, int errorType, int errorCode) throws Exception {
|
||||||
final ArgumentCaptor<IkeSessionCallback> captor =
|
final ArgumentCaptor<IkeSessionCallback> captor =
|
||||||
ArgumentCaptor.forClass(IkeSessionCallback.class);
|
ArgumentCaptor.forClass(IkeSessionCallback.class);
|
||||||
@@ -1333,6 +1333,7 @@ public class VpnTest {
|
|||||||
// state
|
// state
|
||||||
verify(mIkev2SessionCreator, timeout(TEST_TIMEOUT_MS))
|
verify(mIkev2SessionCreator, timeout(TEST_TIMEOUT_MS))
|
||||||
.createIkeSession(any(), any(), any(), any(), captor.capture(), any());
|
.createIkeSession(any(), any(), any(), any(), captor.capture(), any());
|
||||||
|
reset(mIkev2SessionCreator);
|
||||||
final IkeSessionCallback ikeCb = captor.getValue();
|
final IkeSessionCallback ikeCb = captor.getValue();
|
||||||
ikeCb.onClosedWithException(exception);
|
ikeCb.onClosedWithException(exception);
|
||||||
|
|
||||||
@@ -1342,6 +1343,23 @@ public class VpnTest {
|
|||||||
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) {
|
||||||
|
// To prevent spending much time to test the retry function, only retry 2 times here.
|
||||||
|
int retryIndex = 0;
|
||||||
|
verify(mIkev2SessionCreator,
|
||||||
|
timeout(((TestDeps) vpn.mDeps).getNextRetryDelaySeconds(retryIndex++) * 1000
|
||||||
|
+ TEST_TIMEOUT_MS))
|
||||||
|
.createIkeSession(any(), any(), any(), any(), captor.capture(), any());
|
||||||
|
|
||||||
|
// Capture a new IkeSessionCallback to get the latest token.
|
||||||
|
reset(mIkev2SessionCreator);
|
||||||
|
final IkeSessionCallback ikeCb2 = captor.getValue();
|
||||||
|
ikeCb2.onClosedWithException(exception);
|
||||||
|
verify(mIkev2SessionCreator,
|
||||||
|
timeout(((TestDeps) vpn.mDeps).getNextRetryDelaySeconds(retryIndex++) * 1000
|
||||||
|
+ TEST_TIMEOUT_MS))
|
||||||
|
.createIkeSession(any(), any(), any(), any(), captor.capture(), any());
|
||||||
|
reset(mIkev2SessionCreator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1350,7 +1368,7 @@ public class VpnTest {
|
|||||||
final IkeProtocolException exception = mock(IkeProtocolException.class);
|
final IkeProtocolException exception = mock(IkeProtocolException.class);
|
||||||
final int errorCode = IkeProtocolException.ERROR_TYPE_AUTHENTICATION_FAILED;
|
final int errorCode = IkeProtocolException.ERROR_TYPE_AUTHENTICATION_FAILED;
|
||||||
when(exception.getErrorType()).thenReturn(errorCode);
|
when(exception.getErrorType()).thenReturn(errorCode);
|
||||||
setupPlatformVpnWithSpecificExceptionAndItsErrorCode(exception,
|
doTestPlatformVpnWithException(exception,
|
||||||
VpnManager.CATEGORY_EVENT_IKE_ERROR, VpnManager.ERROR_CLASS_NOT_RECOVERABLE,
|
VpnManager.CATEGORY_EVENT_IKE_ERROR, VpnManager.ERROR_CLASS_NOT_RECOVERABLE,
|
||||||
errorCode);
|
errorCode);
|
||||||
}
|
}
|
||||||
@@ -1360,7 +1378,7 @@ public class VpnTest {
|
|||||||
final IkeProtocolException exception = mock(IkeProtocolException.class);
|
final IkeProtocolException exception = mock(IkeProtocolException.class);
|
||||||
final int errorCode = IkeProtocolException.ERROR_TYPE_TEMPORARY_FAILURE;
|
final int errorCode = IkeProtocolException.ERROR_TYPE_TEMPORARY_FAILURE;
|
||||||
when(exception.getErrorType()).thenReturn(errorCode);
|
when(exception.getErrorType()).thenReturn(errorCode);
|
||||||
setupPlatformVpnWithSpecificExceptionAndItsErrorCode(exception,
|
doTestPlatformVpnWithException(exception,
|
||||||
VpnManager.CATEGORY_EVENT_IKE_ERROR, VpnManager.ERROR_CLASS_RECOVERABLE, errorCode);
|
VpnManager.CATEGORY_EVENT_IKE_ERROR, VpnManager.ERROR_CLASS_RECOVERABLE, errorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1370,7 +1388,7 @@ public class VpnTest {
|
|||||||
final UnknownHostException unknownHostException = new UnknownHostException();
|
final UnknownHostException unknownHostException = new UnknownHostException();
|
||||||
final int errorCode = VpnManager.ERROR_CODE_NETWORK_UNKNOWN_HOST;
|
final int errorCode = VpnManager.ERROR_CODE_NETWORK_UNKNOWN_HOST;
|
||||||
when(exception.getCause()).thenReturn(unknownHostException);
|
when(exception.getCause()).thenReturn(unknownHostException);
|
||||||
setupPlatformVpnWithSpecificExceptionAndItsErrorCode(exception,
|
doTestPlatformVpnWithException(exception,
|
||||||
VpnManager.CATEGORY_EVENT_NETWORK_ERROR, VpnManager.ERROR_CLASS_RECOVERABLE,
|
VpnManager.CATEGORY_EVENT_NETWORK_ERROR, VpnManager.ERROR_CLASS_RECOVERABLE,
|
||||||
errorCode);
|
errorCode);
|
||||||
}
|
}
|
||||||
@@ -1382,7 +1400,7 @@ public class VpnTest {
|
|||||||
new IkeTimeoutException("IkeTimeoutException");
|
new IkeTimeoutException("IkeTimeoutException");
|
||||||
final int errorCode = VpnManager.ERROR_CODE_NETWORK_PROTOCOL_TIMEOUT;
|
final int errorCode = VpnManager.ERROR_CODE_NETWORK_PROTOCOL_TIMEOUT;
|
||||||
when(exception.getCause()).thenReturn(ikeTimeoutException);
|
when(exception.getCause()).thenReturn(ikeTimeoutException);
|
||||||
setupPlatformVpnWithSpecificExceptionAndItsErrorCode(exception,
|
doTestPlatformVpnWithException(exception,
|
||||||
VpnManager.CATEGORY_EVENT_NETWORK_ERROR, VpnManager.ERROR_CLASS_RECOVERABLE,
|
VpnManager.CATEGORY_EVENT_NETWORK_ERROR, VpnManager.ERROR_CLASS_RECOVERABLE,
|
||||||
errorCode);
|
errorCode);
|
||||||
}
|
}
|
||||||
@@ -1391,7 +1409,7 @@ public class VpnTest {
|
|||||||
public void testStartPlatformVpnFailedWithIkeNetworkLostException() throws Exception {
|
public void testStartPlatformVpnFailedWithIkeNetworkLostException() throws Exception {
|
||||||
final IkeNetworkLostException exception = new IkeNetworkLostException(
|
final IkeNetworkLostException exception = new IkeNetworkLostException(
|
||||||
new Network(100));
|
new Network(100));
|
||||||
setupPlatformVpnWithSpecificExceptionAndItsErrorCode(exception,
|
doTestPlatformVpnWithException(exception,
|
||||||
VpnManager.CATEGORY_EVENT_NETWORK_ERROR, VpnManager.ERROR_CLASS_RECOVERABLE,
|
VpnManager.CATEGORY_EVENT_NETWORK_ERROR, VpnManager.ERROR_CLASS_RECOVERABLE,
|
||||||
VpnManager.ERROR_CODE_NETWORK_LOST);
|
VpnManager.ERROR_CODE_NETWORK_LOST);
|
||||||
}
|
}
|
||||||
@@ -1402,7 +1420,7 @@ public class VpnTest {
|
|||||||
final IOException ioException = new IOException();
|
final IOException ioException = new IOException();
|
||||||
final int errorCode = VpnManager.ERROR_CODE_NETWORK_IO;
|
final int errorCode = VpnManager.ERROR_CODE_NETWORK_IO;
|
||||||
when(exception.getCause()).thenReturn(ioException);
|
when(exception.getCause()).thenReturn(ioException);
|
||||||
setupPlatformVpnWithSpecificExceptionAndItsErrorCode(exception,
|
doTestPlatformVpnWithException(exception,
|
||||||
VpnManager.CATEGORY_EVENT_NETWORK_ERROR, VpnManager.ERROR_CLASS_RECOVERABLE,
|
VpnManager.CATEGORY_EVENT_NETWORK_ERROR, VpnManager.ERROR_CLASS_RECOVERABLE,
|
||||||
errorCode);
|
errorCode);
|
||||||
}
|
}
|
||||||
@@ -1694,6 +1712,11 @@ public class VpnTest {
|
|||||||
public DeviceIdleInternal getDeviceIdleInternal() {
|
public DeviceIdleInternal getDeviceIdleInternal() {
|
||||||
return mDeviceIdleInternal;
|
return mDeviceIdleInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getNextRetryDelaySeconds(int retryCount) {
|
||||||
|
// Simply return retryCount as the delay seconds for retrying.
|
||||||
|
return retryCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user