Merge "Force creation of Socket upon Transform application"

am: 4acfd60844

Change-Id: Ia19da86a3fa40e309ff7a079307a8a63de8ba796
This commit is contained in:
Benedict Wong
2018-04-04 12:43:36 -07:00
committed by android-build-merger

View File

@@ -37,6 +37,7 @@ import android.system.Os;
import com.android.server.IpSecService; import com.android.server.IpSecService;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import org.junit.Before; import org.junit.Before;
@@ -187,6 +188,33 @@ public class IpSecManagerTest {
verify(mMockIpSecService).closeUdpEncapsulationSocket(DUMMY_RESOURCE_ID); verify(mMockIpSecService).closeUdpEncapsulationSocket(DUMMY_RESOURCE_ID);
} }
@Test
public void testApplyTransportModeTransformEnsuresSocketCreation() throws Exception {
Socket socket = new Socket();
IpSecConfig dummyConfig = new IpSecConfig();
IpSecTransform dummyTransform = new IpSecTransform(null, dummyConfig);
// Even if underlying SocketImpl is not initalized, this should force the init, and
// thereby succeed.
mIpSecManager.applyTransportModeTransform(
socket, IpSecManager.DIRECTION_IN, dummyTransform);
// Check to make sure the FileDescriptor is non-null
assertNotNull(socket.getFileDescriptor$());
}
@Test
public void testRemoveTransportModeTransformsForcesSocketCreation() throws Exception {
Socket socket = new Socket();
// Even if underlying SocketImpl is not initalized, this should force the init, and
// thereby succeed.
mIpSecManager.removeTransportModeTransforms(socket);
// Check to make sure the FileDescriptor is non-null
assertNotNull(socket.getFileDescriptor$());
}
@Test @Test
public void testOpenEncapsulationSocketOnRandomPort() throws Exception { public void testOpenEncapsulationSocketOnRandomPort() throws Exception {
IpSecUdpEncapResponse udpEncapResp = IpSecUdpEncapResponse udpEncapResp =