Merge "Update test for new IkeTunnelConnectionParams field" am: 5850372963
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/1976972 Change-Id: If20d5af24f2c9139ed3f41c62ecbec20433e1fba Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -131,6 +131,7 @@ java_defaults {
|
||||
"service-connectivity-pre-jarjar",
|
||||
"service-connectivity-tiramisu-pre-jarjar",
|
||||
"services.core-vpn",
|
||||
"cts-net-utils"
|
||||
],
|
||||
libs: [
|
||||
"android.net.ipsec.ike.stubs.module_lib",
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package android.net;
|
||||
|
||||
import static android.net.cts.util.IkeSessionTestUtils.CHILD_PARAMS;
|
||||
import static android.net.cts.util.IkeSessionTestUtils.IKE_PARAMS;
|
||||
|
||||
import static com.android.testutils.DevSdkIgnoreRuleKt.SC_V2;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
@@ -25,6 +28,7 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import android.net.ipsec.ike.IkeTunnelConnectionParams;
|
||||
import android.os.Build;
|
||||
import android.test.mock.MockContext;
|
||||
|
||||
@@ -441,6 +445,33 @@ public class Ikev2VpnProfileTest {
|
||||
assertEquals(ikeProfile, Ikev2VpnProfile.fromVpnProfile(ikeProfile.toVpnProfile()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConversionIsLosslessWithIkeTunConnParams() throws Exception {
|
||||
final IkeTunnelConnectionParams tunnelParams =
|
||||
new IkeTunnelConnectionParams(IKE_PARAMS, CHILD_PARAMS);
|
||||
// Config authentication related fields is not required while building with
|
||||
// IkeTunnelConnectionParams.
|
||||
final Ikev2VpnProfile ikeProfile = new Ikev2VpnProfile.Builder(tunnelParams).build();
|
||||
assertEquals(ikeProfile, Ikev2VpnProfile.fromVpnProfile(ikeProfile.toVpnProfile()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() throws Exception {
|
||||
// Verify building without IkeTunnelConnectionParams
|
||||
final Ikev2VpnProfile.Builder builder = getBuilderWithDefaultOptions();
|
||||
builder.setAuthDigitalSignature(mUserCert, mPrivateKey, mServerRootCa);
|
||||
assertEquals(builder.build(), builder.build());
|
||||
|
||||
// Verify building with IkeTunnelConnectionParams
|
||||
final IkeTunnelConnectionParams tunnelParams =
|
||||
new IkeTunnelConnectionParams(IKE_PARAMS, CHILD_PARAMS);
|
||||
final IkeTunnelConnectionParams tunnelParams2 =
|
||||
new IkeTunnelConnectionParams(IKE_PARAMS, CHILD_PARAMS);
|
||||
assertEquals(new Ikev2VpnProfile.Builder(tunnelParams).build(),
|
||||
new Ikev2VpnProfile.Builder(tunnelParams2).build());
|
||||
}
|
||||
|
||||
|
||||
private static class CertificateAndKey {
|
||||
public final X509Certificate cert;
|
||||
public final PrivateKey key;
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package com.android.internal.net;
|
||||
|
||||
import static android.net.cts.util.IkeSessionTestUtils.CHILD_PARAMS;
|
||||
import static android.net.cts.util.IkeSessionTestUtils.IKE_PARAMS;
|
||||
|
||||
import static com.android.modules.utils.build.SdkLevel.isAtLeastT;
|
||||
import static com.android.testutils.ParcelUtils.assertParcelSane;
|
||||
|
||||
@@ -26,6 +29,7 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.net.IpSecAlgorithm;
|
||||
import android.net.ipsec.ike.IkeTunnelConnectionParams;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
@@ -85,7 +89,8 @@ public class VpnProfileTest {
|
||||
|
||||
private VpnProfile getSampleIkev2Profile(String key) {
|
||||
final VpnProfile p = new VpnProfile(key, true /* isRestrictedToTestNetworks */,
|
||||
false /* excludesLocalRoutes */, true /* requiresPlatformValidation */);
|
||||
false /* excludesLocalRoutes */, true /* requiresPlatformValidation */,
|
||||
null /* ikeTunConnParams */);
|
||||
|
||||
p.name = "foo";
|
||||
p.type = VpnProfile.TYPE_IKEV2_IPSEC_USER_PASS;
|
||||
@@ -120,6 +125,35 @@ public class VpnProfileTest {
|
||||
return p;
|
||||
}
|
||||
|
||||
private VpnProfile getSampleIkev2ProfileWithIkeTunConnParams(String key) {
|
||||
final VpnProfile p = new VpnProfile(key, true /* isRestrictedToTestNetworks */,
|
||||
false /* excludesLocalRoutes */, true /* requiresPlatformValidation */,
|
||||
new IkeTunnelConnectionParams(IKE_PARAMS, CHILD_PARAMS));
|
||||
|
||||
p.name = "foo";
|
||||
p.server = "bar";
|
||||
p.dnsServers = "8.8.8.8";
|
||||
p.searchDomains = "";
|
||||
p.routes = "0.0.0.0/0";
|
||||
p.mppe = false;
|
||||
p.proxy = null;
|
||||
p.setAllowedAlgorithms(
|
||||
Arrays.asList(
|
||||
IpSecAlgorithm.AUTH_CRYPT_AES_GCM,
|
||||
IpSecAlgorithm.AUTH_CRYPT_CHACHA20_POLY1305,
|
||||
IpSecAlgorithm.AUTH_HMAC_SHA512,
|
||||
IpSecAlgorithm.CRYPT_AES_CBC));
|
||||
p.isBypassable = true;
|
||||
p.isMetered = true;
|
||||
p.maxMtu = 1350;
|
||||
p.areAuthParamsInline = true;
|
||||
|
||||
// Not saved, but also not compared.
|
||||
p.saveLogin = true;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
assertEquals(
|
||||
@@ -134,12 +168,20 @@ public class VpnProfileTest {
|
||||
public void testParcelUnparcel() {
|
||||
if (isAtLeastT()) {
|
||||
// excludeLocalRoutes, requiresPlatformValidation were added in T.
|
||||
assertParcelSane(getSampleIkev2Profile(DUMMY_PROFILE_KEY), 25);
|
||||
assertParcelSane(getSampleIkev2Profile(DUMMY_PROFILE_KEY), 26);
|
||||
assertParcelSane(getSampleIkev2ProfileWithIkeTunConnParams(DUMMY_PROFILE_KEY), 26);
|
||||
} else {
|
||||
assertParcelSane(getSampleIkev2Profile(DUMMY_PROFILE_KEY), 23);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeDecodeWithIkeTunConnParams() {
|
||||
final VpnProfile profile = getSampleIkev2ProfileWithIkeTunConnParams(DUMMY_PROFILE_KEY);
|
||||
final VpnProfile decoded = VpnProfile.decode(DUMMY_PROFILE_KEY, profile.encode());
|
||||
assertEquals(profile, decoded);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncodeDecode() {
|
||||
final VpnProfile profile = getSampleIkev2Profile(DUMMY_PROFILE_KEY);
|
||||
|
||||
Reference in New Issue
Block a user