Test VpnProfile is not modified in startLegacyVpn

The profile is modified within startLegacyVpnPrivileged(), e.g.
ipsecCaCert, ipsecUserCert. This causes subsequent calls from
callers such as LockdownVpnTracker to fail.

Add a new test to ensure the VpnProfile is not modified in
startLegacyVpn.
Add testClone in VpnProfileTest.

Bug: 190572822
Bug: 309591931
Test: atest FrameworksNetTests, test before and after fix.
Test: Manual test
Change-Id: Id090e0dd3b9e74a7461ae90e68c41e802b458744
This commit is contained in:
Hansen Kurli
2023-11-15 16:27:43 +08:00
parent 31ab762e42
commit e949124bcc
2 changed files with 23 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ import static com.android.testutils.ParcelUtils.assertParcelSane;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@@ -311,4 +312,12 @@ public class VpnProfileTest {
decoded.password = profile.password; decoded.password = profile.password;
assertEquals(profile, decoded); assertEquals(profile, decoded);
} }
@Test
public void testClone() {
final VpnProfile profile = getSampleIkev2Profile(DUMMY_PROFILE_KEY);
final VpnProfile clone = profile.clone();
assertEquals(profile, clone);
assertNotSame(profile, clone);
}
} }

View File

@@ -3131,6 +3131,20 @@ public class VpnTest extends VpnTestBase {
startPptp(false /* useMppe */); startPptp(false /* useMppe */);
} }
@Test
public void testStartLegacyVpnModifyProfile_TypePSK() throws Exception {
setMockedUsers(PRIMARY_USER);
final Vpn vpn = createVpn(PRIMARY_USER.id);
final Ikev2VpnProfile ikev2VpnProfile =
new Ikev2VpnProfile.Builder(TEST_VPN_SERVER, TEST_VPN_IDENTITY)
.setAuthPsk(TEST_VPN_PSK)
.build();
final VpnProfile profile = ikev2VpnProfile.toVpnProfile();
startLegacyVpn(vpn, profile);
assertEquals(profile, ikev2VpnProfile.toVpnProfile());
}
private void assertTransportInfoMatches(NetworkCapabilities nc, int type) { private void assertTransportInfoMatches(NetworkCapabilities nc, int type) {
assertNotNull(nc); assertNotNull(nc);
VpnTransportInfo ti = (VpnTransportInfo) nc.getTransportInfo(); VpnTransportInfo ti = (VpnTransportInfo) nc.getTransportInfo();