/******************************************************************************* * Copyright (c) 2004, 2009 Tasktop Technologies and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Tasktop Technologies - initial API and implementation *******************************************************************************/ package org.eclipse.mylyn.commons.tests.net; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import org.apache.commons.httpclient.params.HttpConnectionParams; import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory; import org.eclipse.mylyn.commons.sdk.util.MockServer; import org.eclipse.mylyn.internal.commons.net.PollingSslProtocolSocketFactory; import junit.framework.TestCase; /** * @author Steffen Pingel */ public class SslProtocolSocketFactoryTest extends TestCase { private MockServer server; private InetSocketAddress proxyAddress; @Override protected void setUp() throws Exception { server = new MockServer(); int proxyPort = server.startAndWait(); assert proxyPort > 0; proxyAddress = new InetSocketAddress("localhost", proxyPort); } @Override protected void tearDown() throws Exception { server.stop(); } public void testTrustAllSslProtocolSocketFactory() throws Exception { SecureProtocolSocketFactory factory = new PollingSslProtocolSocketFactory(); Socket s; s = factory.createSocket(proxyAddress.getHostName(), proxyAddress.getPort()); assertNotNull(s); assertTrue(s.isConnected()); s.close(); InetAddress anyHost = new Socket().getLocalAddress(); s = factory.createSocket(proxyAddress.getHostName(), proxyAddress.getPort(), anyHost, 0); assertNotNull(s); assertTrue(s.isConnected()); s.close(); HttpConnectionParams params = new HttpConnectionParams(); s = factory.createSocket(proxyAddress.getHostName(), proxyAddress.getPort(), anyHost, 0, params); assertNotNull(s); assertTrue(s.isConnected()); s.close(); params.setConnectionTimeout(1000); s = factory.createSocket(proxyAddress.getHostName(), proxyAddress.getPort(), anyHost, 0, params); assertNotNull(s); assertTrue(s.isConnected()); s.close(); } }