Test VpnManager event for CATEGORY_EVENT_IKE_ERROR am: 827b44daea
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1956036 Change-Id: Ifde51b2ee0c3e252911fca5314b2808e4adb94cb Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -95,6 +95,7 @@ import android.net.VpnProfileState;
|
|||||||
import android.net.VpnService;
|
import android.net.VpnService;
|
||||||
import android.net.VpnTransportInfo;
|
import android.net.VpnTransportInfo;
|
||||||
import android.net.ipsec.ike.IkeSessionCallback;
|
import android.net.ipsec.ike.IkeSessionCallback;
|
||||||
|
import android.net.ipsec.ike.exceptions.IkeException;
|
||||||
import android.net.ipsec.ike.exceptions.IkeProtocolException;
|
import android.net.ipsec.ike.exceptions.IkeProtocolException;
|
||||||
import android.os.Build.VERSION_CODES;
|
import android.os.Build.VERSION_CODES;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -1165,15 +1166,16 @@ public class VpnTest {
|
|||||||
config -> Arrays.asList(config.flags).contains(flag)));
|
config -> Arrays.asList(config.flags).contains(flag)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private void setupPlatformVpnWithSpecificExceptionAndItsErrorCode(
|
||||||
public void testStartPlatformVpnAuthenticationFailed() throws Exception {
|
IkeException exception, int errorType, int errorCode) throws Exception {
|
||||||
final ArgumentCaptor<IkeSessionCallback> captor =
|
final ArgumentCaptor<IkeSessionCallback> captor =
|
||||||
ArgumentCaptor.forClass(IkeSessionCallback.class);
|
ArgumentCaptor.forClass(IkeSessionCallback.class);
|
||||||
final IkeProtocolException exception = mock(IkeProtocolException.class);
|
|
||||||
when(exception.getErrorType())
|
|
||||||
.thenReturn(IkeProtocolException.ERROR_TYPE_AUTHENTICATION_FAILED);
|
|
||||||
|
|
||||||
final Vpn vpn = startLegacyVpn(createVpn(primaryUser.id), (mVpnProfile));
|
final Vpn vpn = createVpnAndSetupUidChecks(AppOpsManager.OPSTR_ACTIVATE_PLATFORM_VPN);
|
||||||
|
when(mVpnProfileStore.get(vpn.getProfileNameForPackage(TEST_VPN_PKG)))
|
||||||
|
.thenReturn(mVpnProfile.encode());
|
||||||
|
|
||||||
|
final String sessionKey = vpn.startVpnProfile(TEST_VPN_PKG);
|
||||||
final NetworkCallback cb = triggerOnAvailableAndGetCallback();
|
final NetworkCallback cb = triggerOnAvailableAndGetCallback();
|
||||||
|
|
||||||
verifyInterfaceSetCfgWithFlags(IF_STATE_UP);
|
verifyInterfaceSetCfgWithFlags(IF_STATE_UP);
|
||||||
@@ -1183,10 +1185,32 @@ public class VpnTest {
|
|||||||
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());
|
||||||
final IkeSessionCallback ikeCb = captor.getValue();
|
final IkeSessionCallback ikeCb = captor.getValue();
|
||||||
ikeCb.onClosedExceptionally(exception);
|
ikeCb.onClosedWithException(exception);
|
||||||
|
|
||||||
verify(mConnectivityManager, timeout(TEST_TIMEOUT_MS)).unregisterNetworkCallback(eq(cb));
|
verifyVpnManagerEvent(sessionKey, VpnManager.CATEGORY_EVENT_IKE_ERROR, errorType, errorCode,
|
||||||
assertEquals(LegacyVpnInfo.STATE_FAILED, vpn.getLegacyVpnInfo().state);
|
null /* profileState */);
|
||||||
|
if (errorType == VpnManager.ERROR_CLASS_NOT_RECOVERABLE) {
|
||||||
|
verify(mConnectivityManager, timeout(TEST_TIMEOUT_MS))
|
||||||
|
.unregisterNetworkCallback(eq(cb));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStartPlatformVpnAuthenticationFailed() throws Exception {
|
||||||
|
final IkeProtocolException exception = mock(IkeProtocolException.class);
|
||||||
|
final int errorCode = IkeProtocolException.ERROR_TYPE_AUTHENTICATION_FAILED;
|
||||||
|
when(exception.getErrorType()).thenReturn(errorCode);
|
||||||
|
setupPlatformVpnWithSpecificExceptionAndItsErrorCode(exception,
|
||||||
|
VpnManager.ERROR_CLASS_NOT_RECOVERABLE, errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStartPlatformVpnFailedWithRecoverableError() throws Exception {
|
||||||
|
final IkeProtocolException exception = mock(IkeProtocolException.class);
|
||||||
|
final int errorCode = IkeProtocolException.ERROR_TYPE_TEMPORARY_FAILURE;
|
||||||
|
when(exception.getErrorType()).thenReturn(errorCode);
|
||||||
|
setupPlatformVpnWithSpecificExceptionAndItsErrorCode(exception,
|
||||||
|
VpnManager.ERROR_CLASS_RECOVERABLE, errorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user