Merge "Test VpnProfile is not modified in startLegacyVpn" into main

This commit is contained in:
Hansen Kurli 2023-11-16 10:04:19 +00:00 • committed by Gerrit Code Review
commit 77f9fb300f
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.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@ -311,4 +312,12 @@ public class VpnProfileTest {
decoded.password = profile.password;
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

@ -3164,6 +3164,20 @@ public class VpnTest extends VpnTestBase {
assertThrows(UnsupportedOperationException.class, () -> startLegacyVpn(vpn, profile));
}
@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) {
assertNotNull(nc);
VpnTransportInfo ti = (VpnTransportInfo) nc.getTransportInfo();