Add unit tests for new VpnProfile fields
Add and update tests for automaticNattKeepaliveTimerEnabled and automaticIpVersionSelectionEnabled fields. Test: atest Ikev2VpnProfileTest VpnProfileTest Change-Id: I4e424abd2197d9099a2efe0bd8c4b9120bfcfe3a
This commit is contained in:
@@ -491,6 +491,29 @@ public class Ikev2VpnProfileTest {
|
|||||||
assertEquals(ikeProfile, Ikev2VpnProfile.fromVpnProfile(ikeProfile.toVpnProfile()));
|
assertEquals(ikeProfile, Ikev2VpnProfile.fromVpnProfile(ikeProfile.toVpnProfile()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAutomaticNattAndIpVersionConversionIsLossless() throws Exception {
|
||||||
|
final Ikev2VpnProfile.Builder builder = getBuilderWithDefaultOptions();
|
||||||
|
builder.setAutomaticNattKeepaliveTimerEnabled(true);
|
||||||
|
builder.setAutomaticIpVersionSelectionEnabled(true);
|
||||||
|
|
||||||
|
builder.setAuthDigitalSignature(mUserCert, mPrivateKey, mServerRootCa);
|
||||||
|
final Ikev2VpnProfile ikeProfile = builder.build();
|
||||||
|
|
||||||
|
assertEquals(ikeProfile, Ikev2VpnProfile.fromVpnProfile(ikeProfile.toVpnProfile()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAutomaticNattAndIpVersionDefaults() throws Exception {
|
||||||
|
final Ikev2VpnProfile.Builder builder = getBuilderWithDefaultOptions();
|
||||||
|
|
||||||
|
builder.setAuthDigitalSignature(mUserCert, mPrivateKey, mServerRootCa);
|
||||||
|
final Ikev2VpnProfile ikeProfile = builder.build();
|
||||||
|
|
||||||
|
assertEquals(false, ikeProfile.isAutomaticNattKeepaliveTimerEnabled());
|
||||||
|
assertEquals(false, ikeProfile.isAutomaticIpVersionSelectionEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquals() throws Exception {
|
public void testEquals() throws Exception {
|
||||||
// Verify building without IkeTunnelConnectionParams
|
// Verify building without IkeTunnelConnectionParams
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import static android.net.cts.util.IkeSessionTestUtils.CHILD_PARAMS;
|
|||||||
import static android.net.cts.util.IkeSessionTestUtils.IKE_PARAMS_V4;
|
import static android.net.cts.util.IkeSessionTestUtils.IKE_PARAMS_V4;
|
||||||
|
|
||||||
import static com.android.modules.utils.build.SdkLevel.isAtLeastT;
|
import static com.android.modules.utils.build.SdkLevel.isAtLeastT;
|
||||||
|
import static com.android.modules.utils.build.SdkLevel.isAtLeastU;
|
||||||
import static com.android.testutils.ParcelUtils.assertParcelSane;
|
import static com.android.testutils.ParcelUtils.assertParcelSane;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@@ -55,6 +56,9 @@ public class VpnProfileTest {
|
|||||||
private static final int ENCODED_INDEX_RESTRICTED_TO_TEST_NETWORKS = 24;
|
private static final int ENCODED_INDEX_RESTRICTED_TO_TEST_NETWORKS = 24;
|
||||||
private static final int ENCODED_INDEX_EXCLUDE_LOCAL_ROUTE = 25;
|
private static final int ENCODED_INDEX_EXCLUDE_LOCAL_ROUTE = 25;
|
||||||
private static final int ENCODED_INDEX_REQUIRE_PLATFORM_VALIDATION = 26;
|
private static final int ENCODED_INDEX_REQUIRE_PLATFORM_VALIDATION = 26;
|
||||||
|
private static final int ENCODED_INDEX_IKE_TUN_CONN_PARAMS = 27;
|
||||||
|
private static final int ENCODED_INDEX_AUTOMATIC_NATT_KEEPALIVE_TIMER_ENABLED = 28;
|
||||||
|
private static final int ENCODED_INDEX_AUTOMATIC_IP_VERSION_SELECTION_ENABLED = 29;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaults() throws Exception {
|
public void testDefaults() throws Exception {
|
||||||
@@ -85,12 +89,15 @@ public class VpnProfileTest {
|
|||||||
assertFalse(p.isRestrictedToTestNetworks);
|
assertFalse(p.isRestrictedToTestNetworks);
|
||||||
assertFalse(p.excludeLocalRoutes);
|
assertFalse(p.excludeLocalRoutes);
|
||||||
assertFalse(p.requiresInternetValidation);
|
assertFalse(p.requiresInternetValidation);
|
||||||
|
assertFalse(p.automaticNattKeepaliveTimerEnabled);
|
||||||
|
assertFalse(p.automaticIpVersionSelectionEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
private VpnProfile getSampleIkev2Profile(String key) {
|
private VpnProfile getSampleIkev2Profile(String key) {
|
||||||
final VpnProfile p = new VpnProfile(key, true /* isRestrictedToTestNetworks */,
|
final VpnProfile p = new VpnProfile(key, true /* isRestrictedToTestNetworks */,
|
||||||
false /* excludesLocalRoutes */, true /* requiresPlatformValidation */,
|
false /* excludesLocalRoutes */, true /* requiresPlatformValidation */,
|
||||||
null /* ikeTunConnParams */);
|
null /* ikeTunConnParams */, true /* mAutomaticNattKeepaliveTimerEnabled */,
|
||||||
|
true /* automaticIpVersionSelectionEnabled */);
|
||||||
|
|
||||||
p.name = "foo";
|
p.name = "foo";
|
||||||
p.type = VpnProfile.TYPE_IKEV2_IPSEC_USER_PASS;
|
p.type = VpnProfile.TYPE_IKEV2_IPSEC_USER_PASS;
|
||||||
@@ -128,7 +135,9 @@ public class VpnProfileTest {
|
|||||||
private VpnProfile getSampleIkev2ProfileWithIkeTunConnParams(String key) {
|
private VpnProfile getSampleIkev2ProfileWithIkeTunConnParams(String key) {
|
||||||
final VpnProfile p = new VpnProfile(key, true /* isRestrictedToTestNetworks */,
|
final VpnProfile p = new VpnProfile(key, true /* isRestrictedToTestNetworks */,
|
||||||
false /* excludesLocalRoutes */, true /* requiresPlatformValidation */,
|
false /* excludesLocalRoutes */, true /* requiresPlatformValidation */,
|
||||||
new IkeTunnelConnectionParams(IKE_PARAMS_V4, CHILD_PARAMS));
|
new IkeTunnelConnectionParams(IKE_PARAMS_V4, CHILD_PARAMS),
|
||||||
|
true /* mAutomaticNattKeepaliveTimerEnabled */,
|
||||||
|
true /* automaticIpVersionSelectionEnabled */);
|
||||||
|
|
||||||
p.name = "foo";
|
p.name = "foo";
|
||||||
p.server = "bar";
|
p.server = "bar";
|
||||||
@@ -166,7 +175,11 @@ public class VpnProfileTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParcelUnparcel() {
|
public void testParcelUnparcel() {
|
||||||
if (isAtLeastT()) {
|
if (isAtLeastU()) {
|
||||||
|
// automaticNattKeepaliveTimerEnabled, automaticIpVersionSelectionEnabled added in U.
|
||||||
|
assertParcelSane(getSampleIkev2Profile(DUMMY_PROFILE_KEY), 28);
|
||||||
|
assertParcelSane(getSampleIkev2ProfileWithIkeTunConnParams(DUMMY_PROFILE_KEY), 28);
|
||||||
|
} else if (isAtLeastT()) {
|
||||||
// excludeLocalRoutes, requiresPlatformValidation were added in T.
|
// excludeLocalRoutes, requiresPlatformValidation were added in T.
|
||||||
assertParcelSane(getSampleIkev2Profile(DUMMY_PROFILE_KEY), 26);
|
assertParcelSane(getSampleIkev2Profile(DUMMY_PROFILE_KEY), 26);
|
||||||
assertParcelSane(getSampleIkev2ProfileWithIkeTunConnParams(DUMMY_PROFILE_KEY), 26);
|
assertParcelSane(getSampleIkev2ProfileWithIkeTunConnParams(DUMMY_PROFILE_KEY), 26);
|
||||||
@@ -221,16 +234,28 @@ public class VpnProfileTest {
|
|||||||
ENCODED_INDEX_AUTH_PARAMS_INLINE,
|
ENCODED_INDEX_AUTH_PARAMS_INLINE,
|
||||||
ENCODED_INDEX_RESTRICTED_TO_TEST_NETWORKS,
|
ENCODED_INDEX_RESTRICTED_TO_TEST_NETWORKS,
|
||||||
ENCODED_INDEX_EXCLUDE_LOCAL_ROUTE,
|
ENCODED_INDEX_EXCLUDE_LOCAL_ROUTE,
|
||||||
ENCODED_INDEX_REQUIRE_PLATFORM_VALIDATION /* missingIndices */);
|
ENCODED_INDEX_REQUIRE_PLATFORM_VALIDATION,
|
||||||
|
ENCODED_INDEX_IKE_TUN_CONN_PARAMS,
|
||||||
|
ENCODED_INDEX_AUTOMATIC_NATT_KEEPALIVE_TIMER_ENABLED,
|
||||||
|
ENCODED_INDEX_AUTOMATIC_IP_VERSION_SELECTION_ENABLED
|
||||||
|
/* missingIndices */);
|
||||||
|
|
||||||
assertNull(VpnProfile.decode(DUMMY_PROFILE_KEY, tooFewValues.getBytes()));
|
assertNull(VpnProfile.decode(DUMMY_PROFILE_KEY, tooFewValues.getBytes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getEncodedDecodedIkev2ProfileWithtooFewValues() {
|
||||||
|
return getEncodedDecodedIkev2ProfileMissingValues(
|
||||||
|
ENCODED_INDEX_RESTRICTED_TO_TEST_NETWORKS,
|
||||||
|
ENCODED_INDEX_EXCLUDE_LOCAL_ROUTE,
|
||||||
|
ENCODED_INDEX_REQUIRE_PLATFORM_VALIDATION,
|
||||||
|
ENCODED_INDEX_IKE_TUN_CONN_PARAMS,
|
||||||
|
ENCODED_INDEX_AUTOMATIC_NATT_KEEPALIVE_TIMER_ENABLED,
|
||||||
|
ENCODED_INDEX_AUTOMATIC_IP_VERSION_SELECTION_ENABLED /* missingIndices */);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeDecodeMissingIsRestrictedToTestNetworks() {
|
public void testEncodeDecodeMissingIsRestrictedToTestNetworks() {
|
||||||
final String tooFewValues =
|
final String tooFewValues = getEncodedDecodedIkev2ProfileWithtooFewValues();
|
||||||
getEncodedDecodedIkev2ProfileMissingValues(
|
|
||||||
ENCODED_INDEX_RESTRICTED_TO_TEST_NETWORKS /* missingIndices */);
|
|
||||||
|
|
||||||
// Verify decoding without isRestrictedToTestNetworks defaults to false
|
// Verify decoding without isRestrictedToTestNetworks defaults to false
|
||||||
final VpnProfile decoded = VpnProfile.decode(DUMMY_PROFILE_KEY, tooFewValues.getBytes());
|
final VpnProfile decoded = VpnProfile.decode(DUMMY_PROFILE_KEY, tooFewValues.getBytes());
|
||||||
@@ -239,10 +264,7 @@ public class VpnProfileTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeDecodeMissingExcludeLocalRoutes() {
|
public void testEncodeDecodeMissingExcludeLocalRoutes() {
|
||||||
final String tooFewValues =
|
final String tooFewValues = getEncodedDecodedIkev2ProfileWithtooFewValues();
|
||||||
getEncodedDecodedIkev2ProfileMissingValues(
|
|
||||||
ENCODED_INDEX_EXCLUDE_LOCAL_ROUTE,
|
|
||||||
ENCODED_INDEX_REQUIRE_PLATFORM_VALIDATION /* missingIndices */);
|
|
||||||
|
|
||||||
// Verify decoding without excludeLocalRoutes defaults to false
|
// Verify decoding without excludeLocalRoutes defaults to false
|
||||||
final VpnProfile decoded = VpnProfile.decode(DUMMY_PROFILE_KEY, tooFewValues.getBytes());
|
final VpnProfile decoded = VpnProfile.decode(DUMMY_PROFILE_KEY, tooFewValues.getBytes());
|
||||||
@@ -251,15 +273,31 @@ public class VpnProfileTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeDecodeMissingRequiresValidation() {
|
public void testEncodeDecodeMissingRequiresValidation() {
|
||||||
final String tooFewValues =
|
final String tooFewValues = getEncodedDecodedIkev2ProfileWithtooFewValues();
|
||||||
getEncodedDecodedIkev2ProfileMissingValues(
|
|
||||||
ENCODED_INDEX_REQUIRE_PLATFORM_VALIDATION /* missingIndices */);
|
|
||||||
|
|
||||||
// Verify decoding without requiresValidation defaults to false
|
// Verify decoding without requiresValidation defaults to false
|
||||||
final VpnProfile decoded = VpnProfile.decode(DUMMY_PROFILE_KEY, tooFewValues.getBytes());
|
final VpnProfile decoded = VpnProfile.decode(DUMMY_PROFILE_KEY, tooFewValues.getBytes());
|
||||||
assertFalse(decoded.requiresInternetValidation);
|
assertFalse(decoded.requiresInternetValidation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEncodeDecodeMissingAutomaticNattKeepaliveTimerEnabled() {
|
||||||
|
final String tooFewValues = getEncodedDecodedIkev2ProfileWithtooFewValues();
|
||||||
|
|
||||||
|
// Verify decoding without automaticNattKeepaliveTimerEnabled defaults to false
|
||||||
|
final VpnProfile decoded = VpnProfile.decode(DUMMY_PROFILE_KEY, tooFewValues.getBytes());
|
||||||
|
assertFalse(decoded.automaticNattKeepaliveTimerEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEncodeDecodeMissingAutomaticIpVersionSelectionEnabled() {
|
||||||
|
final String tooFewValues = getEncodedDecodedIkev2ProfileWithtooFewValues();
|
||||||
|
|
||||||
|
// Verify decoding without automaticIpVersionSelectionEnabled defaults to false
|
||||||
|
final VpnProfile decoded = VpnProfile.decode(DUMMY_PROFILE_KEY, tooFewValues.getBytes());
|
||||||
|
assertFalse(decoded.automaticIpVersionSelectionEnabled);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeDecodeLoginsNotSaved() {
|
public void testEncodeDecodeLoginsNotSaved() {
|
||||||
final VpnProfile profile = getSampleIkev2Profile(DUMMY_PROFILE_KEY);
|
final VpnProfile profile = getSampleIkev2Profile(DUMMY_PROFILE_KEY);
|
||||||
|
|||||||
Reference in New Issue
Block a user