Test VpnManager event for CATEGORY_EVENT_IKE_ERROR
Bug: 191413541 Test: atest FrameworksNetTests:VpnTest Change-Id: Iebc0ac281eb03fac9626c64e44cdd14be1462d89
This commit is contained in:
@@ -95,6 +95,7 @@ import android.net.VpnProfileState;
|
||||
import android.net.VpnService;
|
||||
import android.net.VpnTransportInfo;
|
||||
import android.net.ipsec.ike.IkeSessionCallback;
|
||||
import android.net.ipsec.ike.exceptions.IkeException;
|
||||
import android.net.ipsec.ike.exceptions.IkeProtocolException;
|
||||
import android.os.Build.VERSION_CODES;
|
||||
import android.os.Bundle;
|
||||
@@ -1165,15 +1166,16 @@ public class VpnTest {
|
||||
config -> Arrays.asList(config.flags).contains(flag)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartPlatformVpnAuthenticationFailed() throws Exception {
|
||||
private void setupPlatformVpnWithSpecificExceptionAndItsErrorCode(
|
||||
IkeException exception, int errorType, int errorCode) throws Exception {
|
||||
final ArgumentCaptor<IkeSessionCallback> captor =
|
||||
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();
|
||||
|
||||
verifyInterfaceSetCfgWithFlags(IF_STATE_UP);
|
||||
@@ -1183,10 +1185,32 @@ public class VpnTest {
|
||||
verify(mIkev2SessionCreator, timeout(TEST_TIMEOUT_MS))
|
||||
.createIkeSession(any(), any(), any(), any(), captor.capture(), any());
|
||||
final IkeSessionCallback ikeCb = captor.getValue();
|
||||
ikeCb.onClosedExceptionally(exception);
|
||||
ikeCb.onClosedWithException(exception);
|
||||
|
||||
verify(mConnectivityManager, timeout(TEST_TIMEOUT_MS)).unregisterNetworkCallback(eq(cb));
|
||||
assertEquals(LegacyVpnInfo.STATE_FAILED, vpn.getLegacyVpnInfo().state);
|
||||
verifyVpnManagerEvent(sessionKey, VpnManager.CATEGORY_EVENT_IKE_ERROR, errorType, errorCode,
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user