Add test for startPptp
The test verifies arguments used to start the daemon Bug: 201660636 Test: atest VpnTest Change-Id: I0854fbeaf1a3e3554c157fde227a7bfa187b1013 Merged-In: I0854fbeaf1a3e3554c157fde227a7bfa187b1013
This commit is contained in:
committed by
chiachangwang
parent
85694dc277
commit
522cea7d4e
@@ -1846,6 +1846,16 @@ public class VpnTest {
|
|||||||
startRacoon("hostname", "5.6.7.8"); // address returned by deps.resolve
|
startRacoon("hostname", "5.6.7.8"); // address returned by deps.resolve
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStartPptp() throws Exception {
|
||||||
|
startPptp(true /* useMppe */);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStartPptp_NoMppe() throws Exception {
|
||||||
|
startPptp(false /* useMppe */);
|
||||||
|
}
|
||||||
|
|
||||||
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();
|
||||||
@@ -1853,6 +1863,49 @@ public class VpnTest {
|
|||||||
assertEquals(type, ti.getType());
|
assertEquals(type, ti.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startPptp(boolean useMppe) throws Exception {
|
||||||
|
final VpnProfile profile = new VpnProfile("testProfile" /* key */);
|
||||||
|
profile.type = VpnProfile.TYPE_PPTP;
|
||||||
|
profile.name = "testProfileName";
|
||||||
|
profile.username = "userName";
|
||||||
|
profile.password = "thePassword";
|
||||||
|
profile.server = "192.0.2.123";
|
||||||
|
profile.mppe = useMppe;
|
||||||
|
|
||||||
|
doReturn(new Network[] { new Network(101) }).when(mConnectivityManager).getAllNetworks();
|
||||||
|
doReturn(new Network(102)).when(mConnectivityManager).registerNetworkAgent(any(), any(),
|
||||||
|
any(), any(), any(), any(), anyInt());
|
||||||
|
|
||||||
|
final Vpn vpn = startLegacyVpn(createVpn(primaryUser.id), profile);
|
||||||
|
final TestDeps deps = (TestDeps) vpn.mDeps;
|
||||||
|
|
||||||
|
// TODO: use import when this is merged in all branches and there's no merge conflict
|
||||||
|
com.android.testutils.Cleanup.testAndCleanup(() -> {
|
||||||
|
final String[] mtpdArgs = deps.mtpdArgs.get(10, TimeUnit.SECONDS);
|
||||||
|
final String[] argsPrefix = new String[]{
|
||||||
|
EGRESS_IFACE, "pptp", profile.server, "1723", "name", profile.username,
|
||||||
|
"password", profile.password, "linkname", "vpn", "refuse-eap", "nodefaultroute",
|
||||||
|
"usepeerdns", "idle", "1800", "mtu", "1270", "mru", "1270"
|
||||||
|
};
|
||||||
|
assertArrayEquals(argsPrefix, Arrays.copyOf(mtpdArgs, argsPrefix.length));
|
||||||
|
if (useMppe) {
|
||||||
|
assertEquals(argsPrefix.length + 2, mtpdArgs.length);
|
||||||
|
assertEquals("+mppe", mtpdArgs[argsPrefix.length]);
|
||||||
|
assertEquals("-pap", mtpdArgs[argsPrefix.length + 1]);
|
||||||
|
} else {
|
||||||
|
assertEquals(argsPrefix.length + 1, mtpdArgs.length);
|
||||||
|
assertEquals("nomppe", mtpdArgs[argsPrefix.length]);
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(mConnectivityManager, timeout(10_000)).registerNetworkAgent(any(), any(),
|
||||||
|
any(), any(), any(), any(), anyInt());
|
||||||
|
}, () -> { // Cleanup
|
||||||
|
vpn.mVpnRunner.exitVpnRunner();
|
||||||
|
deps.getStateFile().delete(); // set to delete on exit, but this deletes it earlier
|
||||||
|
vpn.mVpnRunner.join(10_000); // wait for up to 10s for the runner to die and cleanup
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void startRacoon(final String serverAddr, final String expectedAddr)
|
public void startRacoon(final String serverAddr, final String expectedAddr)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
final ConditionVariable legacyRunnerReady = new ConditionVariable();
|
final ConditionVariable legacyRunnerReady = new ConditionVariable();
|
||||||
|
|||||||
Reference in New Issue
Block a user