[MNG-2305] only first active proxy considered/used

o Added IT

git-svn-id: https://svn.apache.org/repos/asf/maven/core-integration-testing/trunk@930236 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-04-02 11:02:03 +00:00
parent 059c71e8a5
commit 9d0571f9a6
7 changed files with 564 additions and 0 deletions

View File

@ -419,6 +419,7 @@ public class IntegrationTestSuite
suite.addTestSuite( MavenITmng2339BadProjectInterpolationTest.class );
suite.addTestSuite( MavenITmng2318LocalParentResolutionTest.class );
suite.addTestSuite( MavenITmng2309ProfileInjectionOrderTest.class );
suite.addTestSuite( MavenITmng2305MultipleProxiesTest.class );
suite.addTestSuite( MavenITmng2293CustomPluginParamImplTest.class );
suite.addTestSuite( MavenITmng2277AggregatorAndResolutionPluginsTest.class );
suite.addTestSuite( MavenITmng2276ProfileActivationBySettingsPropertyTest.class );

View File

@ -0,0 +1,164 @@
package org.apache.maven.it;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Request;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.AbstractHandler;
import org.mortbay.jetty.security.SslSocketConnector;
/**
* This is a test set for <a href="http://jira.codehaus.org/browse/MNG-2305">MNG-2305</a>.
*
* @author Benjamin Bentmann
*/
public class MavenITmng2305MultipleProxiesTest
extends AbstractMavenIntegrationTestCase
{
public MavenITmng2305MultipleProxiesTest()
{
super( "[3.0-alpha-3,)" );
}
/**
* Verify that proxies can be setup for multiple protocols, in this case HTTP and HTTPS. As a nice side effect,
* this checks HTTPS tunneling over a web proxy.
*/
public void testit()
throws Exception
{
File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2305" );
Verifier verifier = new Verifier( testDir.getAbsolutePath() );
// NOTE: trust store cannot be reliably configured for the current JVM
verifier.setForkJvm( true );
// keytool -genkey -alias https.mngit -keypass key-passwd -keystore keystore -storepass store-passwd \
// -validity 4096 -dname "cn=https.mngit, ou=None, L=Seattle, ST=Washington, o=ExampleOrg, c=US" -keyalg RSA
String storePath = new File( testDir, "keystore" ).getAbsolutePath();
String storePwd = "store-passwd";
String keyPwd = "key-passwd";
Server server = new Server( 0 );
server.addConnector( newHttpsConnector( storePath, storePwd, keyPwd ) );
server.setHandler( new RepoHandler() );
server.start();
int httpPort = server.getConnectors()[0].getLocalPort();
int httpsPort = server.getConnectors()[1].getLocalPort();
TunnelingProxyServer proxy = new TunnelingProxyServer( 0, "localhost", httpsPort, "https.mngit:443" );
proxy.start();
int proxyPort = proxy.getPort();
try
{
verifier.setAutoclean( false );
verifier.deleteDirectory( "target" );
verifier.deleteArtifacts( "org.apache.maven.its.mng2305" );
Properties filterProps = verifier.newDefaultFilterProperties();
filterProps.setProperty( "@proxy.http@", Integer.toString( httpPort ) );
filterProps.setProperty( "@proxy.https@", Integer.toString( proxyPort ) );
verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
verifier.getCliOptions().add( "--settings" );
verifier.getCliOptions().add( "settings.xml" );
verifier.setSystemProperty( "javax.net.ssl.trustStore", storePath );
verifier.setSystemProperty( "javax.net.ssl.trustStorePassword", storePwd );
verifier.executeGoal( "validate" );
verifier.verifyErrorFreeLog();
verifier.resetStreams();
}
finally
{
proxy.stop();
server.stop();
}
List cp = verifier.loadLines( "target/classpath.txt", "UTF-8" );
assertTrue( cp.toString(), cp.contains( "http-0.1.jar" ) );
assertTrue( cp.toString(), cp.contains( "https-0.1.jar" ) );
}
private Connector newHttpsConnector( String keystore, String storepwd, String keypwd )
{
SslSocketConnector connector = new SslSocketConnector();
connector.setPort( 0 );
connector.setKeystore( keystore );
connector.setPassword( storepwd );
connector.setKeyPassword( keypwd );
return connector;
}
static class RepoHandler extends AbstractHandler
{
public void handle( String target, HttpServletRequest request, HttpServletResponse response, int dispatch )
throws IOException
{
PrintWriter writer = response.getWriter();
String uri = request.getRequestURI();
if ( !uri.startsWith( "/repo/org/apache/maven/its/mng2305/" + request.getScheme() + "/" ) )
{
// HTTP connector serves only http-0.1.jar and HTTPS connector serves only https-0.1.jar
response.setStatus( HttpServletResponse.SC_NOT_FOUND );
}
else if ( uri.endsWith( ".pom" ) )
{
writer.println( "<project>" );
writer.println( " <modelVersion>4.0.0</modelVersion>" );
writer.println( " <groupId>org.apache.maven.its.mng2305</groupId>" );
writer.println( " <artifactId>" + request.getScheme() + "</artifactId>" );
writer.println( " <version>0.1</version>" );
writer.println( "</project>" );
response.setStatus( HttpServletResponse.SC_OK );
}
else if ( uri.endsWith( ".jar" ) )
{
writer.println( "empty" );
response.setStatus( HttpServletResponse.SC_OK );
}
else
{
response.setStatus( HttpServletResponse.SC_NOT_FOUND );
}
( (Request) request ).setHandled( true );
}
}
}

View File

@ -116,6 +116,9 @@ public class MavenITmng4428FollowHttpRedirectTest
Verifier verifier = new Verifier( testDir.getAbsolutePath() );
// NOTE: trust store cannot be reliably configured for the current JVM
verifier.setForkJvm( true );
// keytool -genkey -alias localhost -keypass key-passwd -keystore keystore -storepass store-passwd \
// -validity 4096 -dname "cn=localhost, ou=None, L=Seattle, ST=Washington, o=ExampleOrg, c=US" -keyalg RSA
String storePath = new File( testDir, "keystore" ).getAbsolutePath();

View File

@ -0,0 +1,257 @@
package org.apache.maven.it;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PushbackInputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* A simple HTTP proxy that only understands the CONNECT method to check HTTPS tunneling.
*
* @author Benjamin Bentmann
*/
public class TunnelingProxyServer
implements Runnable
{
private int port;
private volatile ServerSocket server;
private String targetHost;
private int targetPort;
private String connectFilter;
public TunnelingProxyServer( int port, String targetHost, int targetPort, String connectFilter )
{
this.port = port;
this.targetHost = targetHost;
this.targetPort = targetPort;
this.connectFilter = connectFilter;
}
public int getPort()
{
return ( server != null ) ? server.getLocalPort() : port;
}
public void start()
throws IOException
{
server = new ServerSocket( port, 4 );
new Thread( this ).start();
}
public void stop()
throws IOException
{
if ( server != null )
{
server.close();
server = null;
}
}
public void run()
{
try
{
while ( true )
{
new ClientHandler( server.accept() ).start();
}
}
catch ( Exception e )
{
// closed
}
}
class ClientHandler
extends Thread
{
private Socket client;
public ClientHandler( Socket client )
{
this.client = client;
}
public void run()
{
try
{
PushbackInputStream is = new PushbackInputStream( client.getInputStream() );
String dest = null;
while ( true )
{
String line = readLine( is );
if ( line == null || line.length() <= 0 )
{
break;
}
Matcher m = Pattern.compile( "CONNECT +([^:]+:[0-9]+) +.*" ).matcher( line );
if ( m.matches() )
{
dest = m.group( 1 );
}
}
OutputStream os = client.getOutputStream();
if ( dest == null || ( connectFilter != null && !dest.matches( connectFilter ) ) )
{
os.write( ( "HTTP/1.0 400 Bad request for " + dest + "\r\n\r\n" ).getBytes( "UTF-8" ) );
return;
}
os.write( "HTTP/1.0 200 Connection established\r\n\r\n".getBytes( "UTF-8" ) );
Socket server = new Socket( targetHost, targetPort );
Thread t1 = new StreamPumper( is, server.getOutputStream() );
t1.start();
Thread t2 = new StreamPumper( server.getInputStream(), os );
t2.start();
t1.join();
t2.join();
server.close();
}
catch ( Exception e )
{
e.printStackTrace();
}
finally
{
try
{
client.close();
}
catch ( IOException e )
{
e.printStackTrace();
}
}
}
private String readLine( PushbackInputStream is )
throws IOException
{
StringBuffer buffer = new StringBuffer( 1024 );
while ( true )
{
int b = is.read();
if ( b < 0 )
{
return null;
}
else if ( b == '\n' )
{
break;
}
else if ( b == '\r' )
{
b = is.read();
if ( b != '\n' )
{
is.unread( b );
}
break;
}
else
{
buffer.append( (char) b );
}
}
return buffer.toString();
}
}
static class StreamPumper
extends Thread
{
private final InputStream is;
private final OutputStream os;
public StreamPumper( InputStream is, OutputStream os )
{
this.is = is;
this.os = os;
}
public void run()
{
try
{
for ( byte[] buffer = new byte[1024 * 8];; )
{
int n = is.read( buffer );
if ( n < 0 )
{
break;
}
os.write( buffer, 0, n );
}
}
catch ( IOException e )
{
// closed
}
finally
{
try
{
is.close();
}
catch ( IOException e )
{
e.printStackTrace();
}
try
{
os.close();
}
catch ( IOException e )
{
e.printStackTrace();
}
}
}
}
}

Binary file not shown.

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng2305</groupId>
<artifactId>test</artifactId>
<version>0.1-SNAPSHOT</version>
<name>Maven Integration Test :: MNG-2305</name>
<description>
Verify that proxies can be setup for multiple protocols, in this case HTTP and HTTPS. As a nice side effect,
this checks HTTPS tunneling over a web proxy.
</description>
<dependencies>
<dependency>
<groupId>org.apache.maven.its.mng2305</groupId>
<artifactId>http</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.its.mng2305</groupId>
<artifactId>https</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-dependency-resolution</artifactId>
<version>2.1-SNAPSHOT</version>
<configuration>
<compileClassPath>target/classpath.txt</compileClassPath>
<significantPathLevels>1</significantPathLevels>
</configuration>
<executions>
<execution>
<id>test</id>
<phase>validate</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<settings>
<proxies>
<proxy>
<id>http</id>
<active>true</active>
<protocol>http</protocol>
<host>localhost</host>
<port>@proxy.http@</port>
</proxy>
<proxy>
<id>https</id>
<active>true</active>
<protocol>https</protocol>
<host>localhost</host>
<port>@proxy.https@</port>
</proxy>
</proxies>
<profiles>
<profile>
<id>maven-core-it-repo</id>
<repositories>
<repository>
<id>maven-core-it-http</id>
<url>http://http.mngit/repo/</url>
<releases>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>maven-core-it-https</id>
<url>https://https.mngit/repo/</url>
<releases>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>maven-core-it-repo</activeProfile>
</activeProfiles>
</settings>